2 * Copyright (c) 2016, Mellanox Technologies. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 #include <linux/netdevice.h>
34 #include <linux/mlx5/driver.h>
35 #include <linux/mlx5/vport.h>
36 #include "mlx5_core.h"
41 /* General purpose, use for short periods of time.
42 * Beware of lock dependencies (preferably, no locks should be acquired
45 static DEFINE_SPINLOCK(lag_lock);
47 static int mlx5_cmd_create_lag(struct mlx5_core_dev *dev, u8 remap_port1,
50 u32 in[MLX5_ST_SZ_DW(create_lag_in)] = {};
51 void *lag_ctx = MLX5_ADDR_OF(create_lag_in, in, ctx);
53 MLX5_SET(create_lag_in, in, opcode, MLX5_CMD_OP_CREATE_LAG);
55 MLX5_SET(lagc, lag_ctx, tx_remap_affinity_1, remap_port1);
56 MLX5_SET(lagc, lag_ctx, tx_remap_affinity_2, remap_port2);
58 return mlx5_cmd_exec_in(dev, create_lag, in);
61 static int mlx5_cmd_modify_lag(struct mlx5_core_dev *dev, u8 remap_port1,
64 u32 in[MLX5_ST_SZ_DW(modify_lag_in)] = {};
65 void *lag_ctx = MLX5_ADDR_OF(modify_lag_in, in, ctx);
67 MLX5_SET(modify_lag_in, in, opcode, MLX5_CMD_OP_MODIFY_LAG);
68 MLX5_SET(modify_lag_in, in, field_select, 0x1);
70 MLX5_SET(lagc, lag_ctx, tx_remap_affinity_1, remap_port1);
71 MLX5_SET(lagc, lag_ctx, tx_remap_affinity_2, remap_port2);
73 return mlx5_cmd_exec_in(dev, modify_lag, in);
76 int mlx5_cmd_create_vport_lag(struct mlx5_core_dev *dev)
78 u32 in[MLX5_ST_SZ_DW(create_vport_lag_in)] = {};
80 MLX5_SET(create_vport_lag_in, in, opcode, MLX5_CMD_OP_CREATE_VPORT_LAG);
82 return mlx5_cmd_exec_in(dev, create_vport_lag, in);
84 EXPORT_SYMBOL(mlx5_cmd_create_vport_lag);
86 int mlx5_cmd_destroy_vport_lag(struct mlx5_core_dev *dev)
88 u32 in[MLX5_ST_SZ_DW(destroy_vport_lag_in)] = {};
90 MLX5_SET(destroy_vport_lag_in, in, opcode, MLX5_CMD_OP_DESTROY_VPORT_LAG);
92 return mlx5_cmd_exec_in(dev, destroy_vport_lag, in);
94 EXPORT_SYMBOL(mlx5_cmd_destroy_vport_lag);
96 static int mlx5_lag_netdev_event(struct notifier_block *this,
97 unsigned long event, void *ptr);
98 static void mlx5_do_bond_work(struct work_struct *work);
100 static void mlx5_ldev_free(struct kref *ref)
102 struct mlx5_lag *ldev = container_of(ref, struct mlx5_lag, ref);
104 if (ldev->nb.notifier_call)
105 unregister_netdevice_notifier_net(&init_net, &ldev->nb);
106 mlx5_lag_mp_cleanup(ldev);
107 cancel_delayed_work_sync(&ldev->bond_work);
108 destroy_workqueue(ldev->wq);
112 static void mlx5_ldev_put(struct mlx5_lag *ldev)
114 kref_put(&ldev->ref, mlx5_ldev_free);
117 static void mlx5_ldev_get(struct mlx5_lag *ldev)
119 kref_get(&ldev->ref);
122 static struct mlx5_lag *mlx5_lag_dev_alloc(struct mlx5_core_dev *dev)
124 struct mlx5_lag *ldev;
127 ldev = kzalloc(sizeof(*ldev), GFP_KERNEL);
131 ldev->wq = create_singlethread_workqueue("mlx5_lag");
137 kref_init(&ldev->ref);
138 INIT_DELAYED_WORK(&ldev->bond_work, mlx5_do_bond_work);
140 ldev->nb.notifier_call = mlx5_lag_netdev_event;
141 if (register_netdevice_notifier_net(&init_net, &ldev->nb)) {
142 ldev->nb.notifier_call = NULL;
143 mlx5_core_err(dev, "Failed to register LAG netdev notifier\n");
146 err = mlx5_lag_mp_init(ldev);
148 mlx5_core_err(dev, "Failed to init multipath lag err=%d\n",
154 int mlx5_lag_dev_get_netdev_idx(struct mlx5_lag *ldev,
155 struct net_device *ndev)
159 for (i = 0; i < MLX5_MAX_PORTS; i++)
160 if (ldev->pf[i].netdev == ndev)
166 static bool __mlx5_lag_is_roce(struct mlx5_lag *ldev)
168 return !!(ldev->flags & MLX5_LAG_FLAG_ROCE);
171 static bool __mlx5_lag_is_sriov(struct mlx5_lag *ldev)
173 return !!(ldev->flags & MLX5_LAG_FLAG_SRIOV);
176 static void mlx5_infer_tx_affinity_mapping(struct lag_tracker *tracker,
177 u8 *port1, u8 *port2)
182 p1en = tracker->netdev_state[MLX5_LAG_P1].tx_enabled &&
183 tracker->netdev_state[MLX5_LAG_P1].link_up;
185 p2en = tracker->netdev_state[MLX5_LAG_P2].tx_enabled &&
186 tracker->netdev_state[MLX5_LAG_P2].link_up;
190 if ((!p1en && !p2en) || (p1en && p2en))
199 void mlx5_modify_lag(struct mlx5_lag *ldev,
200 struct lag_tracker *tracker)
202 struct mlx5_core_dev *dev0 = ldev->pf[MLX5_LAG_P1].dev;
203 u8 v2p_port1, v2p_port2;
206 mlx5_infer_tx_affinity_mapping(tracker, &v2p_port1,
209 if (v2p_port1 != ldev->v2p_map[MLX5_LAG_P1] ||
210 v2p_port2 != ldev->v2p_map[MLX5_LAG_P2]) {
211 ldev->v2p_map[MLX5_LAG_P1] = v2p_port1;
212 ldev->v2p_map[MLX5_LAG_P2] = v2p_port2;
214 mlx5_core_info(dev0, "modify lag map port 1:%d port 2:%d",
215 ldev->v2p_map[MLX5_LAG_P1],
216 ldev->v2p_map[MLX5_LAG_P2]);
218 err = mlx5_cmd_modify_lag(dev0, v2p_port1, v2p_port2);
221 "Failed to modify LAG (%d)\n",
226 static int mlx5_create_lag(struct mlx5_lag *ldev,
227 struct lag_tracker *tracker)
229 struct mlx5_core_dev *dev0 = ldev->pf[MLX5_LAG_P1].dev;
232 mlx5_infer_tx_affinity_mapping(tracker, &ldev->v2p_map[MLX5_LAG_P1],
233 &ldev->v2p_map[MLX5_LAG_P2]);
235 mlx5_core_info(dev0, "lag map port 1:%d port 2:%d",
236 ldev->v2p_map[MLX5_LAG_P1], ldev->v2p_map[MLX5_LAG_P2]);
238 err = mlx5_cmd_create_lag(dev0, ldev->v2p_map[MLX5_LAG_P1],
239 ldev->v2p_map[MLX5_LAG_P2]);
242 "Failed to create LAG (%d)\n",
247 int mlx5_activate_lag(struct mlx5_lag *ldev,
248 struct lag_tracker *tracker,
251 bool roce_lag = !!(flags & MLX5_LAG_FLAG_ROCE);
252 struct mlx5_core_dev *dev0 = ldev->pf[MLX5_LAG_P1].dev;
255 err = mlx5_create_lag(ldev, tracker);
259 "Failed to activate RoCE LAG\n");
262 "Failed to activate VF LAG\n"
263 "Make sure all VFs are unbound prior to VF LAG activation or deactivation\n");
268 ldev->flags |= flags;
272 static int mlx5_deactivate_lag(struct mlx5_lag *ldev)
274 struct mlx5_core_dev *dev0 = ldev->pf[MLX5_LAG_P1].dev;
275 u32 in[MLX5_ST_SZ_DW(destroy_lag_in)] = {};
276 bool roce_lag = __mlx5_lag_is_roce(ldev);
279 ldev->flags &= ~MLX5_LAG_MODE_FLAGS;
281 MLX5_SET(destroy_lag_in, in, opcode, MLX5_CMD_OP_DESTROY_LAG);
282 err = mlx5_cmd_exec_in(dev0, destroy_lag, in);
286 "Failed to deactivate RoCE LAG; driver restart required\n");
289 "Failed to deactivate VF LAG; driver restart required\n"
290 "Make sure all VFs are unbound prior to VF LAG activation or deactivation\n");
297 static bool mlx5_lag_check_prereq(struct mlx5_lag *ldev)
299 if (!ldev->pf[MLX5_LAG_P1].dev || !ldev->pf[MLX5_LAG_P2].dev)
302 #ifdef CONFIG_MLX5_ESWITCH
303 return mlx5_esw_lag_prereq(ldev->pf[MLX5_LAG_P1].dev,
304 ldev->pf[MLX5_LAG_P2].dev);
306 return (!mlx5_sriov_is_enabled(ldev->pf[MLX5_LAG_P1].dev) &&
307 !mlx5_sriov_is_enabled(ldev->pf[MLX5_LAG_P2].dev));
311 static void mlx5_lag_add_devices(struct mlx5_lag *ldev)
315 for (i = 0; i < MLX5_MAX_PORTS; i++) {
316 if (!ldev->pf[i].dev)
319 if (ldev->pf[i].dev->priv.flags &
320 MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV)
323 ldev->pf[i].dev->priv.flags &= ~MLX5_PRIV_FLAGS_DISABLE_IB_ADEV;
324 mlx5_rescan_drivers_locked(ldev->pf[i].dev);
328 static void mlx5_lag_remove_devices(struct mlx5_lag *ldev)
332 for (i = 0; i < MLX5_MAX_PORTS; i++) {
333 if (!ldev->pf[i].dev)
336 ldev->pf[i].dev->priv.flags |= MLX5_PRIV_FLAGS_DISABLE_IB_ADEV;
337 mlx5_rescan_drivers_locked(ldev->pf[i].dev);
341 static void mlx5_disable_lag(struct mlx5_lag *ldev)
343 struct mlx5_core_dev *dev0 = ldev->pf[MLX5_LAG_P1].dev;
344 struct mlx5_core_dev *dev1 = ldev->pf[MLX5_LAG_P2].dev;
348 roce_lag = __mlx5_lag_is_roce(ldev);
351 if (!(dev0->priv.flags & MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV)) {
352 dev0->priv.flags |= MLX5_PRIV_FLAGS_DISABLE_IB_ADEV;
353 mlx5_rescan_drivers_locked(dev0);
355 mlx5_nic_vport_disable_roce(dev1);
358 err = mlx5_deactivate_lag(ldev);
363 mlx5_lag_add_devices(ldev);
366 static void mlx5_do_bond(struct mlx5_lag *ldev)
368 struct mlx5_core_dev *dev0 = ldev->pf[MLX5_LAG_P1].dev;
369 struct mlx5_core_dev *dev1 = ldev->pf[MLX5_LAG_P2].dev;
370 struct lag_tracker tracker;
371 bool do_bond, roce_lag;
374 if (!mlx5_lag_is_ready(ldev))
377 tracker = ldev->tracker;
379 do_bond = tracker.is_bonded && mlx5_lag_check_prereq(ldev);
381 if (do_bond && !__mlx5_lag_is_active(ldev)) {
382 roce_lag = !mlx5_sriov_is_enabled(dev0) &&
383 !mlx5_sriov_is_enabled(dev1);
385 #ifdef CONFIG_MLX5_ESWITCH
386 roce_lag = roce_lag &&
387 dev0->priv.eswitch->mode == MLX5_ESWITCH_NONE &&
388 dev1->priv.eswitch->mode == MLX5_ESWITCH_NONE;
392 mlx5_lag_remove_devices(ldev);
394 err = mlx5_activate_lag(ldev, &tracker,
395 roce_lag ? MLX5_LAG_FLAG_ROCE :
396 MLX5_LAG_FLAG_SRIOV);
399 mlx5_lag_add_devices(ldev);
405 dev0->priv.flags &= ~MLX5_PRIV_FLAGS_DISABLE_IB_ADEV;
406 mlx5_rescan_drivers_locked(dev0);
407 mlx5_nic_vport_enable_roce(dev1);
409 } else if (do_bond && __mlx5_lag_is_active(ldev)) {
410 mlx5_modify_lag(ldev, &tracker);
411 } else if (!do_bond && __mlx5_lag_is_active(ldev)) {
412 mlx5_disable_lag(ldev);
416 static void mlx5_queue_bond_work(struct mlx5_lag *ldev, unsigned long delay)
418 queue_delayed_work(ldev->wq, &ldev->bond_work, delay);
421 static void mlx5_do_bond_work(struct work_struct *work)
423 struct delayed_work *delayed_work = to_delayed_work(work);
424 struct mlx5_lag *ldev = container_of(delayed_work, struct mlx5_lag,
428 status = mlx5_dev_list_trylock();
431 mlx5_queue_bond_work(ldev, HZ);
436 mlx5_dev_list_unlock();
439 static int mlx5_handle_changeupper_event(struct mlx5_lag *ldev,
440 struct lag_tracker *tracker,
441 struct net_device *ndev,
442 struct netdev_notifier_changeupper_info *info)
444 struct net_device *upper = info->upper_dev, *ndev_tmp;
445 struct netdev_lag_upper_info *lag_upper_info = NULL;
446 bool is_bonded, is_in_lag, mode_supported;
451 if (!netif_is_lag_master(upper))
455 lag_upper_info = info->upper_info;
457 /* The event may still be of interest if the slave does not belong to
458 * us, but is enslaved to a master which has one or more of our netdevs
459 * as slaves (e.g., if a new slave is added to a master that bonds two
460 * of our netdevs, we should unbond).
463 for_each_netdev_in_bond_rcu(upper, ndev_tmp) {
464 idx = mlx5_lag_dev_get_netdev_idx(ldev, ndev_tmp);
466 bond_status |= (1 << idx);
472 /* None of this lagdev's netdevs are slaves of this master. */
473 if (!(bond_status & 0x3))
477 tracker->tx_type = lag_upper_info->tx_type;
479 /* Determine bonding status:
480 * A device is considered bonded if both its physical ports are slaves
481 * of the same lag master, and only them.
483 is_in_lag = num_slaves == MLX5_MAX_PORTS && bond_status == 0x3;
485 if (!mlx5_lag_is_ready(ldev) && is_in_lag) {
486 NL_SET_ERR_MSG_MOD(info->info.extack,
487 "Can't activate LAG offload, PF is configured with more than 64 VFs");
491 /* Lag mode must be activebackup or hash. */
492 mode_supported = tracker->tx_type == NETDEV_LAG_TX_TYPE_ACTIVEBACKUP ||
493 tracker->tx_type == NETDEV_LAG_TX_TYPE_HASH;
495 if (is_in_lag && !mode_supported)
496 NL_SET_ERR_MSG_MOD(info->info.extack,
497 "Can't activate LAG offload, TX type isn't supported");
499 is_bonded = is_in_lag && mode_supported;
500 if (tracker->is_bonded != is_bonded) {
501 tracker->is_bonded = is_bonded;
508 static int mlx5_handle_changelowerstate_event(struct mlx5_lag *ldev,
509 struct lag_tracker *tracker,
510 struct net_device *ndev,
511 struct netdev_notifier_changelowerstate_info *info)
513 struct netdev_lag_lower_state_info *lag_lower_info;
516 if (!netif_is_lag_port(ndev))
519 idx = mlx5_lag_dev_get_netdev_idx(ldev, ndev);
523 /* This information is used to determine virtual to physical
526 lag_lower_info = info->lower_state_info;
530 tracker->netdev_state[idx] = *lag_lower_info;
535 static int mlx5_lag_netdev_event(struct notifier_block *this,
536 unsigned long event, void *ptr)
538 struct net_device *ndev = netdev_notifier_info_to_dev(ptr);
539 struct lag_tracker tracker;
540 struct mlx5_lag *ldev;
543 if ((event != NETDEV_CHANGEUPPER) && (event != NETDEV_CHANGELOWERSTATE))
546 ldev = container_of(this, struct mlx5_lag, nb);
548 if (!mlx5_lag_is_ready(ldev) && event == NETDEV_CHANGELOWERSTATE)
551 tracker = ldev->tracker;
554 case NETDEV_CHANGEUPPER:
555 changed = mlx5_handle_changeupper_event(ldev, &tracker, ndev,
558 case NETDEV_CHANGELOWERSTATE:
559 changed = mlx5_handle_changelowerstate_event(ldev, &tracker,
564 ldev->tracker = tracker;
567 mlx5_queue_bond_work(ldev, 0);
572 static void mlx5_ldev_add_netdev(struct mlx5_lag *ldev,
573 struct mlx5_core_dev *dev,
574 struct net_device *netdev)
576 unsigned int fn = PCI_FUNC(dev->pdev->devfn);
578 if (fn >= MLX5_MAX_PORTS)
581 spin_lock(&lag_lock);
582 ldev->pf[fn].netdev = netdev;
583 ldev->tracker.netdev_state[fn].link_up = 0;
584 ldev->tracker.netdev_state[fn].tx_enabled = 0;
585 spin_unlock(&lag_lock);
588 static void mlx5_ldev_remove_netdev(struct mlx5_lag *ldev,
589 struct net_device *netdev)
593 spin_lock(&lag_lock);
594 for (i = 0; i < MLX5_MAX_PORTS; i++) {
595 if (ldev->pf[i].netdev == netdev) {
596 ldev->pf[i].netdev = NULL;
600 spin_unlock(&lag_lock);
603 static void mlx5_ldev_add_mdev(struct mlx5_lag *ldev,
604 struct mlx5_core_dev *dev)
606 unsigned int fn = PCI_FUNC(dev->pdev->devfn);
608 if (fn >= MLX5_MAX_PORTS)
611 ldev->pf[fn].dev = dev;
612 dev->priv.lag = ldev;
615 /* Must be called with intf_mutex held */
616 static void mlx5_ldev_remove_mdev(struct mlx5_lag *ldev,
617 struct mlx5_core_dev *dev)
621 for (i = 0; i < MLX5_MAX_PORTS; i++)
622 if (ldev->pf[i].dev == dev)
625 if (i == MLX5_MAX_PORTS)
628 ldev->pf[i].dev = NULL;
629 dev->priv.lag = NULL;
632 /* Must be called with intf_mutex held */
633 static void __mlx5_lag_dev_add_mdev(struct mlx5_core_dev *dev)
635 struct mlx5_lag *ldev = NULL;
636 struct mlx5_core_dev *tmp_dev;
638 if (!MLX5_CAP_GEN(dev, vport_group_manager) ||
639 !MLX5_CAP_GEN(dev, lag_master) ||
640 MLX5_CAP_GEN(dev, num_lag_ports) != MLX5_MAX_PORTS)
643 tmp_dev = mlx5_get_next_phys_dev(dev);
645 ldev = tmp_dev->priv.lag;
648 ldev = mlx5_lag_dev_alloc(dev);
650 mlx5_core_err(dev, "Failed to alloc lag dev\n");
657 mlx5_ldev_add_mdev(ldev, dev);
662 void mlx5_lag_remove_mdev(struct mlx5_core_dev *dev)
664 struct mlx5_lag *ldev;
666 ldev = mlx5_lag_dev(dev);
670 mlx5_dev_list_lock();
671 mlx5_ldev_remove_mdev(ldev, dev);
672 mlx5_dev_list_unlock();
676 void mlx5_lag_add_mdev(struct mlx5_core_dev *dev)
678 mlx5_dev_list_lock();
679 __mlx5_lag_dev_add_mdev(dev);
680 mlx5_dev_list_unlock();
683 /* Must be called with intf_mutex held */
684 void mlx5_lag_remove_netdev(struct mlx5_core_dev *dev,
685 struct net_device *netdev)
687 struct mlx5_lag *ldev;
689 ldev = mlx5_lag_dev(dev);
693 if (__mlx5_lag_is_active(ldev))
694 mlx5_disable_lag(ldev);
696 mlx5_ldev_remove_netdev(ldev, netdev);
697 ldev->flags &= ~MLX5_LAG_FLAG_READY;
700 /* Must be called with intf_mutex held */
701 void mlx5_lag_add_netdev(struct mlx5_core_dev *dev,
702 struct net_device *netdev)
704 struct mlx5_lag *ldev;
707 ldev = mlx5_lag_dev(dev);
711 mlx5_ldev_add_netdev(ldev, dev, netdev);
713 for (i = 0; i < MLX5_MAX_PORTS; i++)
714 if (!ldev->pf[i].dev)
717 if (i >= MLX5_MAX_PORTS)
718 ldev->flags |= MLX5_LAG_FLAG_READY;
721 bool mlx5_lag_is_roce(struct mlx5_core_dev *dev)
723 struct mlx5_lag *ldev;
726 spin_lock(&lag_lock);
727 ldev = mlx5_lag_dev(dev);
728 res = ldev && __mlx5_lag_is_roce(ldev);
729 spin_unlock(&lag_lock);
733 EXPORT_SYMBOL(mlx5_lag_is_roce);
735 bool mlx5_lag_is_active(struct mlx5_core_dev *dev)
737 struct mlx5_lag *ldev;
740 spin_lock(&lag_lock);
741 ldev = mlx5_lag_dev(dev);
742 res = ldev && __mlx5_lag_is_active(ldev);
743 spin_unlock(&lag_lock);
747 EXPORT_SYMBOL(mlx5_lag_is_active);
749 bool mlx5_lag_is_sriov(struct mlx5_core_dev *dev)
751 struct mlx5_lag *ldev;
754 spin_lock(&lag_lock);
755 ldev = mlx5_lag_dev(dev);
756 res = ldev && __mlx5_lag_is_sriov(ldev);
757 spin_unlock(&lag_lock);
761 EXPORT_SYMBOL(mlx5_lag_is_sriov);
763 void mlx5_lag_update(struct mlx5_core_dev *dev)
765 struct mlx5_lag *ldev;
767 mlx5_dev_list_lock();
768 ldev = mlx5_lag_dev(dev);
775 mlx5_dev_list_unlock();
778 struct net_device *mlx5_lag_get_roce_netdev(struct mlx5_core_dev *dev)
780 struct net_device *ndev = NULL;
781 struct mlx5_lag *ldev;
783 spin_lock(&lag_lock);
784 ldev = mlx5_lag_dev(dev);
786 if (!(ldev && __mlx5_lag_is_roce(ldev)))
789 if (ldev->tracker.tx_type == NETDEV_LAG_TX_TYPE_ACTIVEBACKUP) {
790 ndev = ldev->tracker.netdev_state[MLX5_LAG_P1].tx_enabled ?
791 ldev->pf[MLX5_LAG_P1].netdev :
792 ldev->pf[MLX5_LAG_P2].netdev;
794 ndev = ldev->pf[MLX5_LAG_P1].netdev;
800 spin_unlock(&lag_lock);
804 EXPORT_SYMBOL(mlx5_lag_get_roce_netdev);
806 u8 mlx5_lag_get_slave_port(struct mlx5_core_dev *dev,
807 struct net_device *slave)
809 struct mlx5_lag *ldev;
812 spin_lock(&lag_lock);
813 ldev = mlx5_lag_dev(dev);
814 if (!(ldev && __mlx5_lag_is_roce(ldev)))
817 if (ldev->pf[MLX5_LAG_P1].netdev == slave)
822 port = ldev->v2p_map[port];
825 spin_unlock(&lag_lock);
828 EXPORT_SYMBOL(mlx5_lag_get_slave_port);
830 int mlx5_lag_query_cong_counters(struct mlx5_core_dev *dev,
835 int outlen = MLX5_ST_SZ_BYTES(query_cong_statistics_out);
836 struct mlx5_core_dev *mdev[MLX5_MAX_PORTS];
837 struct mlx5_lag *ldev;
842 out = kvzalloc(outlen, GFP_KERNEL);
846 memset(values, 0, sizeof(*values) * num_counters);
848 spin_lock(&lag_lock);
849 ldev = mlx5_lag_dev(dev);
850 if (ldev && __mlx5_lag_is_active(ldev)) {
851 num_ports = MLX5_MAX_PORTS;
852 mdev[MLX5_LAG_P1] = ldev->pf[MLX5_LAG_P1].dev;
853 mdev[MLX5_LAG_P2] = ldev->pf[MLX5_LAG_P2].dev;
856 mdev[MLX5_LAG_P1] = dev;
858 spin_unlock(&lag_lock);
860 for (i = 0; i < num_ports; ++i) {
861 u32 in[MLX5_ST_SZ_DW(query_cong_statistics_in)] = {};
863 MLX5_SET(query_cong_statistics_in, in, opcode,
864 MLX5_CMD_OP_QUERY_CONG_STATISTICS);
865 ret = mlx5_cmd_exec_inout(mdev[i], query_cong_statistics, in,
870 for (j = 0; j < num_counters; ++j)
871 values[j] += be64_to_cpup((__be64 *)(out + offsets[j]));
878 EXPORT_SYMBOL(mlx5_lag_query_cong_counters);