From: Valentine Fatiev <valentinef@nvidia.com>
Subject: [PATCH] BACKPORT:
 drivers/net/ethernet/mellanox/mlx5/core/en/reporter_tx.c

Change-Id: I976687d21f7fe9e5c58b327dc844cd313c542c03
---
 .../mellanox/mlx5/core/en/reporter_tx.c       | 66 ++++++++++++++++---
 1 file changed, 58 insertions(+), 8 deletions(-)

--- a/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_tx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_tx.c
@@ -127,6 +127,7 @@ static int mlx5e_tx_reporter_timeout_rec
 	return err;
 }
 
+#ifdef HAVE_DEVLINK_HEALTH_REPORT_SUPPORT
 /* state lock cannot be grabbed within this function.
  * It can cause a dead lock or a read-after-free.
  */
@@ -136,8 +137,11 @@ static int mlx5e_tx_reporter_recover_fro
 }
 
 static int mlx5e_tx_reporter_recover(struct devlink_health_reporter *reporter,
-				     void *context,
-				     struct netlink_ext_ack *extack)
+		                     void *context
+#ifdef HAVE_HEALTH_REPORTER_RECOVER_HAS_EXTACK
+                                    , struct netlink_ext_ack *extack
+#endif
+                                    )
 {
 	struct mlx5e_priv *priv = devlink_health_reporter_priv(reporter);
 	struct mlx5e_err_ctx *err_ctx = context;
@@ -352,8 +356,11 @@ out:
 }
 
 static int mlx5e_tx_reporter_diagnose(struct devlink_health_reporter *reporter,
-				      struct devlink_fmsg *fmsg,
-				      struct netlink_ext_ack *extack)
+				      struct devlink_fmsg *fmsg
+#ifdef HAVE_HEALTH_REPORTER_RECOVER_HAS_EXTACK
+                                      , struct netlink_ext_ack *extack
+#endif
+                                     )
 {
 	struct mlx5e_priv *priv = devlink_health_reporter_priv(reporter);
 	struct mlx5e_ptp *ptp_ch = priv->channels.ptp;
@@ -536,8 +543,11 @@ static int mlx5e_tx_reporter_dump_from_c
 }
 
 static int mlx5e_tx_reporter_dump(struct devlink_health_reporter *reporter,
-				  struct devlink_fmsg *fmsg, void *context,
-				  struct netlink_ext_ack *extack)
+				  struct devlink_fmsg *fmsg, void *context
+#ifdef HAVE_HEALTH_REPORTER_RECOVER_HAS_EXTACK
+                                  , struct netlink_ext_ack *extack
+#endif
+                                 )
 {
 	struct mlx5e_priv *priv = devlink_health_reporter_priv(reporter);
 	struct mlx5e_err_ctx *err_ctx = context;
@@ -545,6 +555,7 @@ static int mlx5e_tx_reporter_dump(struct
 	return err_ctx ? mlx5e_tx_reporter_dump_from_ctx(priv, err_ctx, fmsg) :
 			 mlx5e_tx_reporter_dump_all_sqs(priv, fmsg);
 }
+#endif /* HAVE_DEVLINK_HEALTH_REPORT_SUPPORT */
 
 void mlx5e_reporter_tx_err_cqe(struct mlx5e_txqsq *sq)
 {
@@ -554,7 +565,9 @@ void mlx5e_reporter_tx_err_cqe(struct ml
 
 	err_ctx.ctx = sq;
 	err_ctx.recover = mlx5e_tx_reporter_err_cqe_recover;
-	err_ctx.dump = mlx5e_tx_reporter_dump_sq;
+#ifdef HAVE_DEVLINK_HEALTH_REPORT_SUPPORT
+       err_ctx.dump = mlx5e_tx_reporter_dump_sq;
+#endif /* HAVE_DEVLINK_HEALTH_REPORT_SUPPORT */
 	snprintf(err_str, sizeof(err_str), "ERR CQE on SQ: 0x%x", sq->sqn);
 
 	mlx5e_health_report(priv, priv->tx_reporter, err_str, &err_ctx);
@@ -570,7 +583,9 @@ int mlx5e_reporter_tx_timeout(struct mlx
 	to_ctx.sq = sq;
 	err_ctx.ctx = &to_ctx;
 	err_ctx.recover = mlx5e_tx_reporter_timeout_recover;
+#ifdef HAVE_DEVLINK_HEALTH_REPORT_SUPPORT
 	err_ctx.dump = mlx5e_tx_reporter_timeout_dump;
+#endif
 	snprintf(err_str, sizeof(err_str),
 		 "TX timeout on queue: %d, SQ: 0x%x, CQ: 0x%x, SQ Cons: 0x%x SQ Prod: 0x%x, usecs since last trans: %u",
 		 sq->ch_ix, sq->sqn, sq->cq.mcq.cqn, sq->cc, sq->pc,
@@ -580,22 +595,46 @@ int mlx5e_reporter_tx_timeout(struct mlx
 	return to_ctx.status;
 }
 
+#ifdef HAVE_DEVLINK_HEALTH_REPORT_SUPPORT
 static const struct devlink_health_reporter_ops mlx5_tx_reporter_ops = {
 		.name = "tx",
 		.recover = mlx5e_tx_reporter_recover,
 		.diagnose = mlx5e_tx_reporter_diagnose,
 		.dump = mlx5e_tx_reporter_dump,
 };
+#endif
 
 #define MLX5_REPORTER_TX_GRACEFUL_PERIOD 500
 
 void mlx5e_reporter_tx_create(struct mlx5e_priv *priv)
 {
+#ifndef HAVE_DEVLINK_HEALTH_REPORT_SUPPORT
+	priv->tx_reporter = NULL;
+#else
+#ifdef HAVE_DEVLINK_PORT_HEALTH_REPORTER_CREATE
 	struct devlink_port *dl_port = mlx5e_devlink_get_dl_port(priv);
+#endif
 	struct devlink_health_reporter *reporter;
 
+#ifndef HAVE_DEVLINK_PORT_HEALTH_REPORTER_CREATE
+	struct mlx5_core_dev *mdev = priv->mdev;
+	struct devlink *devlink;
+#endif
+#ifdef HAVE_DEVL_PARAM_DRIVERINIT_VALUE_GET
+	reporter = devl_port_health_reporter_create(dl_port, &mlx5_tx_reporter_ops,
+			MLX5_REPORTER_TX_GRACEFUL_PERIOD, priv);
+#elif defined(HAVE_DEVLINK_PORT_HEALTH_REPORTER_CREATE)
 	reporter = devlink_port_health_reporter_create(dl_port, &mlx5_tx_reporter_ops,
-						       MLX5_REPORTER_TX_GRACEFUL_PERIOD, priv);
+			MLX5_REPORTER_TX_GRACEFUL_PERIOD, priv);
+#else /* HAVE_DEVL_PARAM_DRIVERINIT_VALUE_GET */
+	devlink = priv_to_devlink(mdev);
+	reporter =
+		devlink_health_reporter_create(devlink, &mlx5_tx_reporter_ops,
+#ifdef HAVE_DEVLINK_HEALTH_REPORTER_CREATE_5_ARGS
+				MLX5_REPORTER_TX_GRACEFUL_PERIOD,
+#endif
+				true, priv);
+#endif
 	if (IS_ERR(reporter)) {
 		netdev_warn(priv->netdev,
 			    "Failed to create tx reporter, err = %ld\n",
@@ -603,6 +642,7 @@ void mlx5e_reporter_tx_create(struct mlx
 		return;
 	}
 	priv->tx_reporter = reporter;
+#endif /* HAVE_DEVLINK_HEALTH_REPORT_SUPPORT */
 }
 
 void mlx5e_reporter_tx_destroy(struct mlx5e_priv *priv)
@@ -610,6 +650,16 @@ void mlx5e_reporter_tx_destroy(struct ml
 	if (!priv->tx_reporter)
 		return;
 
+#ifdef HAVE_DEVLINK_HEALTH_REPORT_SUPPORT
+
+#ifdef HAVE_DEVL_PARAM_DRIVERINIT_VALUE_GET
+	devl_health_reporter_destroy(priv->tx_reporter);
+#elif defined(HAVE_DEVLINK_PORT_HEALTH_REPORTER_DESTROY)
 	devlink_port_health_reporter_destroy(priv->tx_reporter);
+#else
+	devlink_health_reporter_destroy(priv->tx_reporter);
+#endif /* HAVE_DEVLINK_PORT_HEALTH_REPORTER_DESTROY  */
+
+#endif /* HAVE_DEVLINK_HEALTH_REPORT_SUPPORT */
 	priv->tx_reporter = NULL;
 }
