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_move_single_vf_nodes - Move Tx scheduling nodes for single VF
574 * @lag: primary interface LAG struct
575 * @oldport: lport of previous interface
576 * @newport: lport of destination interface
577 * @vsi_num: SW index of VF's VSI
580 ice_lag_move_single_vf_nodes(struct ice_lag
*lag
, u8 oldport
, u8 newport
,
585 ice_for_each_traffic_class(tc
)
586 ice_lag_move_vf_node_tc(lag
, oldport
, newport
, vsi_num
, tc
);
590 * ice_lag_move_new_vf_nodes - Move Tx scheduling nodes for a VF if required
591 * @vf: the VF to move Tx nodes for
593 * Called just after configuring new VF queues. Check whether the VF Tx
594 * scheduling nodes need to be updated to fail over to the active port. If so,
597 void ice_lag_move_new_vf_nodes(struct ice_vf
*vf
)
599 struct ice_lag_netdev_list ndlist
;
600 struct list_head
*tmp
, *n
;
601 u8 pri_port
, act_port
;
606 vsi
= ice_get_vf_vsi(vf
);
611 if (WARN_ON(vsi
->type
!= ICE_VSI_VF
))
617 mutex_lock(&pf
->lag_mutex
);
621 pri_port
= pf
->hw
.port_info
->lport
;
622 act_port
= lag
->active_port
;
624 if (lag
->upper_netdev
) {
625 struct ice_lag_netdev_list
*nl
;
626 struct net_device
*tmp_nd
;
628 INIT_LIST_HEAD(&ndlist
.node
);
630 for_each_netdev_in_bond_rcu(lag
->upper_netdev
, tmp_nd
) {
631 nl
= kzalloc(sizeof(*nl
), GFP_ATOMIC
);
636 list_add(&nl
->node
, &ndlist
.node
);
641 lag
->netdev_head
= &ndlist
.node
;
643 if (ice_is_feature_supported(pf
, ICE_F_SRIOV_LAG
) &&
644 lag
->bonded
&& lag
->primary
&& pri_port
!= act_port
&&
645 !list_empty(lag
->netdev_head
))
646 ice_lag_move_single_vf_nodes(lag
, pri_port
, act_port
, vsi
->idx
);
648 list_for_each_safe(tmp
, n
, &ndlist
.node
) {
649 struct ice_lag_netdev_list
*entry
;
651 entry
= list_entry(tmp
, struct ice_lag_netdev_list
, node
);
652 list_del(&entry
->node
);
655 lag
->netdev_head
= NULL
;
658 mutex_unlock(&pf
->lag_mutex
);
662 * ice_lag_move_vf_nodes - move Tx scheduling nodes for all VFs to new port
663 * @lag: lag info struct
664 * @oldport: lport of previous interface
665 * @newport: lport of destination interface
667 static void ice_lag_move_vf_nodes(struct ice_lag
*lag
, u8 oldport
, u8 newport
)
676 ice_for_each_vsi(pf
, i
)
677 if (pf
->vsi
[i
] && (pf
->vsi
[i
]->type
== ICE_VSI_VF
||
678 pf
->vsi
[i
]->type
== ICE_VSI_SWITCHDEV_CTRL
))
679 ice_lag_move_single_vf_nodes(lag
, oldport
, newport
, i
);
682 #define ICE_LAG_SRIOV_CP_RECIPE 10
683 #define ICE_LAG_SRIOV_TRAIN_PKT_LEN 16
686 * ice_lag_cfg_cp_fltr - configure filter for control packets
687 * @lag: local interface's lag struct
688 * @add: add or remove rule
691 ice_lag_cfg_cp_fltr(struct ice_lag
*lag
, bool add
)
693 struct ice_sw_rule_lkup_rx_tx
*s_rule
= NULL
;
697 vsi
= lag
->pf
->vsi
[0];
699 buf_len
= ICE_SW_RULE_RX_TX_HDR_SIZE(s_rule
,
700 ICE_LAG_SRIOV_TRAIN_PKT_LEN
);
701 s_rule
= kzalloc(buf_len
, GFP_KERNEL
);
703 netdev_warn(lag
->netdev
, "-ENOMEM error configuring CP filter\n");
708 s_rule
->hdr
.type
= cpu_to_le16(ICE_AQC_SW_RULES_T_LKUP_RX
);
709 s_rule
->recipe_id
= cpu_to_le16(ICE_LAG_SRIOV_CP_RECIPE
);
710 s_rule
->src
= cpu_to_le16(vsi
->port_info
->lport
);
711 s_rule
->act
= cpu_to_le32(ICE_FWD_TO_VSI
|
712 ICE_SINGLE_ACT_LAN_ENABLE
|
713 ICE_SINGLE_ACT_VALID_BIT
|
715 ICE_SINGLE_ACT_VSI_ID_S
) &
716 ICE_SINGLE_ACT_VSI_ID_M
));
717 s_rule
->hdr_len
= cpu_to_le16(ICE_LAG_SRIOV_TRAIN_PKT_LEN
);
718 memcpy(s_rule
->hdr_data
, lacp_train_pkt
, LACP_TRAIN_PKT_LEN
);
719 opc
= ice_aqc_opc_add_sw_rules
;
721 opc
= ice_aqc_opc_remove_sw_rules
;
722 s_rule
->index
= cpu_to_le16(lag
->cp_rule_idx
);
724 if (ice_aq_sw_rules(&lag
->pf
->hw
, s_rule
, buf_len
, 1, opc
, NULL
)) {
725 netdev_warn(lag
->netdev
, "Error %s CP rule for fail-over\n",
726 add
? "ADDING" : "REMOVING");
731 lag
->cp_rule_idx
= le16_to_cpu(s_rule
->index
);
733 lag
->cp_rule_idx
= 0;
740 * ice_lag_info_event - handle NETDEV_BONDING_INFO event
741 * @lag: LAG info struct
742 * @ptr: opaque data pointer
744 * ptr is to be cast to (netdev_notifier_bonding_info *)
746 static void ice_lag_info_event(struct ice_lag
*lag
, void *ptr
)
748 struct netdev_notifier_bonding_info
*info
;
749 struct netdev_bonding_info
*bonding_info
;
750 struct net_device
*event_netdev
;
751 const char *lag_netdev_name
;
753 event_netdev
= netdev_notifier_info_to_dev(ptr
);
755 lag_netdev_name
= netdev_name(lag
->netdev
);
756 bonding_info
= &info
->bonding_info
;
758 if (event_netdev
!= lag
->netdev
|| !lag
->bonded
|| !lag
->upper_netdev
)
761 if (bonding_info
->master
.bond_mode
!= BOND_MODE_ACTIVEBACKUP
) {
762 netdev_dbg(lag
->netdev
, "Bonding event recv, but mode not active/backup\n");
766 if (strcmp(bonding_info
->slave
.slave_name
, lag_netdev_name
)) {
767 netdev_dbg(lag
->netdev
, "Bonding event recv, but secondary info not for us\n");
771 if (bonding_info
->slave
.state
)
772 ice_lag_set_backup(lag
);
774 ice_lag_set_primary(lag
);
777 ice_display_lag_info(lag
);
781 * ice_lag_reclaim_vf_tc - move scheduling nodes back to primary interface
782 * @lag: primary interface lag struct
783 * @src_hw: HW struct current node location
784 * @vsi_num: VSI index in PF space
785 * @tc: traffic class to move
788 ice_lag_reclaim_vf_tc(struct ice_lag
*lag
, struct ice_hw
*src_hw
, u16 vsi_num
,
791 DEFINE_FLEX(struct ice_aqc_move_elem
, buf
, teid
, 1);
792 struct device
*dev
= ice_pf_to_dev(lag
->pf
);
793 u16 numq
, valq
, num_moved
, qbuf_size
;
794 u16 buf_size
= __struct_size(buf
);
795 struct ice_aqc_cfg_txqs_buf
*qbuf
;
796 struct ice_sched_node
*n_prt
;
797 __le32 teid
, parent_teid
;
798 struct ice_vsi_ctx
*ctx
;
803 ctx
= ice_get_vsi_ctx(hw
, vsi_num
);
805 dev_warn(dev
, "Unable to locate VSI context for LAG reclaim\n");
809 /* check to see if this VF is enabled on this TC */
810 if (!ctx
->sched
.vsi_node
[tc
])
813 numq
= ctx
->num_lan_q_entries
[tc
];
814 teid
= ctx
->sched
.vsi_node
[tc
]->info
.node_teid
;
815 tmp_teid
= le32_to_cpu(teid
);
816 parent_teid
= ctx
->sched
.vsi_node
[tc
]->info
.parent_teid
;
818 /* if !teid or !numq, then this TC is not active */
819 if (!tmp_teid
|| !numq
)
822 /* suspend traffic */
823 if (ice_sched_suspend_resume_elems(hw
, 1, &tmp_teid
, true))
824 dev_dbg(dev
, "Problem suspending traffic for LAG node move\n");
826 /* reconfig queues for new port */
827 qbuf_size
= struct_size(qbuf
, queue_info
, numq
);
828 qbuf
= kzalloc(qbuf_size
, GFP_KERNEL
);
830 dev_warn(dev
, "Failure allocating memory for VF queue recfg buffer\n");
834 /* add the per queue info for the reconfigure command buffer */
835 valq
= ice_lag_qbuf_recfg(hw
, qbuf
, vsi_num
, numq
, tc
);
837 dev_dbg(dev
, "No valid queues found for LAG reclaim\n");
841 if (ice_aq_cfg_lan_txq(hw
, qbuf
, qbuf_size
, numq
,
842 src_hw
->port_info
->lport
, hw
->port_info
->lport
,
844 dev_warn(dev
, "Failure to configure queues for LAG failover\n");
851 /* find parent in primary tree */
852 n_prt
= ice_lag_get_sched_parent(hw
, tc
);
856 /* Move node to new parent */
857 buf
->hdr
.src_parent_teid
= parent_teid
;
858 buf
->hdr
.dest_parent_teid
= n_prt
->info
.node_teid
;
859 buf
->hdr
.num_elems
= cpu_to_le16(1);
860 buf
->hdr
.mode
= ICE_AQC_MOVE_ELEM_MODE_KEEP_OWN
;
863 if (ice_aq_move_sched_elems(&lag
->pf
->hw
, buf
, buf_size
, &num_moved
))
864 dev_warn(dev
, "Failure to move VF nodes for LAG reclaim\n");
866 ice_sched_update_parent(n_prt
, ctx
->sched
.vsi_node
[tc
]);
874 /* restart traffic */
875 if (ice_sched_suspend_resume_elems(hw
, 1, &tmp_teid
, false))
876 dev_warn(dev
, "Problem restarting traffic for LAG node reclaim\n");
880 * ice_lag_reclaim_vf_nodes - When interface leaving bond primary reclaims nodes
881 * @lag: primary interface lag struct
882 * @src_hw: HW struct for current node location
885 ice_lag_reclaim_vf_nodes(struct ice_lag
*lag
, struct ice_hw
*src_hw
)
890 if (!lag
->primary
|| !src_hw
)
894 ice_for_each_vsi(pf
, i
)
895 if (pf
->vsi
[i
] && (pf
->vsi
[i
]->type
== ICE_VSI_VF
||
896 pf
->vsi
[i
]->type
== ICE_VSI_SWITCHDEV_CTRL
))
897 ice_for_each_traffic_class(tc
)
898 ice_lag_reclaim_vf_tc(lag
, src_hw
, i
, tc
);
902 * ice_lag_link - handle LAG link event
903 * @lag: LAG info struct
905 static void ice_lag_link(struct ice_lag
*lag
)
907 struct ice_pf
*pf
= lag
->pf
;
910 dev_warn(ice_pf_to_dev(pf
), "%s Already part of a bond\n",
911 netdev_name(lag
->netdev
));
914 lag
->role
= ICE_LAG_UNSET
;
915 netdev_info(lag
->netdev
, "Shared SR-IOV resources in bond are active\n");
919 * ice_lag_unlink - handle unlink event
920 * @lag: LAG info struct
922 static void ice_lag_unlink(struct ice_lag
*lag
)
924 u8 pri_port
, act_port
, loc_port
;
925 struct ice_pf
*pf
= lag
->pf
;
928 netdev_dbg(lag
->netdev
, "bonding unlink event on non-LAG netdev\n");
933 act_port
= lag
->active_port
;
934 pri_port
= lag
->pf
->hw
.port_info
->lport
;
935 if (act_port
!= pri_port
&& act_port
!= ICE_LAG_INVALID_PORT
)
936 ice_lag_move_vf_nodes(lag
, act_port
, pri_port
);
937 lag
->primary
= false;
938 lag
->active_port
= ICE_LAG_INVALID_PORT
;
940 struct ice_lag
*primary_lag
;
942 primary_lag
= ice_lag_find_primary(lag
);
944 act_port
= primary_lag
->active_port
;
945 pri_port
= primary_lag
->pf
->hw
.port_info
->lport
;
946 loc_port
= pf
->hw
.port_info
->lport
;
947 if (act_port
== loc_port
&&
948 act_port
!= ICE_LAG_INVALID_PORT
) {
949 ice_lag_reclaim_vf_nodes(primary_lag
,
951 primary_lag
->active_port
= ICE_LAG_INVALID_PORT
;
957 lag
->role
= ICE_LAG_NONE
;
958 lag
->upper_netdev
= NULL
;
962 * ice_lag_link_unlink - helper function to call lag_link/unlink
963 * @lag: lag info struct
964 * @ptr: opaque pointer data
966 static void ice_lag_link_unlink(struct ice_lag
*lag
, void *ptr
)
968 struct net_device
*netdev
= netdev_notifier_info_to_dev(ptr
);
969 struct netdev_notifier_changeupper_info
*info
= ptr
;
971 if (netdev
!= lag
->netdev
)
981 * ice_lag_set_swid - set the SWID on secondary interface
982 * @primary_swid: primary interface's SWID
983 * @local_lag: local interfaces LAG struct
984 * @link: Is this a linking activity
986 * If link is false, then primary_swid should be expected to not be valid
987 * This function should never be called in interrupt context.
990 ice_lag_set_swid(u16 primary_swid
, struct ice_lag
*local_lag
,
993 struct ice_aqc_alloc_free_res_elem
*buf
;
994 struct ice_aqc_set_port_params
*cmd
;
995 struct ice_aq_desc desc
;
999 buf_len
= struct_size(buf
, elem
, 1);
1000 buf
= kzalloc(buf_len
, GFP_KERNEL
);
1002 dev_err(ice_pf_to_dev(local_lag
->pf
), "-ENOMEM error setting SWID\n");
1006 buf
->num_elems
= cpu_to_le16(1);
1007 buf
->res_type
= cpu_to_le16(ICE_AQC_RES_TYPE_SWID
);
1008 /* if unlinnking need to free the shared resource */
1009 if (!link
&& local_lag
->bond_swid
) {
1010 buf
->elem
[0].e
.sw_resp
= cpu_to_le16(local_lag
->bond_swid
);
1011 status
= ice_aq_alloc_free_res(&local_lag
->pf
->hw
, buf
,
1012 buf_len
, ice_aqc_opc_free_res
);
1014 dev_err(ice_pf_to_dev(local_lag
->pf
), "Error freeing SWID during LAG unlink\n");
1015 local_lag
->bond_swid
= 0;
1019 buf
->res_type
|= cpu_to_le16(ICE_LAG_RES_SHARED
|
1021 /* store the primary's SWID in case it leaves bond first */
1022 local_lag
->bond_swid
= primary_swid
;
1023 buf
->elem
[0].e
.sw_resp
= cpu_to_le16(local_lag
->bond_swid
);
1025 buf
->elem
[0].e
.sw_resp
=
1026 cpu_to_le16(local_lag
->pf
->hw
.port_info
->sw_id
);
1029 status
= ice_aq_alloc_free_res(&local_lag
->pf
->hw
, buf
, buf_len
,
1030 ice_aqc_opc_alloc_res
);
1032 dev_err(ice_pf_to_dev(local_lag
->pf
), "Error subscribing to SWID 0x%04X\n",
1033 local_lag
->bond_swid
);
1037 /* Configure port param SWID to correct value */
1039 swid
= primary_swid
;
1041 swid
= local_lag
->pf
->hw
.port_info
->sw_id
;
1043 cmd
= &desc
.params
.set_port_params
;
1044 ice_fill_dflt_direct_cmd_desc(&desc
, ice_aqc_opc_set_port_params
);
1046 cmd
->swid
= cpu_to_le16(ICE_AQC_PORT_SWID_VALID
| swid
);
1047 /* If this is happening in reset context, it is possible that the
1048 * primary interface has not finished setting its SWID to SHARED
1049 * yet. Allow retries to account for this timing issue between
1052 for (i
= 0; i
< ICE_LAG_RESET_RETRIES
; i
++) {
1053 status
= ice_aq_send_cmd(&local_lag
->pf
->hw
, &desc
, NULL
, 0,
1058 usleep_range(1000, 2000);
1062 dev_err(ice_pf_to_dev(local_lag
->pf
), "Error setting SWID in port params %d\n",
1067 * ice_lag_primary_swid - set/clear the SHARED attrib of primary's SWID
1068 * @lag: primary interface's lag struct
1069 * @link: is this a linking activity
1071 * Implement setting primary SWID as shared using 0x020B
1073 static void ice_lag_primary_swid(struct ice_lag
*lag
, bool link
)
1079 swid
= hw
->port_info
->sw_id
;
1081 if (ice_share_res(hw
, ICE_AQC_RES_TYPE_SWID
, link
, swid
))
1082 dev_warn(ice_pf_to_dev(lag
->pf
), "Failure to set primary interface shared status\n");
1086 * ice_lag_add_prune_list - Adds event_pf's VSI to primary's prune list
1087 * @lag: lag info struct
1088 * @event_pf: PF struct for VSI we are adding to primary's prune list
1090 static void ice_lag_add_prune_list(struct ice_lag
*lag
, struct ice_pf
*event_pf
)
1092 u16 num_vsi
, rule_buf_sz
, vsi_list_id
, event_vsi_num
, prim_vsi_idx
;
1093 struct ice_sw_rule_vsi_list
*s_rule
= NULL
;
1098 dev
= ice_pf_to_dev(lag
->pf
);
1099 event_vsi_num
= event_pf
->vsi
[0]->vsi_num
;
1100 prim_vsi_idx
= lag
->pf
->vsi
[0]->idx
;
1102 if (!ice_find_vsi_list_entry(&lag
->pf
->hw
, ICE_SW_LKUP_VLAN
,
1103 prim_vsi_idx
, &vsi_list_id
)) {
1104 dev_warn(dev
, "Could not locate prune list when setting up SRIOV LAG\n");
1108 rule_buf_sz
= (u16
)ICE_SW_RULE_VSI_LIST_SIZE(s_rule
, num_vsi
);
1109 s_rule
= kzalloc(rule_buf_sz
, GFP_KERNEL
);
1111 dev_warn(dev
, "Error allocating space for prune list when configuring SRIOV LAG\n");
1115 s_rule
->hdr
.type
= cpu_to_le16(ICE_AQC_SW_RULES_T_PRUNE_LIST_SET
);
1116 s_rule
->index
= cpu_to_le16(vsi_list_id
);
1117 s_rule
->number_vsi
= cpu_to_le16(num_vsi
);
1118 s_rule
->vsi
[0] = cpu_to_le16(event_vsi_num
);
1120 if (ice_aq_sw_rules(&event_pf
->hw
, s_rule
, rule_buf_sz
, 1,
1121 ice_aqc_opc_update_sw_rules
, NULL
))
1122 dev_warn(dev
, "Error adding VSI prune list\n");
1127 * ice_lag_del_prune_list - Remove secondary's vsi from primary's prune list
1128 * @lag: primary interface's ice_lag struct
1129 * @event_pf: PF struct for unlinking interface
1131 static void ice_lag_del_prune_list(struct ice_lag
*lag
, struct ice_pf
*event_pf
)
1133 u16 num_vsi
, vsi_num
, vsi_idx
, rule_buf_sz
, vsi_list_id
;
1134 struct ice_sw_rule_vsi_list
*s_rule
= NULL
;
1139 dev
= ice_pf_to_dev(lag
->pf
);
1140 vsi_num
= event_pf
->vsi
[0]->vsi_num
;
1141 vsi_idx
= lag
->pf
->vsi
[0]->idx
;
1143 if (!ice_find_vsi_list_entry(&lag
->pf
->hw
, ICE_SW_LKUP_VLAN
,
1144 vsi_idx
, &vsi_list_id
)) {
1145 dev_warn(dev
, "Could not locate prune list when unwinding SRIOV LAG\n");
1149 rule_buf_sz
= (u16
)ICE_SW_RULE_VSI_LIST_SIZE(s_rule
, num_vsi
);
1150 s_rule
= kzalloc(rule_buf_sz
, GFP_KERNEL
);
1152 dev_warn(dev
, "Error allocating prune list when unwinding SRIOV LAG\n");
1156 s_rule
->hdr
.type
= cpu_to_le16(ICE_AQC_SW_RULES_T_PRUNE_LIST_CLEAR
);
1157 s_rule
->index
= cpu_to_le16(vsi_list_id
);
1158 s_rule
->number_vsi
= cpu_to_le16(num_vsi
);
1159 s_rule
->vsi
[0] = cpu_to_le16(vsi_num
);
1161 if (ice_aq_sw_rules(&event_pf
->hw
, (struct ice_aqc_sw_rules
*)s_rule
,
1162 rule_buf_sz
, 1, ice_aqc_opc_update_sw_rules
, NULL
))
1163 dev_warn(dev
, "Error clearing VSI prune list\n");
1169 * ice_lag_init_feature_support_flag - Check for NVM support for LAG
1172 static void ice_lag_init_feature_support_flag(struct ice_pf
*pf
)
1174 struct ice_hw_common_caps
*caps
;
1176 caps
= &pf
->hw
.dev_caps
.common_cap
;
1178 ice_set_feature_support(pf
, ICE_F_ROCE_LAG
);
1180 ice_clear_feature_support(pf
, ICE_F_ROCE_LAG
);
1182 if (caps
->sriov_lag
)
1183 ice_set_feature_support(pf
, ICE_F_SRIOV_LAG
);
1185 ice_clear_feature_support(pf
, ICE_F_SRIOV_LAG
);
1189 * ice_lag_changeupper_event - handle LAG changeupper event
1190 * @lag: LAG info struct
1191 * @ptr: opaque pointer data
1193 static void ice_lag_changeupper_event(struct ice_lag
*lag
, void *ptr
)
1195 struct netdev_notifier_changeupper_info
*info
;
1196 struct ice_lag
*primary_lag
;
1197 struct net_device
*netdev
;
1200 netdev
= netdev_notifier_info_to_dev(ptr
);
1202 /* not for this netdev */
1203 if (netdev
!= lag
->netdev
)
1206 primary_lag
= ice_lag_find_primary(lag
);
1207 if (info
->linking
) {
1208 lag
->upper_netdev
= info
->upper_dev
;
1209 /* If there is not already a primary interface in the LAG,
1210 * then mark this one as primary.
1213 lag
->primary
= true;
1214 /* Configure primary's SWID to be shared */
1215 ice_lag_primary_swid(lag
, true);
1220 swid
= primary_lag
->pf
->hw
.port_info
->sw_id
;
1221 ice_lag_set_swid(swid
, lag
, true);
1222 ice_lag_add_prune_list(primary_lag
, lag
->pf
);
1223 ice_lag_cfg_drop_fltr(lag
, true);
1225 /* add filter for primary control packets */
1226 ice_lag_cfg_cp_fltr(lag
, true);
1228 if (!primary_lag
&& lag
->primary
)
1231 if (!lag
->primary
) {
1232 ice_lag_set_swid(0, lag
, false);
1234 if (primary_lag
&& lag
->primary
) {
1235 ice_lag_primary_swid(lag
, false);
1236 ice_lag_del_prune_list(primary_lag
, lag
->pf
);
1239 /* remove filter for control packets */
1240 ice_lag_cfg_cp_fltr(lag
, false);
1245 * ice_lag_monitor_link - monitor interfaces entering/leaving the aggregate
1246 * @lag: lag info struct
1247 * @ptr: opaque data containing notifier event
1249 * This function only operates after a primary has been set.
1251 static void ice_lag_monitor_link(struct ice_lag
*lag
, void *ptr
)
1253 struct netdev_notifier_changeupper_info
*info
;
1254 struct ice_hw
*prim_hw
, *active_hw
;
1255 struct net_device
*event_netdev
;
1262 event_netdev
= netdev_notifier_info_to_dev(ptr
);
1263 if (!netif_is_same_ice(lag
->pf
, event_netdev
))
1268 prim_port
= prim_hw
->port_info
->lport
;
1270 info
= (struct netdev_notifier_changeupper_info
*)ptr
;
1271 if (info
->upper_dev
!= lag
->upper_netdev
)
1274 if (!info
->linking
) {
1275 /* Since there are only two interfaces allowed in SRIOV+LAG, if
1276 * one port is leaving, then nodes need to be on primary
1279 if (prim_port
!= lag
->active_port
&&
1280 lag
->active_port
!= ICE_LAG_INVALID_PORT
) {
1281 active_hw
= ice_lag_find_hw_by_lport(lag
,
1283 ice_lag_reclaim_vf_nodes(lag
, active_hw
);
1284 lag
->active_port
= ICE_LAG_INVALID_PORT
;
1290 * ice_lag_monitor_active - main PF keep track of which port is active
1291 * @lag: lag info struct
1292 * @ptr: opaque data containing notifier event
1294 * This function is for the primary PF to monitor changes in which port is
1295 * active and handle changes for SRIOV VF functionality
1297 static void ice_lag_monitor_active(struct ice_lag
*lag
, void *ptr
)
1299 struct net_device
*event_netdev
, *event_upper
;
1300 struct netdev_notifier_bonding_info
*info
;
1301 struct netdev_bonding_info
*bonding_info
;
1302 struct ice_netdev_priv
*event_np
;
1303 struct ice_pf
*pf
, *event_pf
;
1304 u8 prim_port
, event_port
;
1313 event_netdev
= netdev_notifier_info_to_dev(ptr
);
1315 event_upper
= netdev_master_upper_dev_get_rcu(event_netdev
);
1317 if (!netif_is_ice(event_netdev
) || event_upper
!= lag
->upper_netdev
)
1320 event_np
= netdev_priv(event_netdev
);
1321 event_pf
= event_np
->vsi
->back
;
1322 event_port
= event_pf
->hw
.port_info
->lport
;
1323 prim_port
= pf
->hw
.port_info
->lport
;
1325 info
= (struct netdev_notifier_bonding_info
*)ptr
;
1326 bonding_info
= &info
->bonding_info
;
1328 if (!bonding_info
->slave
.state
) {
1329 /* if no port is currently active, then nodes and filters exist
1330 * on primary port, check if we need to move them
1332 if (lag
->active_port
== ICE_LAG_INVALID_PORT
) {
1333 if (event_port
!= prim_port
)
1334 ice_lag_move_vf_nodes(lag
, prim_port
,
1336 lag
->active_port
= event_port
;
1340 /* active port is already set and is current event port */
1341 if (lag
->active_port
== event_port
)
1343 /* new active port */
1344 ice_lag_move_vf_nodes(lag
, lag
->active_port
, event_port
);
1345 lag
->active_port
= event_port
;
1347 /* port not set as currently active (e.g. new active port
1348 * has already claimed the nodes and filters
1350 if (lag
->active_port
!= event_port
)
1352 /* This is the case when neither port is active (both link down)
1353 * Link down on the bond - set active port to invalid and move
1354 * nodes and filters back to primary if not already there
1356 if (event_port
!= prim_port
)
1357 ice_lag_move_vf_nodes(lag
, event_port
, prim_port
);
1358 lag
->active_port
= ICE_LAG_INVALID_PORT
;
1363 * ice_lag_chk_comp - evaluate bonded interface for feature support
1364 * @lag: lag info struct
1365 * @ptr: opaque data for netdev event info
1368 ice_lag_chk_comp(struct ice_lag
*lag
, void *ptr
)
1370 struct net_device
*event_netdev
, *event_upper
;
1371 struct netdev_notifier_bonding_info
*info
;
1372 struct netdev_bonding_info
*bonding_info
;
1373 struct list_head
*tmp
;
1380 event_netdev
= netdev_notifier_info_to_dev(ptr
);
1382 event_upper
= netdev_master_upper_dev_get_rcu(event_netdev
);
1384 if (event_upper
!= lag
->upper_netdev
)
1387 dev
= ice_pf_to_dev(lag
->pf
);
1389 /* only supporting switchdev mode for SRIOV VF LAG.
1390 * primary interface has to be in switchdev mode
1392 if (!ice_is_switchdev_running(lag
->pf
)) {
1393 dev_info(dev
, "Primary interface not in switchdev mode - VF LAG disabled\n");
1397 info
= (struct netdev_notifier_bonding_info
*)ptr
;
1398 bonding_info
= &info
->bonding_info
;
1399 lag
->bond_mode
= bonding_info
->master
.bond_mode
;
1400 if (lag
->bond_mode
!= BOND_MODE_ACTIVEBACKUP
) {
1401 dev_info(dev
, "Bond Mode not ACTIVE-BACKUP - VF LAG disabled\n");
1405 list_for_each(tmp
, lag
->netdev_head
) {
1406 struct ice_dcbx_cfg
*dcb_cfg
, *peer_dcb_cfg
;
1407 struct ice_lag_netdev_list
*entry
;
1408 struct ice_netdev_priv
*peer_np
;
1409 struct net_device
*peer_netdev
;
1410 struct ice_vsi
*vsi
, *peer_vsi
;
1411 struct ice_pf
*peer_pf
;
1413 entry
= list_entry(tmp
, struct ice_lag_netdev_list
, node
);
1414 peer_netdev
= entry
->netdev
;
1415 if (!netif_is_ice(peer_netdev
)) {
1416 dev_info(dev
, "Found %s non-ice netdev in LAG - VF LAG disabled\n",
1417 netdev_name(peer_netdev
));
1423 dev_info(dev
, "Found more than two netdevs in LAG - VF LAG disabled\n");
1427 peer_np
= netdev_priv(peer_netdev
);
1428 vsi
= ice_get_main_vsi(lag
->pf
);
1429 peer_vsi
= peer_np
->vsi
;
1430 if (lag
->pf
->pdev
->bus
!= peer_vsi
->back
->pdev
->bus
||
1431 lag
->pf
->pdev
->slot
!= peer_vsi
->back
->pdev
->slot
) {
1432 dev_info(dev
, "Found %s on different device in LAG - VF LAG disabled\n",
1433 netdev_name(peer_netdev
));
1437 dcb_cfg
= &vsi
->port_info
->qos_cfg
.local_dcbx_cfg
;
1438 peer_dcb_cfg
= &peer_vsi
->port_info
->qos_cfg
.local_dcbx_cfg
;
1439 if (memcmp(dcb_cfg
, peer_dcb_cfg
,
1440 sizeof(struct ice_dcbx_cfg
))) {
1441 dev_info(dev
, "Found %s with different DCB in LAG - VF LAG disabled\n",
1442 netdev_name(peer_netdev
));
1446 peer_pf
= peer_vsi
->back
;
1447 if (test_bit(ICE_FLAG_FW_LLDP_AGENT
, peer_pf
->flags
)) {
1448 dev_warn(dev
, "Found %s with FW LLDP agent active - VF LAG disabled\n",
1449 netdev_name(peer_netdev
));
1458 * ice_lag_unregister - handle netdev unregister events
1459 * @lag: LAG info struct
1460 * @event_netdev: netdev struct for target of notifier event
1463 ice_lag_unregister(struct ice_lag
*lag
, struct net_device
*event_netdev
)
1465 struct ice_netdev_priv
*np
;
1466 struct ice_pf
*event_pf
;
1467 struct ice_lag
*p_lag
;
1469 p_lag
= ice_lag_find_primary(lag
);
1470 np
= netdev_priv(event_netdev
);
1471 event_pf
= np
->vsi
->back
;
1474 if (p_lag
->active_port
!= p_lag
->pf
->hw
.port_info
->lport
&&
1475 p_lag
->active_port
!= ICE_LAG_INVALID_PORT
) {
1476 struct ice_hw
*active_hw
;
1478 active_hw
= ice_lag_find_hw_by_lport(lag
,
1479 p_lag
->active_port
);
1481 ice_lag_reclaim_vf_nodes(p_lag
, active_hw
);
1482 lag
->active_port
= ICE_LAG_INVALID_PORT
;
1486 /* primary processing for primary */
1487 if (lag
->primary
&& lag
->netdev
== event_netdev
)
1488 ice_lag_primary_swid(lag
, false);
1490 /* primary processing for secondary */
1491 if (lag
->primary
&& lag
->netdev
!= event_netdev
)
1492 ice_lag_del_prune_list(lag
, event_pf
);
1494 /* secondary processing for secondary */
1495 if (!lag
->primary
&& lag
->netdev
== event_netdev
)
1496 ice_lag_set_swid(0, lag
, false);
1500 * ice_lag_monitor_rdma - set and clear rdma functionality
1501 * @lag: pointer to lag struct
1502 * @ptr: opaque data for netdev event info
1505 ice_lag_monitor_rdma(struct ice_lag
*lag
, void *ptr
)
1507 struct netdev_notifier_changeupper_info
*info
;
1508 struct net_device
*netdev
;
1511 netdev
= netdev_notifier_info_to_dev(ptr
);
1513 if (netdev
!= lag
->netdev
)
1517 ice_clear_rdma_cap(lag
->pf
);
1519 ice_set_rdma_cap(lag
->pf
);
1523 * ice_lag_chk_disabled_bond - monitor interfaces entering/leaving disabled bond
1524 * @lag: lag info struct
1525 * @ptr: opaque data containing event
1527 * as interfaces enter a bond - determine if the bond is currently
1528 * SRIOV LAG compliant and flag if not. As interfaces leave the
1529 * bond, reset their compliant status.
1531 static void ice_lag_chk_disabled_bond(struct ice_lag
*lag
, void *ptr
)
1533 struct net_device
*netdev
= netdev_notifier_info_to_dev(ptr
);
1534 struct netdev_notifier_changeupper_info
*info
= ptr
;
1535 struct ice_lag
*prim_lag
;
1537 if (netdev
!= lag
->netdev
)
1540 if (info
->linking
) {
1541 prim_lag
= ice_lag_find_primary(lag
);
1543 !ice_is_feature_supported(prim_lag
->pf
, ICE_F_SRIOV_LAG
)) {
1544 ice_clear_feature_support(lag
->pf
, ICE_F_SRIOV_LAG
);
1545 netdev_info(netdev
, "Interface added to non-compliant SRIOV LAG aggregate\n");
1548 ice_lag_init_feature_support_flag(lag
->pf
);
1553 * ice_lag_disable_sriov_bond - set members of bond as not supporting SRIOV LAG
1554 * @lag: primary interfaces lag struct
1556 static void ice_lag_disable_sriov_bond(struct ice_lag
*lag
)
1558 struct ice_netdev_priv
*np
;
1561 np
= netdev_priv(lag
->netdev
);
1563 ice_clear_feature_support(pf
, ICE_F_SRIOV_LAG
);
1567 * ice_lag_process_event - process a task assigned to the lag_wq
1568 * @work: pointer to work_struct
1570 static void ice_lag_process_event(struct work_struct
*work
)
1572 struct netdev_notifier_changeupper_info
*info
;
1573 struct ice_lag_work
*lag_work
;
1574 struct net_device
*netdev
;
1575 struct list_head
*tmp
, *n
;
1578 lag_work
= container_of(work
, struct ice_lag_work
, lag_task
);
1579 pf
= lag_work
->lag
->pf
;
1581 mutex_lock(&pf
->lag_mutex
);
1582 lag_work
->lag
->netdev_head
= &lag_work
->netdev_list
.node
;
1584 switch (lag_work
->event
) {
1585 case NETDEV_CHANGEUPPER
:
1586 info
= &lag_work
->info
.changeupper_info
;
1587 ice_lag_chk_disabled_bond(lag_work
->lag
, info
);
1588 if (ice_is_feature_supported(pf
, ICE_F_SRIOV_LAG
)) {
1589 ice_lag_monitor_link(lag_work
->lag
, info
);
1590 ice_lag_changeupper_event(lag_work
->lag
, info
);
1591 ice_lag_link_unlink(lag_work
->lag
, info
);
1593 ice_lag_monitor_rdma(lag_work
->lag
, info
);
1595 case NETDEV_BONDING_INFO
:
1596 if (ice_is_feature_supported(pf
, ICE_F_SRIOV_LAG
)) {
1597 if (!ice_lag_chk_comp(lag_work
->lag
,
1598 &lag_work
->info
.bonding_info
)) {
1599 netdev
= lag_work
->info
.bonding_info
.info
.dev
;
1600 ice_lag_disable_sriov_bond(lag_work
->lag
);
1601 ice_lag_unregister(lag_work
->lag
, netdev
);
1604 ice_lag_monitor_active(lag_work
->lag
,
1605 &lag_work
->info
.bonding_info
);
1606 ice_lag_cfg_pf_fltrs(lag_work
->lag
,
1607 &lag_work
->info
.bonding_info
);
1609 ice_lag_info_event(lag_work
->lag
, &lag_work
->info
.bonding_info
);
1611 case NETDEV_UNREGISTER
:
1612 if (ice_is_feature_supported(pf
, ICE_F_SRIOV_LAG
)) {
1613 netdev
= lag_work
->info
.bonding_info
.info
.dev
;
1614 if ((netdev
== lag_work
->lag
->netdev
||
1615 lag_work
->lag
->primary
) && lag_work
->lag
->bonded
)
1616 ice_lag_unregister(lag_work
->lag
, netdev
);
1624 /* cleanup resources allocated for this work item */
1625 list_for_each_safe(tmp
, n
, &lag_work
->netdev_list
.node
) {
1626 struct ice_lag_netdev_list
*entry
;
1628 entry
= list_entry(tmp
, struct ice_lag_netdev_list
, node
);
1629 list_del(&entry
->node
);
1632 lag_work
->lag
->netdev_head
= NULL
;
1634 mutex_unlock(&pf
->lag_mutex
);
1640 * ice_lag_event_handler - handle LAG events from netdev
1641 * @notif_blk: notifier block registered by this netdev
1642 * @event: event type
1643 * @ptr: opaque data containing notifier event
1646 ice_lag_event_handler(struct notifier_block
*notif_blk
, unsigned long event
,
1649 struct net_device
*netdev
= netdev_notifier_info_to_dev(ptr
);
1650 struct net_device
*upper_netdev
;
1651 struct ice_lag_work
*lag_work
;
1652 struct ice_lag
*lag
;
1654 if (!netif_is_ice(netdev
))
1657 if (event
!= NETDEV_CHANGEUPPER
&& event
!= NETDEV_BONDING_INFO
&&
1658 event
!= NETDEV_UNREGISTER
)
1661 if (!(netdev
->priv_flags
& IFF_BONDING
))
1664 lag
= container_of(notif_blk
, struct ice_lag
, notif_block
);
1668 if (!net_eq(dev_net(netdev
), &init_net
))
1671 /* This memory will be freed at the end of ice_lag_process_event */
1672 lag_work
= kzalloc(sizeof(*lag_work
), GFP_KERNEL
);
1676 lag_work
->event_netdev
= netdev
;
1677 lag_work
->lag
= lag
;
1678 lag_work
->event
= event
;
1679 if (event
== NETDEV_CHANGEUPPER
) {
1680 struct netdev_notifier_changeupper_info
*info
;
1683 upper_netdev
= info
->upper_dev
;
1685 upper_netdev
= netdev_master_upper_dev_get(netdev
);
1688 INIT_LIST_HEAD(&lag_work
->netdev_list
.node
);
1690 struct ice_lag_netdev_list
*nd_list
;
1691 struct net_device
*tmp_nd
;
1694 for_each_netdev_in_bond_rcu(upper_netdev
, tmp_nd
) {
1695 nd_list
= kzalloc(sizeof(*nd_list
), GFP_ATOMIC
);
1699 nd_list
->netdev
= tmp_nd
;
1700 list_add(&nd_list
->node
, &lag_work
->netdev_list
.node
);
1706 case NETDEV_CHANGEUPPER
:
1707 lag_work
->info
.changeupper_info
=
1708 *((struct netdev_notifier_changeupper_info
*)ptr
);
1710 case NETDEV_BONDING_INFO
:
1711 lag_work
->info
.bonding_info
=
1712 *((struct netdev_notifier_bonding_info
*)ptr
);
1715 lag_work
->info
.notifier_info
=
1716 *((struct netdev_notifier_info
*)ptr
);
1720 INIT_WORK(&lag_work
->lag_task
, ice_lag_process_event
);
1721 queue_work(ice_lag_wq
, &lag_work
->lag_task
);
1727 * ice_register_lag_handler - register LAG handler on netdev
1730 static int ice_register_lag_handler(struct ice_lag
*lag
)
1732 struct device
*dev
= ice_pf_to_dev(lag
->pf
);
1733 struct notifier_block
*notif_blk
;
1735 notif_blk
= &lag
->notif_block
;
1737 if (!notif_blk
->notifier_call
) {
1738 notif_blk
->notifier_call
= ice_lag_event_handler
;
1739 if (register_netdevice_notifier(notif_blk
)) {
1740 notif_blk
->notifier_call
= NULL
;
1741 dev_err(dev
, "FAIL register LAG event handler!\n");
1744 dev_dbg(dev
, "LAG event handler registered\n");
1750 * ice_unregister_lag_handler - unregister LAG handler on netdev
1753 static void ice_unregister_lag_handler(struct ice_lag
*lag
)
1755 struct device
*dev
= ice_pf_to_dev(lag
->pf
);
1756 struct notifier_block
*notif_blk
;
1758 notif_blk
= &lag
->notif_block
;
1759 if (notif_blk
->notifier_call
) {
1760 unregister_netdevice_notifier(notif_blk
);
1761 dev_dbg(dev
, "LAG event handler unregistered\n");
1766 * ice_create_lag_recipe
1767 * @hw: pointer to HW struct
1768 * @rid: pointer to u16 to pass back recipe index
1769 * @base_recipe: recipe to base the new recipe on
1770 * @prio: priority for new recipe
1772 * function returns 0 on error
1774 static int ice_create_lag_recipe(struct ice_hw
*hw
, u16
*rid
,
1775 const u8
*base_recipe
, u8 prio
)
1777 struct ice_aqc_recipe_data_elem
*new_rcp
;
1780 err
= ice_alloc_recipe(hw
, rid
);
1784 new_rcp
= kzalloc(ICE_RECIPE_LEN
* ICE_MAX_NUM_RECIPES
, GFP_KERNEL
);
1788 memcpy(new_rcp
, base_recipe
, ICE_RECIPE_LEN
);
1789 new_rcp
->content
.act_ctrl_fwd_priority
= prio
;
1790 new_rcp
->content
.rid
= *rid
| ICE_AQ_RECIPE_ID_IS_ROOT
;
1791 new_rcp
->recipe_indx
= *rid
;
1792 bitmap_zero((unsigned long *)new_rcp
->recipe_bitmap
,
1793 ICE_MAX_NUM_RECIPES
);
1794 set_bit(*rid
, (unsigned long *)new_rcp
->recipe_bitmap
);
1796 err
= ice_aq_add_recipe(hw
, new_rcp
, 1, NULL
);
1805 * ice_lag_move_vf_nodes_tc_sync - move a VF's nodes for a tc during reset
1806 * @lag: primary interfaces lag struct
1807 * @dest_hw: HW struct for destination's interface
1808 * @vsi_num: VSI index in PF space
1809 * @tc: traffic class to move
1812 ice_lag_move_vf_nodes_tc_sync(struct ice_lag
*lag
, struct ice_hw
*dest_hw
,
1815 DEFINE_FLEX(struct ice_aqc_move_elem
, buf
, teid
, 1);
1816 struct device
*dev
= ice_pf_to_dev(lag
->pf
);
1817 u16 numq
, valq
, num_moved
, qbuf_size
;
1818 u16 buf_size
= __struct_size(buf
);
1819 struct ice_aqc_cfg_txqs_buf
*qbuf
;
1820 struct ice_sched_node
*n_prt
;
1821 __le32 teid
, parent_teid
;
1822 struct ice_vsi_ctx
*ctx
;
1827 ctx
= ice_get_vsi_ctx(hw
, vsi_num
);
1829 dev_warn(dev
, "LAG rebuild failed after reset due to VSI Context failure\n");
1833 if (!ctx
->sched
.vsi_node
[tc
])
1836 numq
= ctx
->num_lan_q_entries
[tc
];
1837 teid
= ctx
->sched
.vsi_node
[tc
]->info
.node_teid
;
1838 tmp_teid
= le32_to_cpu(teid
);
1839 parent_teid
= ctx
->sched
.vsi_node
[tc
]->info
.parent_teid
;
1841 if (!tmp_teid
|| !numq
)
1844 if (ice_sched_suspend_resume_elems(hw
, 1, &tmp_teid
, true))
1845 dev_dbg(dev
, "Problem suspending traffic during reset rebuild\n");
1847 /* reconfig queues for new port */
1848 qbuf_size
= struct_size(qbuf
, queue_info
, numq
);
1849 qbuf
= kzalloc(qbuf_size
, GFP_KERNEL
);
1851 dev_warn(dev
, "Failure allocating VF queue recfg buffer for reset rebuild\n");
1855 /* add the per queue info for the reconfigure command buffer */
1856 valq
= ice_lag_qbuf_recfg(hw
, qbuf
, vsi_num
, numq
, tc
);
1858 dev_warn(dev
, "Failure to reconfig queues for LAG reset rebuild\n");
1862 if (ice_aq_cfg_lan_txq(hw
, qbuf
, qbuf_size
, numq
, hw
->port_info
->lport
,
1863 dest_hw
->port_info
->lport
, NULL
)) {
1864 dev_warn(dev
, "Failure to configure queues for LAG reset rebuild\n");
1871 /* find parent in destination tree */
1872 n_prt
= ice_lag_get_sched_parent(dest_hw
, tc
);
1876 /* Move node to new parent */
1877 buf
->hdr
.src_parent_teid
= parent_teid
;
1878 buf
->hdr
.dest_parent_teid
= n_prt
->info
.node_teid
;
1879 buf
->hdr
.num_elems
= cpu_to_le16(1);
1880 buf
->hdr
.mode
= ICE_AQC_MOVE_ELEM_MODE_KEEP_OWN
;
1881 buf
->teid
[0] = teid
;
1883 if (ice_aq_move_sched_elems(&lag
->pf
->hw
, buf
, buf_size
, &num_moved
))
1884 dev_warn(dev
, "Failure to move VF nodes for LAG reset rebuild\n");
1886 ice_sched_update_parent(n_prt
, ctx
->sched
.vsi_node
[tc
]);
1894 if (ice_sched_suspend_resume_elems(hw
, 1, &tmp_teid
, false))
1895 dev_warn(dev
, "Problem restarting traffic for LAG node reset rebuild\n");
1899 * ice_lag_move_vf_nodes_sync - move vf nodes to active interface
1900 * @lag: primary interfaces lag struct
1901 * @dest_hw: lport value for currently active port
1903 * This function is used in a reset context, outside of event handling,
1904 * to move the VF nodes to the secondary interface when that interface
1905 * is the active interface during a reset rebuild
1908 ice_lag_move_vf_nodes_sync(struct ice_lag
*lag
, struct ice_hw
*dest_hw
)
1913 if (!lag
->primary
|| !dest_hw
)
1917 ice_for_each_vsi(pf
, i
)
1918 if (pf
->vsi
[i
] && (pf
->vsi
[i
]->type
== ICE_VSI_VF
||
1919 pf
->vsi
[i
]->type
== ICE_VSI_SWITCHDEV_CTRL
))
1920 ice_for_each_traffic_class(tc
)
1921 ice_lag_move_vf_nodes_tc_sync(lag
, dest_hw
, i
,
1926 * ice_init_lag - initialize support for LAG
1929 * Alloc memory for LAG structs and initialize the elements.
1930 * Memory will be freed in ice_deinit_lag
1932 int ice_init_lag(struct ice_pf
*pf
)
1934 struct device
*dev
= ice_pf_to_dev(pf
);
1935 struct ice_lag
*lag
;
1936 struct ice_vsi
*vsi
;
1937 u64 recipe_bits
= 0;
1940 ice_lag_init_feature_support_flag(pf
);
1942 pf
->lag
= kzalloc(sizeof(*lag
), GFP_KERNEL
);
1947 vsi
= ice_get_main_vsi(pf
);
1949 dev_err(dev
, "couldn't get main vsi, link aggregation init fail\n");
1955 lag
->netdev
= vsi
->netdev
;
1956 lag
->role
= ICE_LAG_NONE
;
1957 lag
->active_port
= ICE_LAG_INVALID_PORT
;
1958 lag
->bonded
= false;
1959 lag
->upper_netdev
= NULL
;
1960 lag
->notif_block
.notifier_call
= NULL
;
1962 err
= ice_register_lag_handler(lag
);
1964 dev_warn(dev
, "INIT LAG: Failed to register event handler\n");
1968 err
= ice_create_lag_recipe(&pf
->hw
, &lag
->pf_recipe
,
1969 ice_dflt_vsi_rcp
, 1);
1973 err
= ice_create_lag_recipe(&pf
->hw
, &lag
->lport_recipe
,
1978 /* associate recipes to profiles */
1979 for (n
= 0; n
< ICE_PROFID_IPV6_GTPU_IPV6_TCP_INNER
; n
++) {
1980 err
= ice_aq_get_recipe_to_profile(&pf
->hw
, n
,
1981 (u8
*)&recipe_bits
, NULL
);
1985 if (recipe_bits
& BIT(ICE_SW_LKUP_DFLT
)) {
1986 recipe_bits
|= BIT(lag
->pf_recipe
) |
1987 BIT(lag
->lport_recipe
);
1988 ice_aq_map_recipe_to_profile(&pf
->hw
, n
,
1989 (u8
*)&recipe_bits
, NULL
);
1993 ice_display_lag_info(lag
);
1995 dev_dbg(dev
, "INIT LAG complete\n");
1999 ice_free_hw_res(&pf
->hw
, ICE_AQC_RES_TYPE_RECIPE
, 1,
2000 &pf
->lag
->pf_recipe
);
2008 * ice_deinit_lag - Clean up LAG
2011 * Clean up kernel LAG info and free memory
2012 * This function is meant to only be called on driver remove/shutdown
2014 void ice_deinit_lag(struct ice_pf
*pf
)
2016 struct ice_lag
*lag
;
2024 ice_unregister_lag_handler(lag
);
2026 flush_workqueue(ice_lag_wq
);
2028 ice_free_hw_res(&pf
->hw
, ICE_AQC_RES_TYPE_RECIPE
, 1,
2029 &pf
->lag
->pf_recipe
);
2030 ice_free_hw_res(&pf
->hw
, ICE_AQC_RES_TYPE_RECIPE
, 1,
2031 &pf
->lag
->lport_recipe
);
2039 * ice_lag_rebuild - rebuild lag resources after reset
2040 * @pf: pointer to local pf struct
2042 * PF resets are promoted to CORER resets when interface in an aggregate. This
2043 * means that we need to rebuild the PF resources for the interface. Since
2044 * this will happen outside the normal event processing, need to acquire the lag
2047 * This function will also evaluate the VF resources if this is the primary
2050 void ice_lag_rebuild(struct ice_pf
*pf
)
2052 struct ice_lag_netdev_list ndlist
;
2053 struct ice_lag
*lag
, *prim_lag
;
2054 struct list_head
*tmp
, *n
;
2055 u8 act_port
, loc_port
;
2057 if (!pf
->lag
|| !pf
->lag
->bonded
)
2060 mutex_lock(&pf
->lag_mutex
);
2066 struct ice_lag_netdev_list
*nl
;
2067 struct net_device
*tmp_nd
;
2069 INIT_LIST_HEAD(&ndlist
.node
);
2071 for_each_netdev_in_bond_rcu(lag
->upper_netdev
, tmp_nd
) {
2072 nl
= kzalloc(sizeof(*nl
), GFP_ATOMIC
);
2076 nl
->netdev
= tmp_nd
;
2077 list_add(&nl
->node
, &ndlist
.node
);
2080 lag
->netdev_head
= &ndlist
.node
;
2081 prim_lag
= ice_lag_find_primary(lag
);
2085 dev_dbg(ice_pf_to_dev(pf
), "No primary interface in aggregate, can't rebuild\n");
2086 goto lag_rebuild_out
;
2089 act_port
= prim_lag
->active_port
;
2090 loc_port
= lag
->pf
->hw
.port_info
->lport
;
2092 /* configure SWID for this port */
2094 ice_lag_primary_swid(lag
, true);
2096 ice_lag_set_swid(prim_lag
->pf
->hw
.port_info
->sw_id
, lag
, true);
2097 ice_lag_add_prune_list(prim_lag
, pf
);
2098 if (act_port
== loc_port
)
2099 ice_lag_move_vf_nodes_sync(prim_lag
, &pf
->hw
);
2102 ice_lag_cfg_cp_fltr(lag
, true);
2104 if (lag
->pf_rule_id
)
2105 if (ice_lag_cfg_dflt_fltr(lag
, true))
2106 dev_err(ice_pf_to_dev(pf
), "Error adding default VSI rule in rebuild\n");
2108 ice_clear_rdma_cap(pf
);
2110 list_for_each_safe(tmp
, n
, &ndlist
.node
) {
2111 struct ice_lag_netdev_list
*entry
;
2113 entry
= list_entry(tmp
, struct ice_lag_netdev_list
, node
);
2114 list_del(&entry
->node
);
2117 mutex_unlock(&pf
->lag_mutex
);
2121 * ice_lag_is_switchdev_running
2122 * @pf: pointer to PF structure
2124 * Check if switchdev is running on any of the interfaces connected to lag.
2126 bool ice_lag_is_switchdev_running(struct ice_pf
*pf
)
2128 struct ice_lag
*lag
= pf
->lag
;
2129 struct net_device
*tmp_nd
;
2131 if (!ice_is_feature_supported(pf
, ICE_F_SRIOV_LAG
) || !lag
)
2135 for_each_netdev_in_bond_rcu(lag
->upper_netdev
, tmp_nd
) {
2136 struct ice_netdev_priv
*priv
= netdev_priv(tmp_nd
);
2138 if (!netif_is_ice(tmp_nd
) || !priv
|| !priv
->vsi
||
2142 if (ice_is_switchdev_running(priv
->vsi
->back
)) {