git: 7fb8dd15fa24 - stable/13 - mlx5: Implement mlx5_nic_vport_update_local_lb()

From: Hans Petter Selasky <hselasky_at_FreeBSD.org>
Date: Tue, 08 Feb 2022 15:14:11 UTC
The branch stable/13 has been updated by hselasky:

URL: https://cgit.FreeBSD.org/src/commit/?id=7fb8dd15fa241f35c99b7f1c0b7582067cee0776

commit 7fb8dd15fa241f35c99b7f1c0b7582067cee0776
Author:     Hans Petter Selasky <hselasky@FreeBSD.org>
AuthorDate: 2022-02-08 15:08:54 +0000
Commit:     Hans Petter Selasky <hselasky@FreeBSD.org>
CommitDate: 2022-02-08 15:08:54 +0000

    mlx5: Implement mlx5_nic_vport_update_local_lb()
    
    Sponsored by:   NVIDIA Networking
    
    (cherry picked from commit c1b76119cbf91e0698e2c6264be5f85ebfeea652)
---
 sys/dev/mlx5/mlx5_core/mlx5_vport.c    | 38 ++++++++++++++++++++++++++++++++++
 sys/dev/mlx5/mlx5_en/mlx5_en_ethtool.c |  7 ++++---
 sys/dev/mlx5/mlx5_ifc.h                |  5 +++--
 sys/dev/mlx5/vport.h                   |  1 +
 4 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/sys/dev/mlx5/mlx5_core/mlx5_vport.c b/sys/dev/mlx5/mlx5_core/mlx5_vport.c
index 4c90c3ddf4b6..430d56125666 100644
--- a/sys/dev/mlx5/mlx5_core/mlx5_vport.c
+++ b/sys/dev/mlx5/mlx5_core/mlx5_vport.c
@@ -1510,6 +1510,44 @@ int mlx5_modify_nic_vport_promisc(struct mlx5_core_dev *mdev,
 }
 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_promisc);
 
+int mlx5_nic_vport_update_local_lb(struct mlx5_core_dev *mdev, bool enable)
+{
+	int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
+	void *in;
+	int err;
+
+	if (!MLX5_CAP_GEN(mdev, disable_local_lb_mc) &&
+	    !MLX5_CAP_GEN(mdev, disable_local_lb_uc))
+		return 0;
+
+	in = kvzalloc(inlen, GFP_KERNEL);
+	if (!in)
+		return -ENOMEM;
+
+	MLX5_SET(modify_nic_vport_context_in, in,
+		 nic_vport_context.disable_mc_local_lb, !enable);
+	MLX5_SET(modify_nic_vport_context_in, in,
+		 nic_vport_context.disable_uc_local_lb, !enable);
+
+	if (MLX5_CAP_GEN(mdev, disable_local_lb_mc))
+		MLX5_SET(modify_nic_vport_context_in, in,
+			 field_select.disable_mc_local_lb, 1);
+
+	if (MLX5_CAP_GEN(mdev, disable_local_lb_uc))
+		MLX5_SET(modify_nic_vport_context_in, in,
+			 field_select.disable_uc_local_lb, 1);
+
+	err = mlx5_modify_nic_vport_context(mdev, in, inlen);
+
+	if (!err)
+		mlx5_core_dbg(mdev, "%s local_lb\n",
+			      enable ? "enable" : "disable");
+
+	kvfree(in);
+	return err;
+}
+EXPORT_SYMBOL_GPL(mlx5_nic_vport_update_local_lb);
+
 int mlx5_nic_vport_modify_local_lb(struct mlx5_core_dev *mdev,
 				   enum mlx5_local_lb_selection selection,
 				   u8 value)
diff --git a/sys/dev/mlx5/mlx5_en/mlx5_en_ethtool.c b/sys/dev/mlx5/mlx5_en/mlx5_en_ethtool.c
index 654a2a15cd56..d07aee1f0793 100644
--- a/sys/dev/mlx5/mlx5_en/mlx5_en_ethtool.c
+++ b/sys/dev/mlx5/mlx5_en/mlx5_en_ethtool.c
@@ -1233,7 +1233,7 @@ mlx5e_ethtool_handler(SYSCTL_HANDLER_ARGS)
 		priv->params_ethtool.mc_local_lb =
 		    priv->params_ethtool.mc_local_lb ? 1 : 0;
 
-		if (MLX5_CAP_GEN(priv->mdev, disable_local_lb)) {
+		if (MLX5_CAP_GEN(priv->mdev, disable_local_lb_mc)) {
 			error = mlx5_nic_vport_modify_local_lb(priv->mdev,
 			    MLX5_LOCAL_MC_LB, priv->params_ethtool.mc_local_lb);
 		} else {
@@ -1245,7 +1245,7 @@ mlx5e_ethtool_handler(SYSCTL_HANDLER_ARGS)
 		priv->params_ethtool.uc_local_lb =
 		    priv->params_ethtool.uc_local_lb ? 1 : 0;
 
-		if (MLX5_CAP_GEN(priv->mdev, disable_local_lb)) {
+		if (MLX5_CAP_GEN(priv->mdev, disable_local_lb_uc)) {
 			error = mlx5_nic_vport_modify_local_lb(priv->mdev,
 			    MLX5_LOCAL_UC_LB, priv->params_ethtool.uc_local_lb);
 		} else {
@@ -1446,7 +1446,8 @@ mlx5e_create_ethtool(struct mlx5e_priv *priv)
 	mlx5e_ethtool_sync_tx_completion_fact(priv);
 
 	/* get default values for local loopback, if any */
-	if (MLX5_CAP_GEN(priv->mdev, disable_local_lb)) {
+	if (MLX5_CAP_GEN(priv->mdev, disable_local_lb_mc) ||
+	    MLX5_CAP_GEN(priv->mdev, disable_local_lb_uc)) {
 		int err;
 		u8 val;
 
diff --git a/sys/dev/mlx5/mlx5_ifc.h b/sys/dev/mlx5/mlx5_ifc.h
index bea12c63a3a4..627c367eace5 100644
--- a/sys/dev/mlx5/mlx5_ifc.h
+++ b/sys/dev/mlx5/mlx5_ifc.h
@@ -1287,8 +1287,9 @@ struct mlx5_ifc_cmd_hca_cap_bits {
 	u8         log_max_wq_sz[0x5];
 
 	u8         nic_vport_change_event[0x1];
-	u8         disable_local_lb[0x1];
-	u8         reserved_59[0x9];
+	u8         disable_local_lb_uc[0x1];
+	u8         disable_local_lb_mc[0x1];
+	u8         reserved_59[0x8];
 	u8         log_max_vlan_list[0x5];
 	u8         reserved_60[0x3];
 	u8         log_max_current_mc_list[0x5];
diff --git a/sys/dev/mlx5/vport.h b/sys/dev/mlx5/vport.h
index 61dc9c4880cf..c8eabd1051d4 100644
--- a/sys/dev/mlx5/vport.h
+++ b/sys/dev/mlx5/vport.h
@@ -56,6 +56,7 @@ enum mlx5_local_lb_selection {
 int mlx5_nic_vport_query_local_lb(struct mlx5_core_dev *mdev,
 				  enum mlx5_local_lb_selection selection,
 				  u8 *value);
+int mlx5_nic_vport_update_local_lb(struct mlx5_core_dev *mdev, bool enable);
 int mlx5_nic_vport_modify_local_lb(struct mlx5_core_dev *mdev,
 				   enum mlx5_local_lb_selection selection,
 				   u8 value);