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 |= FIELD_PREP(ICE_SINGLE_ACT_VSI_ID_M, vsi_num);
213 s_rule->hdr.type = cpu_to_le16(ICE_AQC_SW_RULES_T_LKUP_RX);
214 s_rule->recipe_id = cpu_to_le16(recipe_id);
215 s_rule->src = cpu_to_le16(hw->port_info->lport);
216 s_rule->act = cpu_to_le32(act);
217 s_rule->hdr_len = cpu_to_le16(DUMMY_ETH_HDR_LEN);
218 opc = ice_aqc_opc_add_sw_rules;
220 s_rule->index = cpu_to_le16(*rule_idx);
221 opc = ice_aqc_opc_remove_sw_rules;
224 err = ice_aq_sw_rules(&lag->pf->hw, s_rule, s_rule_sz, 1, opc, NULL);
229 *rule_idx = le16_to_cpu(s_rule->index);
239 * ice_lag_cfg_dflt_fltr - Add/Remove default VSI rule for LAG
240 * @lag: lag struct for local interface
241 * @add: boolean on whether to add filter
244 ice_lag_cfg_dflt_fltr(struct ice_lag *lag, bool add)
246 u32 act = ICE_SINGLE_ACT_VSI_FORWARDING |
247 ICE_SINGLE_ACT_VALID_BIT | ICE_SINGLE_ACT_LAN_ENABLE;
249 return ice_lag_cfg_fltr(lag, act, lag->pf_recipe,
250 &lag->pf_rule_id, add);
254 * ice_lag_cfg_drop_fltr - Add/Remove lport drop rule
255 * @lag: lag struct for local interface
256 * @add: boolean on whether to add filter
259 ice_lag_cfg_drop_fltr(struct ice_lag *lag, bool add)
261 u32 act = ICE_SINGLE_ACT_VSI_FORWARDING |
262 ICE_SINGLE_ACT_VALID_BIT |
265 return ice_lag_cfg_fltr(lag, act, lag->lport_recipe,
266 &lag->lport_rule_idx, add);
270 * ice_lag_cfg_pf_fltrs - set filters up for new active port
271 * @lag: local interfaces lag struct
272 * @ptr: opaque data containing notifier event
275 ice_lag_cfg_pf_fltrs(struct ice_lag *lag, void *ptr)
277 struct netdev_notifier_bonding_info *info;
278 struct netdev_bonding_info *bonding_info;
279 struct net_device *event_netdev;
282 event_netdev = netdev_notifier_info_to_dev(ptr);
283 /* not for this netdev */
284 if (event_netdev != lag->netdev)
287 info = (struct netdev_notifier_bonding_info *)ptr;
288 bonding_info = &info->bonding_info;
289 dev = ice_pf_to_dev(lag->pf);
291 /* interface not active - remove old default VSI rule */
292 if (bonding_info->slave.state && lag->pf_rule_id) {
293 if (ice_lag_cfg_dflt_fltr(lag, false))
294 dev_err(dev, "Error removing old default VSI filter\n");
295 if (ice_lag_cfg_drop_fltr(lag, true))
296 dev_err(dev, "Error adding new drop filter\n");
300 /* interface becoming active - add new default VSI rule */
301 if (!bonding_info->slave.state && !lag->pf_rule_id) {
302 if (ice_lag_cfg_dflt_fltr(lag, true))
303 dev_err(dev, "Error adding new default VSI filter\n");
304 if (lag->lport_rule_idx && ice_lag_cfg_drop_fltr(lag, false))
305 dev_err(dev, "Error removing old drop filter\n");
310 * ice_display_lag_info - print LAG info
311 * @lag: LAG info struct
313 static void ice_display_lag_info(struct ice_lag *lag)
315 const char *name, *upper, *role, *bonded, *primary;
316 struct device *dev = &lag->pf->pdev->dev;
318 name = lag->netdev ? netdev_name(lag->netdev) : "unset";
319 upper = lag->upper_netdev ? netdev_name(lag->upper_netdev) : "unset";
320 primary = lag->primary ? "TRUE" : "FALSE";
321 bonded = lag->bonded ? "BONDED" : "UNBONDED";
327 case ICE_LAG_PRIMARY:
340 dev_dbg(dev, "%s %s, upper:%s, role:%s, primary:%s\n", name, bonded,
341 upper, role, primary);
345 * ice_lag_qbuf_recfg - generate a buffer of queues for a reconfigure command
346 * @hw: HW struct that contains the queue contexts
347 * @qbuf: pointer to buffer to populate
348 * @vsi_num: index of the VSI in PF space
349 * @numq: number of queues to search for
350 * @tc: traffic class that contains the queues
352 * function returns the number of valid queues in buffer
355 ice_lag_qbuf_recfg(struct ice_hw *hw, struct ice_aqc_cfg_txqs_buf *qbuf,
356 u16 vsi_num, u16 numq, u8 tc)
358 struct ice_q_ctx *q_ctx;
364 for (i = 0; i < numq; i++) {
365 q_ctx = ice_get_lan_q_ctx(hw, vsi_num, tc, i);
367 dev_dbg(ice_hw_to_dev(hw), "%s queue %d NO Q CONTEXT\n",
371 if (q_ctx->q_teid == ICE_INVAL_TEID) {
372 dev_dbg(ice_hw_to_dev(hw), "%s queue %d INVAL TEID\n",
376 if (q_ctx->q_handle == ICE_INVAL_Q_HANDLE) {
377 dev_dbg(ice_hw_to_dev(hw), "%s queue %d INVAL Q HANDLE\n",
382 qid = pf->vsi[vsi_num]->txq_map[q_ctx->q_handle];
383 qbuf->queue_info[count].q_handle = cpu_to_le16(qid);
384 qbuf->queue_info[count].tc = tc;
385 qbuf->queue_info[count].q_teid = cpu_to_le32(q_ctx->q_teid);
393 * ice_lag_get_sched_parent - locate or create a sched node parent
394 * @hw: HW struct for getting parent in
395 * @tc: traffic class on parent/node
397 static struct ice_sched_node *
398 ice_lag_get_sched_parent(struct ice_hw *hw, u8 tc)
400 struct ice_sched_node *tc_node, *aggnode, *parent = NULL;
401 u16 num_nodes[ICE_AQC_TOPO_MAX_LEVEL_NUM] = { 0 };
402 struct ice_port_info *pi = hw->port_info;
407 dev = ice_hw_to_dev(hw);
409 tc_node = ice_sched_get_tc_node(pi, tc);
411 dev_warn(dev, "Failure to find TC node for LAG move\n");
415 aggnode = ice_sched_get_agg_node(pi, tc_node, ICE_DFLT_AGG_ID);
417 dev_warn(dev, "Failure to find aggregate node for LAG move\n");
421 aggl = ice_sched_get_agg_layer(hw);
422 vsil = ice_sched_get_vsi_layer(hw);
424 for (n = aggl + 1; n < vsil; n++)
427 for (n = 0; n < aggnode->num_children; n++) {
428 parent = ice_sched_get_free_vsi_parent(hw, aggnode->children[n],
434 /* if free parent not found - add one */
436 for (n = aggl + 1; n < vsil; n++) {
441 err = ice_sched_add_nodes_to_layer(pi, tc_node, parent, n,
442 num_nodes[n], &first_teid,
444 if (err || num_nodes[n] != num_nodes_added)
448 parent = ice_sched_find_node_by_teid(tc_node,
451 parent = parent->children[0];
453 dev_warn(dev, "Failure to add new parent for LAG move\n");
462 * ice_lag_move_vf_node_tc - move scheduling nodes for one VF on one TC
463 * @lag: lag info struct
464 * @oldport: lport of previous nodes location
465 * @newport: lport of destination nodes location
466 * @vsi_num: array index of VSI in PF space
467 * @tc: traffic class to move
470 ice_lag_move_vf_node_tc(struct ice_lag *lag, u8 oldport, u8 newport,
473 DEFINE_FLEX(struct ice_aqc_move_elem, buf, teid, 1);
474 struct device *dev = ice_pf_to_dev(lag->pf);
475 u16 numq, valq, num_moved, qbuf_size;
476 u16 buf_size = __struct_size(buf);
477 struct ice_aqc_cfg_txqs_buf *qbuf;
478 struct ice_sched_node *n_prt;
479 struct ice_hw *new_hw = NULL;
480 __le32 teid, parent_teid;
481 struct ice_vsi_ctx *ctx;
484 ctx = ice_get_vsi_ctx(&lag->pf->hw, vsi_num);
486 dev_warn(dev, "Unable to locate VSI context for LAG failover\n");
490 /* check to see if this VF is enabled on this TC */
491 if (!ctx->sched.vsi_node[tc])
494 /* locate HW struct for destination port */
495 new_hw = ice_lag_find_hw_by_lport(lag, newport);
497 dev_warn(dev, "Unable to locate HW struct for LAG node destination\n");
501 numq = ctx->num_lan_q_entries[tc];
502 teid = ctx->sched.vsi_node[tc]->info.node_teid;
503 tmp_teid = le32_to_cpu(teid);
504 parent_teid = ctx->sched.vsi_node[tc]->info.parent_teid;
505 /* if no teid assigned or numq == 0, then this TC is not active */
506 if (!tmp_teid || !numq)
509 /* suspend VSI subtree for Traffic Class "tc" on
512 if (ice_sched_suspend_resume_elems(&lag->pf->hw, 1, &tmp_teid, true))
513 dev_dbg(dev, "Problem suspending traffic for LAG node move\n");
515 /* reconfigure all VF's queues on this Traffic Class
518 qbuf_size = struct_size(qbuf, queue_info, numq);
519 qbuf = kzalloc(qbuf_size, GFP_KERNEL);
521 dev_warn(dev, "Failure allocating memory for VF queue recfg buffer\n");
525 /* add the per queue info for the reconfigure command buffer */
526 valq = ice_lag_qbuf_recfg(&lag->pf->hw, qbuf, vsi_num, numq, tc);
528 dev_dbg(dev, "No valid queues found for LAG failover\n");
532 if (ice_aq_cfg_lan_txq(&lag->pf->hw, qbuf, qbuf_size, valq, oldport,
534 dev_warn(dev, "Failure to configure queues for LAG failover\n");
541 /* find new parent in destination port's tree for VF VSI node on this
544 n_prt = ice_lag_get_sched_parent(new_hw, tc);
548 /* Move Vf's VSI node for this TC to newport's scheduler tree */
549 buf->hdr.src_parent_teid = parent_teid;
550 buf->hdr.dest_parent_teid = n_prt->info.node_teid;
551 buf->hdr.num_elems = cpu_to_le16(1);
552 buf->hdr.mode = ICE_AQC_MOVE_ELEM_MODE_KEEP_OWN;
555 if (ice_aq_move_sched_elems(&lag->pf->hw, buf, buf_size, &num_moved))
556 dev_warn(dev, "Failure to move VF nodes for failover\n");
558 ice_sched_update_parent(n_prt, ctx->sched.vsi_node[tc]);
566 /* restart traffic for VSI node */
567 if (ice_sched_suspend_resume_elems(&lag->pf->hw, 1, &tmp_teid, false))
568 dev_dbg(dev, "Problem restarting traffic for LAG node move\n");
572 * ice_lag_build_netdev_list - populate the lag struct's netdev list
573 * @lag: local lag struct
574 * @ndlist: pointer to netdev list to populate
576 static void ice_lag_build_netdev_list(struct ice_lag *lag,
577 struct ice_lag_netdev_list *ndlist)
579 struct ice_lag_netdev_list *nl;
580 struct net_device *tmp_nd;
582 INIT_LIST_HEAD(&ndlist->node);
584 for_each_netdev_in_bond_rcu(lag->upper_netdev, tmp_nd) {
585 nl = kzalloc(sizeof(*nl), GFP_ATOMIC);
590 list_add(&nl->node, &ndlist->node);
593 lag->netdev_head = &ndlist->node;
597 * ice_lag_destroy_netdev_list - free lag struct's netdev list
598 * @lag: pointer to local lag struct
599 * @ndlist: pointer to lag struct netdev list
601 static void ice_lag_destroy_netdev_list(struct ice_lag *lag,
602 struct ice_lag_netdev_list *ndlist)
604 struct ice_lag_netdev_list *entry, *n;
607 list_for_each_entry_safe(entry, n, &ndlist->node, node) {
608 list_del(&entry->node);
612 lag->netdev_head = NULL;
616 * ice_lag_move_single_vf_nodes - Move Tx scheduling nodes for single VF
617 * @lag: primary interface LAG struct
618 * @oldport: lport of previous interface
619 * @newport: lport of destination interface
620 * @vsi_num: SW index of VF's VSI
623 ice_lag_move_single_vf_nodes(struct ice_lag *lag, u8 oldport, u8 newport,
628 ice_for_each_traffic_class(tc)
629 ice_lag_move_vf_node_tc(lag, oldport, newport, vsi_num, tc);
633 * ice_lag_move_new_vf_nodes - Move Tx scheduling nodes for a VF if required
634 * @vf: the VF to move Tx nodes for
636 * Called just after configuring new VF queues. Check whether the VF Tx
637 * scheduling nodes need to be updated to fail over to the active port. If so,
640 void ice_lag_move_new_vf_nodes(struct ice_vf *vf)
642 struct ice_lag_netdev_list ndlist;
643 u8 pri_port, act_port;
648 vsi = ice_get_vf_vsi(vf);
653 if (WARN_ON(vsi->type != ICE_VSI_VF))
659 mutex_lock(&pf->lag_mutex);
663 pri_port = pf->hw.port_info->lport;
664 act_port = lag->active_port;
666 if (lag->upper_netdev)
667 ice_lag_build_netdev_list(lag, &ndlist);
669 if (ice_is_feature_supported(pf, ICE_F_SRIOV_LAG) &&
670 lag->bonded && lag->primary && pri_port != act_port &&
671 !list_empty(lag->netdev_head))
672 ice_lag_move_single_vf_nodes(lag, pri_port, act_port, vsi->idx);
674 ice_lag_destroy_netdev_list(lag, &ndlist);
677 mutex_unlock(&pf->lag_mutex);
681 * ice_lag_move_vf_nodes - move Tx scheduling nodes for all VFs to new port
682 * @lag: lag info struct
683 * @oldport: lport of previous interface
684 * @newport: lport of destination interface
686 static void ice_lag_move_vf_nodes(struct ice_lag *lag, u8 oldport, u8 newport)
695 ice_for_each_vsi(pf, i)
696 if (pf->vsi[i] && (pf->vsi[i]->type == ICE_VSI_VF ||
697 pf->vsi[i]->type == ICE_VSI_SWITCHDEV_CTRL))
698 ice_lag_move_single_vf_nodes(lag, oldport, newport, i);
702 * ice_lag_move_vf_nodes_cfg - move vf nodes outside LAG netdev event context
703 * @lag: local lag struct
704 * @src_prt: lport value for source port
705 * @dst_prt: lport value for destination port
707 * This function is used to move nodes during an out-of-netdev-event situation,
708 * primarily when the driver needs to reconfigure or recreate resources.
710 * Must be called while holding the lag_mutex to avoid lag events from
711 * processing while out-of-sync moves are happening. Also, paired moves,
712 * such as used in a reset flow, should both be called under the same mutex
713 * lock to avoid changes between start of reset and end of reset.
715 void ice_lag_move_vf_nodes_cfg(struct ice_lag *lag, u8 src_prt, u8 dst_prt)
717 struct ice_lag_netdev_list ndlist;
719 ice_lag_build_netdev_list(lag, &ndlist);
720 ice_lag_move_vf_nodes(lag, src_prt, dst_prt);
721 ice_lag_destroy_netdev_list(lag, &ndlist);
724 #define ICE_LAG_SRIOV_CP_RECIPE 10
725 #define ICE_LAG_SRIOV_TRAIN_PKT_LEN 16
728 * ice_lag_cfg_cp_fltr - configure filter for control packets
729 * @lag: local interface's lag struct
730 * @add: add or remove rule
733 ice_lag_cfg_cp_fltr(struct ice_lag *lag, bool add)
735 struct ice_sw_rule_lkup_rx_tx *s_rule = NULL;
739 vsi = lag->pf->vsi[0];
741 buf_len = ICE_SW_RULE_RX_TX_HDR_SIZE(s_rule,
742 ICE_LAG_SRIOV_TRAIN_PKT_LEN);
743 s_rule = kzalloc(buf_len, GFP_KERNEL);
745 netdev_warn(lag->netdev, "-ENOMEM error configuring CP filter\n");
750 s_rule->hdr.type = cpu_to_le16(ICE_AQC_SW_RULES_T_LKUP_RX);
751 s_rule->recipe_id = cpu_to_le16(ICE_LAG_SRIOV_CP_RECIPE);
752 s_rule->src = cpu_to_le16(vsi->port_info->lport);
753 s_rule->act = cpu_to_le32(ICE_FWD_TO_VSI |
754 ICE_SINGLE_ACT_LAN_ENABLE |
755 ICE_SINGLE_ACT_VALID_BIT |
756 FIELD_PREP(ICE_SINGLE_ACT_VSI_ID_M, vsi->vsi_num));
757 s_rule->hdr_len = cpu_to_le16(ICE_LAG_SRIOV_TRAIN_PKT_LEN);
758 memcpy(s_rule->hdr_data, lacp_train_pkt, LACP_TRAIN_PKT_LEN);
759 opc = ice_aqc_opc_add_sw_rules;
761 opc = ice_aqc_opc_remove_sw_rules;
762 s_rule->index = cpu_to_le16(lag->cp_rule_idx);
764 if (ice_aq_sw_rules(&lag->pf->hw, s_rule, buf_len, 1, opc, NULL)) {
765 netdev_warn(lag->netdev, "Error %s CP rule for fail-over\n",
766 add ? "ADDING" : "REMOVING");
771 lag->cp_rule_idx = le16_to_cpu(s_rule->index);
773 lag->cp_rule_idx = 0;
780 * ice_lag_info_event - handle NETDEV_BONDING_INFO event
781 * @lag: LAG info struct
782 * @ptr: opaque data pointer
784 * ptr is to be cast to (netdev_notifier_bonding_info *)
786 static void ice_lag_info_event(struct ice_lag *lag, void *ptr)
788 struct netdev_notifier_bonding_info *info;
789 struct netdev_bonding_info *bonding_info;
790 struct net_device *event_netdev;
791 const char *lag_netdev_name;
793 event_netdev = netdev_notifier_info_to_dev(ptr);
795 lag_netdev_name = netdev_name(lag->netdev);
796 bonding_info = &info->bonding_info;
798 if (event_netdev != lag->netdev || !lag->bonded || !lag->upper_netdev)
801 if (bonding_info->master.bond_mode != BOND_MODE_ACTIVEBACKUP) {
802 netdev_dbg(lag->netdev, "Bonding event recv, but mode not active/backup\n");
806 if (strcmp(bonding_info->slave.slave_name, lag_netdev_name)) {
807 netdev_dbg(lag->netdev, "Bonding event recv, but secondary info not for us\n");
811 if (bonding_info->slave.state)
812 ice_lag_set_backup(lag);
814 ice_lag_set_primary(lag);
817 ice_display_lag_info(lag);
821 * ice_lag_reclaim_vf_tc - move scheduling nodes back to primary interface
822 * @lag: primary interface lag struct
823 * @src_hw: HW struct current node location
824 * @vsi_num: VSI index in PF space
825 * @tc: traffic class to move
828 ice_lag_reclaim_vf_tc(struct ice_lag *lag, struct ice_hw *src_hw, u16 vsi_num,
831 DEFINE_FLEX(struct ice_aqc_move_elem, buf, teid, 1);
832 struct device *dev = ice_pf_to_dev(lag->pf);
833 u16 numq, valq, num_moved, qbuf_size;
834 u16 buf_size = __struct_size(buf);
835 struct ice_aqc_cfg_txqs_buf *qbuf;
836 struct ice_sched_node *n_prt;
837 __le32 teid, parent_teid;
838 struct ice_vsi_ctx *ctx;
843 ctx = ice_get_vsi_ctx(hw, vsi_num);
845 dev_warn(dev, "Unable to locate VSI context for LAG reclaim\n");
849 /* check to see if this VF is enabled on this TC */
850 if (!ctx->sched.vsi_node[tc])
853 numq = ctx->num_lan_q_entries[tc];
854 teid = ctx->sched.vsi_node[tc]->info.node_teid;
855 tmp_teid = le32_to_cpu(teid);
856 parent_teid = ctx->sched.vsi_node[tc]->info.parent_teid;
858 /* if !teid or !numq, then this TC is not active */
859 if (!tmp_teid || !numq)
862 /* suspend traffic */
863 if (ice_sched_suspend_resume_elems(hw, 1, &tmp_teid, true))
864 dev_dbg(dev, "Problem suspending traffic for LAG node move\n");
866 /* reconfig queues for new port */
867 qbuf_size = struct_size(qbuf, queue_info, numq);
868 qbuf = kzalloc(qbuf_size, GFP_KERNEL);
870 dev_warn(dev, "Failure allocating memory for VF queue recfg buffer\n");
874 /* add the per queue info for the reconfigure command buffer */
875 valq = ice_lag_qbuf_recfg(hw, qbuf, vsi_num, numq, tc);
877 dev_dbg(dev, "No valid queues found for LAG reclaim\n");
881 if (ice_aq_cfg_lan_txq(hw, qbuf, qbuf_size, numq,
882 src_hw->port_info->lport, hw->port_info->lport,
884 dev_warn(dev, "Failure to configure queues for LAG failover\n");
891 /* find parent in primary tree */
892 n_prt = ice_lag_get_sched_parent(hw, tc);
896 /* Move node to new parent */
897 buf->hdr.src_parent_teid = parent_teid;
898 buf->hdr.dest_parent_teid = n_prt->info.node_teid;
899 buf->hdr.num_elems = cpu_to_le16(1);
900 buf->hdr.mode = ICE_AQC_MOVE_ELEM_MODE_KEEP_OWN;
903 if (ice_aq_move_sched_elems(&lag->pf->hw, buf, buf_size, &num_moved))
904 dev_warn(dev, "Failure to move VF nodes for LAG reclaim\n");
906 ice_sched_update_parent(n_prt, ctx->sched.vsi_node[tc]);
914 /* restart traffic */
915 if (ice_sched_suspend_resume_elems(hw, 1, &tmp_teid, false))
916 dev_warn(dev, "Problem restarting traffic for LAG node reclaim\n");
920 * ice_lag_reclaim_vf_nodes - When interface leaving bond primary reclaims nodes
921 * @lag: primary interface lag struct
922 * @src_hw: HW struct for current node location
925 ice_lag_reclaim_vf_nodes(struct ice_lag *lag, struct ice_hw *src_hw)
930 if (!lag->primary || !src_hw)
934 ice_for_each_vsi(pf, i)
935 if (pf->vsi[i] && (pf->vsi[i]->type == ICE_VSI_VF ||
936 pf->vsi[i]->type == ICE_VSI_SWITCHDEV_CTRL))
937 ice_for_each_traffic_class(tc)
938 ice_lag_reclaim_vf_tc(lag, src_hw, i, tc);
942 * ice_lag_link - handle LAG link event
943 * @lag: LAG info struct
945 static void ice_lag_link(struct ice_lag *lag)
947 struct ice_pf *pf = lag->pf;
950 dev_warn(ice_pf_to_dev(pf), "%s Already part of a bond\n",
951 netdev_name(lag->netdev));
954 lag->role = ICE_LAG_UNSET;
955 netdev_info(lag->netdev, "Shared SR-IOV resources in bond are active\n");
959 * ice_lag_unlink - handle unlink event
960 * @lag: LAG info struct
962 static void ice_lag_unlink(struct ice_lag *lag)
964 u8 pri_port, act_port, loc_port;
965 struct ice_pf *pf = lag->pf;
968 netdev_dbg(lag->netdev, "bonding unlink event on non-LAG netdev\n");
973 act_port = lag->active_port;
974 pri_port = lag->pf->hw.port_info->lport;
975 if (act_port != pri_port && act_port != ICE_LAG_INVALID_PORT)
976 ice_lag_move_vf_nodes(lag, act_port, pri_port);
977 lag->primary = false;
978 lag->active_port = ICE_LAG_INVALID_PORT;
980 struct ice_lag *primary_lag;
982 primary_lag = ice_lag_find_primary(lag);
984 act_port = primary_lag->active_port;
985 pri_port = primary_lag->pf->hw.port_info->lport;
986 loc_port = pf->hw.port_info->lport;
987 if (act_port == loc_port &&
988 act_port != ICE_LAG_INVALID_PORT) {
989 ice_lag_reclaim_vf_nodes(primary_lag,
991 primary_lag->active_port = ICE_LAG_INVALID_PORT;
997 lag->role = ICE_LAG_NONE;
998 lag->upper_netdev = NULL;
1002 * ice_lag_link_unlink - helper function to call lag_link/unlink
1003 * @lag: lag info struct
1004 * @ptr: opaque pointer data
1006 static void ice_lag_link_unlink(struct ice_lag *lag, void *ptr)
1008 struct net_device *netdev = netdev_notifier_info_to_dev(ptr);
1009 struct netdev_notifier_changeupper_info *info = ptr;
1011 if (netdev != lag->netdev)
1017 ice_lag_unlink(lag);
1021 * ice_lag_set_swid - set the SWID on secondary interface
1022 * @primary_swid: primary interface's SWID
1023 * @local_lag: local interfaces LAG struct
1024 * @link: Is this a linking activity
1026 * If link is false, then primary_swid should be expected to not be valid
1027 * This function should never be called in interrupt context.
1030 ice_lag_set_swid(u16 primary_swid, struct ice_lag *local_lag,
1033 struct ice_aqc_alloc_free_res_elem *buf;
1034 struct ice_aqc_set_port_params *cmd;
1035 struct ice_aq_desc desc;
1039 buf_len = struct_size(buf, elem, 1);
1040 buf = kzalloc(buf_len, GFP_KERNEL);
1042 dev_err(ice_pf_to_dev(local_lag->pf), "-ENOMEM error setting SWID\n");
1046 buf->num_elems = cpu_to_le16(1);
1047 buf->res_type = cpu_to_le16(ICE_AQC_RES_TYPE_SWID);
1048 /* if unlinnking need to free the shared resource */
1049 if (!link && local_lag->bond_swid) {
1050 buf->elem[0].e.sw_resp = cpu_to_le16(local_lag->bond_swid);
1051 status = ice_aq_alloc_free_res(&local_lag->pf->hw, buf,
1052 buf_len, ice_aqc_opc_free_res);
1054 dev_err(ice_pf_to_dev(local_lag->pf), "Error freeing SWID during LAG unlink\n");
1055 local_lag->bond_swid = 0;
1059 buf->res_type |= cpu_to_le16(ICE_LAG_RES_SHARED |
1061 /* store the primary's SWID in case it leaves bond first */
1062 local_lag->bond_swid = primary_swid;
1063 buf->elem[0].e.sw_resp = cpu_to_le16(local_lag->bond_swid);
1065 buf->elem[0].e.sw_resp =
1066 cpu_to_le16(local_lag->pf->hw.port_info->sw_id);
1069 status = ice_aq_alloc_free_res(&local_lag->pf->hw, buf, buf_len,
1070 ice_aqc_opc_alloc_res);
1072 dev_err(ice_pf_to_dev(local_lag->pf), "Error subscribing to SWID 0x%04X\n",
1073 local_lag->bond_swid);
1077 /* Configure port param SWID to correct value */
1079 swid = primary_swid;
1081 swid = local_lag->pf->hw.port_info->sw_id;
1083 cmd = &desc.params.set_port_params;
1084 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_port_params);
1086 cmd->swid = cpu_to_le16(ICE_AQC_PORT_SWID_VALID | swid);
1087 /* If this is happening in reset context, it is possible that the
1088 * primary interface has not finished setting its SWID to SHARED
1089 * yet. Allow retries to account for this timing issue between
1092 for (i = 0; i < ICE_LAG_RESET_RETRIES; i++) {
1093 status = ice_aq_send_cmd(&local_lag->pf->hw, &desc, NULL, 0,
1098 usleep_range(1000, 2000);
1102 dev_err(ice_pf_to_dev(local_lag->pf), "Error setting SWID in port params %d\n",
1107 * ice_lag_primary_swid - set/clear the SHARED attrib of primary's SWID
1108 * @lag: primary interface's lag struct
1109 * @link: is this a linking activity
1111 * Implement setting primary SWID as shared using 0x020B
1113 static void ice_lag_primary_swid(struct ice_lag *lag, bool link)
1119 swid = hw->port_info->sw_id;
1121 if (ice_share_res(hw, ICE_AQC_RES_TYPE_SWID, link, swid))
1122 dev_warn(ice_pf_to_dev(lag->pf), "Failure to set primary interface shared status\n");
1126 * ice_lag_add_prune_list - Adds event_pf's VSI to primary's prune list
1127 * @lag: lag info struct
1128 * @event_pf: PF struct for VSI we are adding to primary's prune list
1130 static void ice_lag_add_prune_list(struct ice_lag *lag, struct ice_pf *event_pf)
1132 u16 num_vsi, rule_buf_sz, vsi_list_id, event_vsi_num, prim_vsi_idx;
1133 struct ice_sw_rule_vsi_list *s_rule = NULL;
1138 dev = ice_pf_to_dev(lag->pf);
1139 event_vsi_num = event_pf->vsi[0]->vsi_num;
1140 prim_vsi_idx = lag->pf->vsi[0]->idx;
1142 if (!ice_find_vsi_list_entry(&lag->pf->hw, ICE_SW_LKUP_VLAN,
1143 prim_vsi_idx, &vsi_list_id)) {
1144 dev_warn(dev, "Could not locate prune list when setting up SRIOV LAG\n");
1148 rule_buf_sz = (u16)ICE_SW_RULE_VSI_LIST_SIZE(s_rule, num_vsi);
1149 s_rule = kzalloc(rule_buf_sz, GFP_KERNEL);
1151 dev_warn(dev, "Error allocating space for prune list when configuring SRIOV LAG\n");
1155 s_rule->hdr.type = cpu_to_le16(ICE_AQC_SW_RULES_T_PRUNE_LIST_SET);
1156 s_rule->index = cpu_to_le16(vsi_list_id);
1157 s_rule->number_vsi = cpu_to_le16(num_vsi);
1158 s_rule->vsi[0] = cpu_to_le16(event_vsi_num);
1160 if (ice_aq_sw_rules(&event_pf->hw, s_rule, rule_buf_sz, 1,
1161 ice_aqc_opc_update_sw_rules, NULL))
1162 dev_warn(dev, "Error adding VSI prune list\n");
1167 * ice_lag_del_prune_list - Remove secondary's vsi from primary's prune list
1168 * @lag: primary interface's ice_lag struct
1169 * @event_pf: PF struct for unlinking interface
1171 static void ice_lag_del_prune_list(struct ice_lag *lag, struct ice_pf *event_pf)
1173 u16 num_vsi, vsi_num, vsi_idx, rule_buf_sz, vsi_list_id;
1174 struct ice_sw_rule_vsi_list *s_rule = NULL;
1179 dev = ice_pf_to_dev(lag->pf);
1180 vsi_num = event_pf->vsi[0]->vsi_num;
1181 vsi_idx = lag->pf->vsi[0]->idx;
1183 if (!ice_find_vsi_list_entry(&lag->pf->hw, ICE_SW_LKUP_VLAN,
1184 vsi_idx, &vsi_list_id)) {
1185 dev_warn(dev, "Could not locate prune list when unwinding SRIOV LAG\n");
1189 rule_buf_sz = (u16)ICE_SW_RULE_VSI_LIST_SIZE(s_rule, num_vsi);
1190 s_rule = kzalloc(rule_buf_sz, GFP_KERNEL);
1192 dev_warn(dev, "Error allocating prune list when unwinding SRIOV LAG\n");
1196 s_rule->hdr.type = cpu_to_le16(ICE_AQC_SW_RULES_T_PRUNE_LIST_CLEAR);
1197 s_rule->index = cpu_to_le16(vsi_list_id);
1198 s_rule->number_vsi = cpu_to_le16(num_vsi);
1199 s_rule->vsi[0] = cpu_to_le16(vsi_num);
1201 if (ice_aq_sw_rules(&event_pf->hw, (struct ice_aqc_sw_rules *)s_rule,
1202 rule_buf_sz, 1, ice_aqc_opc_update_sw_rules, NULL))
1203 dev_warn(dev, "Error clearing VSI prune list\n");
1209 * ice_lag_init_feature_support_flag - Check for NVM support for LAG
1212 static void ice_lag_init_feature_support_flag(struct ice_pf *pf)
1214 struct ice_hw_common_caps *caps;
1216 caps = &pf->hw.dev_caps.common_cap;
1218 ice_set_feature_support(pf, ICE_F_ROCE_LAG);
1220 ice_clear_feature_support(pf, ICE_F_ROCE_LAG);
1222 if (caps->sriov_lag)
1223 ice_set_feature_support(pf, ICE_F_SRIOV_LAG);
1225 ice_clear_feature_support(pf, ICE_F_SRIOV_LAG);
1229 * ice_lag_changeupper_event - handle LAG changeupper event
1230 * @lag: LAG info struct
1231 * @ptr: opaque pointer data
1233 static void ice_lag_changeupper_event(struct ice_lag *lag, void *ptr)
1235 struct netdev_notifier_changeupper_info *info;
1236 struct ice_lag *primary_lag;
1237 struct net_device *netdev;
1240 netdev = netdev_notifier_info_to_dev(ptr);
1242 /* not for this netdev */
1243 if (netdev != lag->netdev)
1246 primary_lag = ice_lag_find_primary(lag);
1247 if (info->linking) {
1248 lag->upper_netdev = info->upper_dev;
1249 /* If there is not already a primary interface in the LAG,
1250 * then mark this one as primary.
1253 lag->primary = true;
1254 /* Configure primary's SWID to be shared */
1255 ice_lag_primary_swid(lag, true);
1260 swid = primary_lag->pf->hw.port_info->sw_id;
1261 ice_lag_set_swid(swid, lag, true);
1262 ice_lag_add_prune_list(primary_lag, lag->pf);
1263 ice_lag_cfg_drop_fltr(lag, true);
1265 /* add filter for primary control packets */
1266 ice_lag_cfg_cp_fltr(lag, true);
1268 if (!primary_lag && lag->primary)
1271 if (!lag->primary) {
1272 ice_lag_set_swid(0, lag, false);
1274 if (primary_lag && lag->primary) {
1275 ice_lag_primary_swid(lag, false);
1276 ice_lag_del_prune_list(primary_lag, lag->pf);
1279 /* remove filter for control packets */
1280 ice_lag_cfg_cp_fltr(lag, false);
1285 * ice_lag_monitor_link - monitor interfaces entering/leaving the aggregate
1286 * @lag: lag info struct
1287 * @ptr: opaque data containing notifier event
1289 * This function only operates after a primary has been set.
1291 static void ice_lag_monitor_link(struct ice_lag *lag, void *ptr)
1293 struct netdev_notifier_changeupper_info *info;
1294 struct ice_hw *prim_hw, *active_hw;
1295 struct net_device *event_netdev;
1302 event_netdev = netdev_notifier_info_to_dev(ptr);
1303 if (!netif_is_same_ice(lag->pf, event_netdev))
1308 prim_port = prim_hw->port_info->lport;
1310 info = (struct netdev_notifier_changeupper_info *)ptr;
1311 if (info->upper_dev != lag->upper_netdev)
1314 if (!info->linking) {
1315 /* Since there are only two interfaces allowed in SRIOV+LAG, if
1316 * one port is leaving, then nodes need to be on primary
1319 if (prim_port != lag->active_port &&
1320 lag->active_port != ICE_LAG_INVALID_PORT) {
1321 active_hw = ice_lag_find_hw_by_lport(lag,
1323 ice_lag_reclaim_vf_nodes(lag, active_hw);
1324 lag->active_port = ICE_LAG_INVALID_PORT;
1330 * ice_lag_monitor_active - main PF keep track of which port is active
1331 * @lag: lag info struct
1332 * @ptr: opaque data containing notifier event
1334 * This function is for the primary PF to monitor changes in which port is
1335 * active and handle changes for SRIOV VF functionality
1337 static void ice_lag_monitor_active(struct ice_lag *lag, void *ptr)
1339 struct net_device *event_netdev, *event_upper;
1340 struct netdev_notifier_bonding_info *info;
1341 struct netdev_bonding_info *bonding_info;
1342 struct ice_netdev_priv *event_np;
1343 struct ice_pf *pf, *event_pf;
1344 u8 prim_port, event_port;
1353 event_netdev = netdev_notifier_info_to_dev(ptr);
1355 event_upper = netdev_master_upper_dev_get_rcu(event_netdev);
1357 if (!netif_is_ice(event_netdev) || event_upper != lag->upper_netdev)
1360 event_np = netdev_priv(event_netdev);
1361 event_pf = event_np->vsi->back;
1362 event_port = event_pf->hw.port_info->lport;
1363 prim_port = pf->hw.port_info->lport;
1365 info = (struct netdev_notifier_bonding_info *)ptr;
1366 bonding_info = &info->bonding_info;
1368 if (!bonding_info->slave.state) {
1369 /* if no port is currently active, then nodes and filters exist
1370 * on primary port, check if we need to move them
1372 if (lag->active_port == ICE_LAG_INVALID_PORT) {
1373 if (event_port != prim_port)
1374 ice_lag_move_vf_nodes(lag, prim_port,
1376 lag->active_port = event_port;
1380 /* active port is already set and is current event port */
1381 if (lag->active_port == event_port)
1383 /* new active port */
1384 ice_lag_move_vf_nodes(lag, lag->active_port, event_port);
1385 lag->active_port = event_port;
1387 /* port not set as currently active (e.g. new active port
1388 * has already claimed the nodes and filters
1390 if (lag->active_port != event_port)
1392 /* This is the case when neither port is active (both link down)
1393 * Link down on the bond - set active port to invalid and move
1394 * nodes and filters back to primary if not already there
1396 if (event_port != prim_port)
1397 ice_lag_move_vf_nodes(lag, event_port, prim_port);
1398 lag->active_port = ICE_LAG_INVALID_PORT;
1403 * ice_lag_chk_comp - evaluate bonded interface for feature support
1404 * @lag: lag info struct
1405 * @ptr: opaque data for netdev event info
1408 ice_lag_chk_comp(struct ice_lag *lag, void *ptr)
1410 struct net_device *event_netdev, *event_upper;
1411 struct netdev_notifier_bonding_info *info;
1412 struct netdev_bonding_info *bonding_info;
1413 struct list_head *tmp;
1420 event_netdev = netdev_notifier_info_to_dev(ptr);
1422 event_upper = netdev_master_upper_dev_get_rcu(event_netdev);
1424 if (event_upper != lag->upper_netdev)
1427 dev = ice_pf_to_dev(lag->pf);
1429 /* only supporting switchdev mode for SRIOV VF LAG.
1430 * primary interface has to be in switchdev mode
1432 if (!ice_is_switchdev_running(lag->pf)) {
1433 dev_info(dev, "Primary interface not in switchdev mode - VF LAG disabled\n");
1437 info = (struct netdev_notifier_bonding_info *)ptr;
1438 bonding_info = &info->bonding_info;
1439 lag->bond_mode = bonding_info->master.bond_mode;
1440 if (lag->bond_mode != BOND_MODE_ACTIVEBACKUP) {
1441 dev_info(dev, "Bond Mode not ACTIVE-BACKUP - VF LAG disabled\n");
1445 list_for_each(tmp, lag->netdev_head) {
1446 struct ice_dcbx_cfg *dcb_cfg, *peer_dcb_cfg;
1447 struct ice_lag_netdev_list *entry;
1448 struct ice_netdev_priv *peer_np;
1449 struct net_device *peer_netdev;
1450 struct ice_vsi *vsi, *peer_vsi;
1451 struct ice_pf *peer_pf;
1453 entry = list_entry(tmp, struct ice_lag_netdev_list, node);
1454 peer_netdev = entry->netdev;
1455 if (!netif_is_ice(peer_netdev)) {
1456 dev_info(dev, "Found %s non-ice netdev in LAG - VF LAG disabled\n",
1457 netdev_name(peer_netdev));
1463 dev_info(dev, "Found more than two netdevs in LAG - VF LAG disabled\n");
1467 peer_np = netdev_priv(peer_netdev);
1468 vsi = ice_get_main_vsi(lag->pf);
1469 peer_vsi = peer_np->vsi;
1470 if (lag->pf->pdev->bus != peer_vsi->back->pdev->bus ||
1471 lag->pf->pdev->slot != peer_vsi->back->pdev->slot) {
1472 dev_info(dev, "Found %s on different device in LAG - VF LAG disabled\n",
1473 netdev_name(peer_netdev));
1477 dcb_cfg = &vsi->port_info->qos_cfg.local_dcbx_cfg;
1478 peer_dcb_cfg = &peer_vsi->port_info->qos_cfg.local_dcbx_cfg;
1479 if (memcmp(dcb_cfg, peer_dcb_cfg,
1480 sizeof(struct ice_dcbx_cfg))) {
1481 dev_info(dev, "Found %s with different DCB in LAG - VF LAG disabled\n",
1482 netdev_name(peer_netdev));
1486 peer_pf = peer_vsi->back;
1487 if (test_bit(ICE_FLAG_FW_LLDP_AGENT, peer_pf->flags)) {
1488 dev_warn(dev, "Found %s with FW LLDP agent active - VF LAG disabled\n",
1489 netdev_name(peer_netdev));
1498 * ice_lag_unregister - handle netdev unregister events
1499 * @lag: LAG info struct
1500 * @event_netdev: netdev struct for target of notifier event
1503 ice_lag_unregister(struct ice_lag *lag, struct net_device *event_netdev)
1505 struct ice_netdev_priv *np;
1506 struct ice_pf *event_pf;
1507 struct ice_lag *p_lag;
1509 p_lag = ice_lag_find_primary(lag);
1510 np = netdev_priv(event_netdev);
1511 event_pf = np->vsi->back;
1514 if (p_lag->active_port != p_lag->pf->hw.port_info->lport &&
1515 p_lag->active_port != ICE_LAG_INVALID_PORT) {
1516 struct ice_hw *active_hw;
1518 active_hw = ice_lag_find_hw_by_lport(lag,
1519 p_lag->active_port);
1521 ice_lag_reclaim_vf_nodes(p_lag, active_hw);
1522 lag->active_port = ICE_LAG_INVALID_PORT;
1526 /* primary processing for primary */
1527 if (lag->primary && lag->netdev == event_netdev)
1528 ice_lag_primary_swid(lag, false);
1530 /* primary processing for secondary */
1531 if (lag->primary && lag->netdev != event_netdev)
1532 ice_lag_del_prune_list(lag, event_pf);
1534 /* secondary processing for secondary */
1535 if (!lag->primary && lag->netdev == event_netdev)
1536 ice_lag_set_swid(0, lag, false);
1540 * ice_lag_monitor_rdma - set and clear rdma functionality
1541 * @lag: pointer to lag struct
1542 * @ptr: opaque data for netdev event info
1545 ice_lag_monitor_rdma(struct ice_lag *lag, void *ptr)
1547 struct netdev_notifier_changeupper_info *info;
1548 struct net_device *netdev;
1551 netdev = netdev_notifier_info_to_dev(ptr);
1553 if (netdev != lag->netdev)
1557 ice_clear_rdma_cap(lag->pf);
1559 ice_set_rdma_cap(lag->pf);
1563 * ice_lag_chk_disabled_bond - monitor interfaces entering/leaving disabled bond
1564 * @lag: lag info struct
1565 * @ptr: opaque data containing event
1567 * as interfaces enter a bond - determine if the bond is currently
1568 * SRIOV LAG compliant and flag if not. As interfaces leave the
1569 * bond, reset their compliant status.
1571 static void ice_lag_chk_disabled_bond(struct ice_lag *lag, void *ptr)
1573 struct net_device *netdev = netdev_notifier_info_to_dev(ptr);
1574 struct netdev_notifier_changeupper_info *info = ptr;
1575 struct ice_lag *prim_lag;
1577 if (netdev != lag->netdev)
1580 if (info->linking) {
1581 prim_lag = ice_lag_find_primary(lag);
1583 !ice_is_feature_supported(prim_lag->pf, ICE_F_SRIOV_LAG)) {
1584 ice_clear_feature_support(lag->pf, ICE_F_SRIOV_LAG);
1585 netdev_info(netdev, "Interface added to non-compliant SRIOV LAG aggregate\n");
1588 ice_lag_init_feature_support_flag(lag->pf);
1593 * ice_lag_disable_sriov_bond - set members of bond as not supporting SRIOV LAG
1594 * @lag: primary interfaces lag struct
1596 static void ice_lag_disable_sriov_bond(struct ice_lag *lag)
1598 struct ice_netdev_priv *np;
1601 np = netdev_priv(lag->netdev);
1603 ice_clear_feature_support(pf, ICE_F_SRIOV_LAG);
1607 * ice_lag_process_event - process a task assigned to the lag_wq
1608 * @work: pointer to work_struct
1610 static void ice_lag_process_event(struct work_struct *work)
1612 struct netdev_notifier_changeupper_info *info;
1613 struct ice_lag_work *lag_work;
1614 struct net_device *netdev;
1615 struct list_head *tmp, *n;
1618 lag_work = container_of(work, struct ice_lag_work, lag_task);
1619 pf = lag_work->lag->pf;
1621 mutex_lock(&pf->lag_mutex);
1622 lag_work->lag->netdev_head = &lag_work->netdev_list.node;
1624 switch (lag_work->event) {
1625 case NETDEV_CHANGEUPPER:
1626 info = &lag_work->info.changeupper_info;
1627 ice_lag_chk_disabled_bond(lag_work->lag, info);
1628 if (ice_is_feature_supported(pf, ICE_F_SRIOV_LAG)) {
1629 ice_lag_monitor_link(lag_work->lag, info);
1630 ice_lag_changeupper_event(lag_work->lag, info);
1631 ice_lag_link_unlink(lag_work->lag, info);
1633 ice_lag_monitor_rdma(lag_work->lag, info);
1635 case NETDEV_BONDING_INFO:
1636 if (ice_is_feature_supported(pf, ICE_F_SRIOV_LAG)) {
1637 if (!ice_lag_chk_comp(lag_work->lag,
1638 &lag_work->info.bonding_info)) {
1639 netdev = lag_work->info.bonding_info.info.dev;
1640 ice_lag_disable_sriov_bond(lag_work->lag);
1641 ice_lag_unregister(lag_work->lag, netdev);
1644 ice_lag_monitor_active(lag_work->lag,
1645 &lag_work->info.bonding_info);
1646 ice_lag_cfg_pf_fltrs(lag_work->lag,
1647 &lag_work->info.bonding_info);
1649 ice_lag_info_event(lag_work->lag, &lag_work->info.bonding_info);
1651 case NETDEV_UNREGISTER:
1652 if (ice_is_feature_supported(pf, ICE_F_SRIOV_LAG)) {
1653 netdev = lag_work->info.bonding_info.info.dev;
1654 if ((netdev == lag_work->lag->netdev ||
1655 lag_work->lag->primary) && lag_work->lag->bonded)
1656 ice_lag_unregister(lag_work->lag, netdev);
1664 /* cleanup resources allocated for this work item */
1665 list_for_each_safe(tmp, n, &lag_work->netdev_list.node) {
1666 struct ice_lag_netdev_list *entry;
1668 entry = list_entry(tmp, struct ice_lag_netdev_list, node);
1669 list_del(&entry->node);
1672 lag_work->lag->netdev_head = NULL;
1674 mutex_unlock(&pf->lag_mutex);
1680 * ice_lag_event_handler - handle LAG events from netdev
1681 * @notif_blk: notifier block registered by this netdev
1682 * @event: event type
1683 * @ptr: opaque data containing notifier event
1686 ice_lag_event_handler(struct notifier_block *notif_blk, unsigned long event,
1689 struct net_device *netdev = netdev_notifier_info_to_dev(ptr);
1690 struct net_device *upper_netdev;
1691 struct ice_lag_work *lag_work;
1692 struct ice_lag *lag;
1694 if (!netif_is_ice(netdev))
1697 if (event != NETDEV_CHANGEUPPER && event != NETDEV_BONDING_INFO &&
1698 event != NETDEV_UNREGISTER)
1701 if (!(netdev->priv_flags & IFF_BONDING))
1704 lag = container_of(notif_blk, struct ice_lag, notif_block);
1708 if (!net_eq(dev_net(netdev), &init_net))
1711 /* This memory will be freed at the end of ice_lag_process_event */
1712 lag_work = kzalloc(sizeof(*lag_work), GFP_KERNEL);
1716 lag_work->event_netdev = netdev;
1717 lag_work->lag = lag;
1718 lag_work->event = event;
1719 if (event == NETDEV_CHANGEUPPER) {
1720 struct netdev_notifier_changeupper_info *info;
1723 upper_netdev = info->upper_dev;
1725 upper_netdev = netdev_master_upper_dev_get(netdev);
1728 INIT_LIST_HEAD(&lag_work->netdev_list.node);
1730 struct ice_lag_netdev_list *nd_list;
1731 struct net_device *tmp_nd;
1734 for_each_netdev_in_bond_rcu(upper_netdev, tmp_nd) {
1735 nd_list = kzalloc(sizeof(*nd_list), GFP_ATOMIC);
1739 nd_list->netdev = tmp_nd;
1740 list_add(&nd_list->node, &lag_work->netdev_list.node);
1746 case NETDEV_CHANGEUPPER:
1747 lag_work->info.changeupper_info =
1748 *((struct netdev_notifier_changeupper_info *)ptr);
1750 case NETDEV_BONDING_INFO:
1751 lag_work->info.bonding_info =
1752 *((struct netdev_notifier_bonding_info *)ptr);
1755 lag_work->info.notifier_info =
1756 *((struct netdev_notifier_info *)ptr);
1760 INIT_WORK(&lag_work->lag_task, ice_lag_process_event);
1761 queue_work(ice_lag_wq, &lag_work->lag_task);
1767 * ice_register_lag_handler - register LAG handler on netdev
1770 static int ice_register_lag_handler(struct ice_lag *lag)
1772 struct device *dev = ice_pf_to_dev(lag->pf);
1773 struct notifier_block *notif_blk;
1775 notif_blk = &lag->notif_block;
1777 if (!notif_blk->notifier_call) {
1778 notif_blk->notifier_call = ice_lag_event_handler;
1779 if (register_netdevice_notifier(notif_blk)) {
1780 notif_blk->notifier_call = NULL;
1781 dev_err(dev, "FAIL register LAG event handler!\n");
1784 dev_dbg(dev, "LAG event handler registered\n");
1790 * ice_unregister_lag_handler - unregister LAG handler on netdev
1793 static void ice_unregister_lag_handler(struct ice_lag *lag)
1795 struct device *dev = ice_pf_to_dev(lag->pf);
1796 struct notifier_block *notif_blk;
1798 notif_blk = &lag->notif_block;
1799 if (notif_blk->notifier_call) {
1800 unregister_netdevice_notifier(notif_blk);
1801 dev_dbg(dev, "LAG event handler unregistered\n");
1806 * ice_create_lag_recipe
1807 * @hw: pointer to HW struct
1808 * @rid: pointer to u16 to pass back recipe index
1809 * @base_recipe: recipe to base the new recipe on
1810 * @prio: priority for new recipe
1812 * function returns 0 on error
1814 static int ice_create_lag_recipe(struct ice_hw *hw, u16 *rid,
1815 const u8 *base_recipe, u8 prio)
1817 struct ice_aqc_recipe_data_elem *new_rcp;
1820 err = ice_alloc_recipe(hw, rid);
1824 new_rcp = kzalloc(ICE_RECIPE_LEN * ICE_MAX_NUM_RECIPES, GFP_KERNEL);
1828 memcpy(new_rcp, base_recipe, ICE_RECIPE_LEN);
1829 new_rcp->content.act_ctrl_fwd_priority = prio;
1830 new_rcp->content.rid = *rid | ICE_AQ_RECIPE_ID_IS_ROOT;
1831 new_rcp->recipe_indx = *rid;
1832 bitmap_zero((unsigned long *)new_rcp->recipe_bitmap,
1833 ICE_MAX_NUM_RECIPES);
1834 set_bit(*rid, (unsigned long *)new_rcp->recipe_bitmap);
1836 err = ice_aq_add_recipe(hw, new_rcp, 1, NULL);
1845 * ice_lag_move_vf_nodes_tc_sync - move a VF's nodes for a tc during reset
1846 * @lag: primary interfaces lag struct
1847 * @dest_hw: HW struct for destination's interface
1848 * @vsi_num: VSI index in PF space
1849 * @tc: traffic class to move
1852 ice_lag_move_vf_nodes_tc_sync(struct ice_lag *lag, struct ice_hw *dest_hw,
1855 DEFINE_FLEX(struct ice_aqc_move_elem, buf, teid, 1);
1856 struct device *dev = ice_pf_to_dev(lag->pf);
1857 u16 numq, valq, num_moved, qbuf_size;
1858 u16 buf_size = __struct_size(buf);
1859 struct ice_aqc_cfg_txqs_buf *qbuf;
1860 struct ice_sched_node *n_prt;
1861 __le32 teid, parent_teid;
1862 struct ice_vsi_ctx *ctx;
1867 ctx = ice_get_vsi_ctx(hw, vsi_num);
1869 dev_warn(dev, "LAG rebuild failed after reset due to VSI Context failure\n");
1873 if (!ctx->sched.vsi_node[tc])
1876 numq = ctx->num_lan_q_entries[tc];
1877 teid = ctx->sched.vsi_node[tc]->info.node_teid;
1878 tmp_teid = le32_to_cpu(teid);
1879 parent_teid = ctx->sched.vsi_node[tc]->info.parent_teid;
1881 if (!tmp_teid || !numq)
1884 if (ice_sched_suspend_resume_elems(hw, 1, &tmp_teid, true))
1885 dev_dbg(dev, "Problem suspending traffic during reset rebuild\n");
1887 /* reconfig queues for new port */
1888 qbuf_size = struct_size(qbuf, queue_info, numq);
1889 qbuf = kzalloc(qbuf_size, GFP_KERNEL);
1891 dev_warn(dev, "Failure allocating VF queue recfg buffer for reset rebuild\n");
1895 /* add the per queue info for the reconfigure command buffer */
1896 valq = ice_lag_qbuf_recfg(hw, qbuf, vsi_num, numq, tc);
1898 dev_warn(dev, "Failure to reconfig queues for LAG reset rebuild\n");
1902 if (ice_aq_cfg_lan_txq(hw, qbuf, qbuf_size, numq, hw->port_info->lport,
1903 dest_hw->port_info->lport, NULL)) {
1904 dev_warn(dev, "Failure to configure queues for LAG reset rebuild\n");
1911 /* find parent in destination tree */
1912 n_prt = ice_lag_get_sched_parent(dest_hw, tc);
1916 /* Move node to new parent */
1917 buf->hdr.src_parent_teid = parent_teid;
1918 buf->hdr.dest_parent_teid = n_prt->info.node_teid;
1919 buf->hdr.num_elems = cpu_to_le16(1);
1920 buf->hdr.mode = ICE_AQC_MOVE_ELEM_MODE_KEEP_OWN;
1921 buf->teid[0] = teid;
1923 if (ice_aq_move_sched_elems(&lag->pf->hw, buf, buf_size, &num_moved))
1924 dev_warn(dev, "Failure to move VF nodes for LAG reset rebuild\n");
1926 ice_sched_update_parent(n_prt, ctx->sched.vsi_node[tc]);
1934 if (ice_sched_suspend_resume_elems(hw, 1, &tmp_teid, false))
1935 dev_warn(dev, "Problem restarting traffic for LAG node reset rebuild\n");
1939 * ice_lag_move_vf_nodes_sync - move vf nodes to active interface
1940 * @lag: primary interfaces lag struct
1941 * @dest_hw: lport value for currently active port
1943 * This function is used in a reset context, outside of event handling,
1944 * to move the VF nodes to the secondary interface when that interface
1945 * is the active interface during a reset rebuild
1948 ice_lag_move_vf_nodes_sync(struct ice_lag *lag, struct ice_hw *dest_hw)
1953 if (!lag->primary || !dest_hw)
1957 ice_for_each_vsi(pf, i)
1958 if (pf->vsi[i] && (pf->vsi[i]->type == ICE_VSI_VF ||
1959 pf->vsi[i]->type == ICE_VSI_SWITCHDEV_CTRL))
1960 ice_for_each_traffic_class(tc)
1961 ice_lag_move_vf_nodes_tc_sync(lag, dest_hw, i,
1966 * ice_init_lag - initialize support for LAG
1969 * Alloc memory for LAG structs and initialize the elements.
1970 * Memory will be freed in ice_deinit_lag
1972 int ice_init_lag(struct ice_pf *pf)
1974 struct device *dev = ice_pf_to_dev(pf);
1975 struct ice_lag *lag;
1976 struct ice_vsi *vsi;
1977 u64 recipe_bits = 0;
1980 ice_lag_init_feature_support_flag(pf);
1981 if (!ice_is_feature_supported(pf, ICE_F_SRIOV_LAG))
1984 pf->lag = kzalloc(sizeof(*lag), GFP_KERNEL);
1989 vsi = ice_get_main_vsi(pf);
1991 dev_err(dev, "couldn't get main vsi, link aggregation init fail\n");
1997 lag->netdev = vsi->netdev;
1998 lag->role = ICE_LAG_NONE;
1999 lag->active_port = ICE_LAG_INVALID_PORT;
2000 lag->bonded = false;
2001 lag->upper_netdev = NULL;
2002 lag->notif_block.notifier_call = NULL;
2004 err = ice_register_lag_handler(lag);
2006 dev_warn(dev, "INIT LAG: Failed to register event handler\n");
2010 err = ice_create_lag_recipe(&pf->hw, &lag->pf_recipe,
2011 ice_dflt_vsi_rcp, 1);
2015 err = ice_create_lag_recipe(&pf->hw, &lag->lport_recipe,
2020 /* associate recipes to profiles */
2021 for (n = 0; n < ICE_PROFID_IPV6_GTPU_IPV6_TCP_INNER; n++) {
2022 err = ice_aq_get_recipe_to_profile(&pf->hw, n,
2023 (u8 *)&recipe_bits, NULL);
2027 if (recipe_bits & BIT(ICE_SW_LKUP_DFLT)) {
2028 recipe_bits |= BIT(lag->pf_recipe) |
2029 BIT(lag->lport_recipe);
2030 ice_aq_map_recipe_to_profile(&pf->hw, n,
2031 (u8 *)&recipe_bits, NULL);
2035 ice_display_lag_info(lag);
2037 dev_dbg(dev, "INIT LAG complete\n");
2041 ice_free_hw_res(&pf->hw, ICE_AQC_RES_TYPE_RECIPE, 1,
2042 &pf->lag->pf_recipe);
2050 * ice_deinit_lag - Clean up LAG
2053 * Clean up kernel LAG info and free memory
2054 * This function is meant to only be called on driver remove/shutdown
2056 void ice_deinit_lag(struct ice_pf *pf)
2058 struct ice_lag *lag;
2066 ice_unregister_lag_handler(lag);
2068 flush_workqueue(ice_lag_wq);
2070 ice_free_hw_res(&pf->hw, ICE_AQC_RES_TYPE_RECIPE, 1,
2071 &pf->lag->pf_recipe);
2072 ice_free_hw_res(&pf->hw, ICE_AQC_RES_TYPE_RECIPE, 1,
2073 &pf->lag->lport_recipe);
2081 * ice_lag_rebuild - rebuild lag resources after reset
2082 * @pf: pointer to local pf struct
2084 * PF resets are promoted to CORER resets when interface in an aggregate. This
2085 * means that we need to rebuild the PF resources for the interface. Since
2086 * this will happen outside the normal event processing, need to acquire the lag
2089 * This function will also evaluate the VF resources if this is the primary
2092 void ice_lag_rebuild(struct ice_pf *pf)
2094 struct ice_lag_netdev_list ndlist;
2095 struct ice_lag *lag, *prim_lag;
2096 u8 act_port, loc_port;
2098 if (!pf->lag || !pf->lag->bonded)
2101 mutex_lock(&pf->lag_mutex);
2107 ice_lag_build_netdev_list(lag, &ndlist);
2108 prim_lag = ice_lag_find_primary(lag);
2112 dev_dbg(ice_pf_to_dev(pf), "No primary interface in aggregate, can't rebuild\n");
2113 goto lag_rebuild_out;
2116 act_port = prim_lag->active_port;
2117 loc_port = lag->pf->hw.port_info->lport;
2119 /* configure SWID for this port */
2121 ice_lag_primary_swid(lag, true);
2123 ice_lag_set_swid(prim_lag->pf->hw.port_info->sw_id, lag, true);
2124 ice_lag_add_prune_list(prim_lag, pf);
2125 if (act_port == loc_port)
2126 ice_lag_move_vf_nodes_sync(prim_lag, &pf->hw);
2129 ice_lag_cfg_cp_fltr(lag, true);
2131 if (lag->pf_rule_id)
2132 if (ice_lag_cfg_dflt_fltr(lag, true))
2133 dev_err(ice_pf_to_dev(pf), "Error adding default VSI rule in rebuild\n");
2135 ice_clear_rdma_cap(pf);
2137 ice_lag_destroy_netdev_list(lag, &ndlist);
2138 mutex_unlock(&pf->lag_mutex);
2142 * ice_lag_is_switchdev_running
2143 * @pf: pointer to PF structure
2145 * Check if switchdev is running on any of the interfaces connected to lag.
2147 bool ice_lag_is_switchdev_running(struct ice_pf *pf)
2149 struct ice_lag *lag = pf->lag;
2150 struct net_device *tmp_nd;
2152 if (!ice_is_feature_supported(pf, ICE_F_SRIOV_LAG) || !lag)
2156 for_each_netdev_in_bond_rcu(lag->upper_netdev, tmp_nd) {
2157 struct ice_netdev_priv *priv = netdev_priv(tmp_nd);
2159 if (!netif_is_ice(tmp_nd) || !priv || !priv->vsi ||
2163 if (ice_is_switchdev_running(priv->vsi->back)) {