From: Valentine Fatiev <valentinef@nvidia.com>
Subject: [PATCH] BACKPORT: drivers/infiniband/core/cm.c

Change-Id: I2759a5278e1fe88c9e8bc2a9fa64a69c2afd41f1
---
 drivers/infiniband/core/cm.c | 73 ++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)

--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -28,11 +28,16 @@
 #include <rdma/ib_sysfs.h>
 #include "cm_msgs.h"
 #include "core_priv.h"
+#ifdef HAVE_TRACE_EVENTS_H
 #include "cm_trace.h"
+#endif
 
 MODULE_AUTHOR("Sean Hefty");
 MODULE_DESCRIPTION("InfiniBand CM");
 MODULE_LICENSE("Dual BSD/GPL");
+#ifdef RETPOLINE_MLNX
+MODULE_INFO(retpoline, "Y");
+#endif
 
 static const char * const ibcm_rej_reason_strs[] = {
 	[IB_CM_REJ_NO_QP]			= "no QP",
@@ -1569,7 +1574,9 @@ int ib_send_cm_req(struct ib_cm_id *cm_i
 	cm_id_priv->local_qpn = cpu_to_be32(IBA_GET(CM_REQ_LOCAL_QPN, req_msg));
 	cm_id_priv->rq_psn = cpu_to_be32(IBA_GET(CM_REQ_STARTING_PSN, req_msg));
 
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 	trace_icm_send_req(&cm_id_priv->id);
+#endif
 	ret = ib_post_send_mad(msg, NULL);
 	if (ret)
 		goto out_free;
@@ -1616,9 +1623,11 @@ static int cm_issue_rej(struct cm_port *
 		IBA_SET_MEM(CM_REJ_ARI, rej_msg, ari, ari_length);
 	}
 
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 	trace_icm_issue_rej(
 		IBA_GET(CM_REJ_LOCAL_COMM_ID, rcv_msg),
 		IBA_GET(CM_REJ_REMOTE_COMM_ID, rcv_msg));
+#endif
 	ret = ib_post_send_mad(msg, NULL);
 	if (ret)
 		cm_free_response_msg(msg);
@@ -1970,7 +1979,9 @@ static void cm_dup_req_handler(struct cm
 	}
 	spin_unlock_irq(&cm_id_priv->lock);
 
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 	trace_icm_send_dup_req(&cm_id_priv->id);
+#endif
 	ret = ib_post_send_mad(msg, NULL);
 	if (ret)
 		goto free;
@@ -2135,7 +2146,9 @@ static int cm_req_handler(struct cm_work
 
 	listen_cm_id_priv = cm_match_req(work, cm_id_priv);
 	if (!listen_cm_id_priv) {
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_no_listener_err(&cm_id_priv->id);
+#endif
 		cm_id_priv->id.state = IB_CM_IDLE;
 		ret = -EINVAL;
 		goto destroy;
@@ -2287,7 +2300,9 @@ int ib_send_cm_rep(struct ib_cm_id *cm_i
 	spin_lock_irqsave(&cm_id_priv->lock, flags);
 	if (cm_id->state != IB_CM_REQ_RCVD &&
 	    cm_id->state != IB_CM_MRA_REQ_SENT) {
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_send_rep_err(cm_id_priv->id.local_id, cm_id->state);
+#endif
 		ret = -EINVAL;
 		goto out;
 	}
@@ -2303,7 +2318,9 @@ int ib_send_cm_rep(struct ib_cm_id *cm_i
 	msg->timeout_ms = cm_id_priv->timeout_ms;
 	msg->context[1] = (void *) (unsigned long) IB_CM_REP_SENT;
 
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 	trace_icm_send_rep(cm_id);
+#endif
 	ret = ib_post_send_mad(msg, NULL);
 	if (ret)
 		goto out_free;
@@ -2364,7 +2381,9 @@ int ib_send_cm_rtu(struct ib_cm_id *cm_i
 	spin_lock_irqsave(&cm_id_priv->lock, flags);
 	if (cm_id->state != IB_CM_REP_RCVD &&
 	    cm_id->state != IB_CM_MRA_REP_SENT) {
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_send_cm_rtu_err(cm_id);
+#endif
 		ret = -EINVAL;
 		goto error;
 	}
@@ -2378,7 +2397,9 @@ int ib_send_cm_rtu(struct ib_cm_id *cm_i
 	cm_format_rtu((struct cm_rtu_msg *) msg->mad, cm_id_priv,
 		      private_data, private_data_len);
 
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 	trace_icm_send_rtu(cm_id);
+#endif
 	ret = ib_post_send_mad(msg, NULL);
 	if (ret) {
 		spin_unlock_irqrestore(&cm_id_priv->lock, flags);
@@ -2460,7 +2481,9 @@ static void cm_dup_rep_handler(struct cm
 		goto unlock;
 	spin_unlock_irq(&cm_id_priv->lock);
 
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 	trace_icm_send_dup_rep(&cm_id_priv->id);
+#endif
 	ret = ib_post_send_mad(msg, NULL);
 	if (ret)
 		goto free;
@@ -2484,8 +2507,10 @@ static int cm_rep_handler(struct cm_work
 		cpu_to_be32(IBA_GET(CM_REP_REMOTE_COMM_ID, rep_msg)), 0);
 	if (!cm_id_priv) {
 		cm_dup_rep_handler(work);
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_remote_no_priv_err(
 			 IBA_GET(CM_REP_REMOTE_COMM_ID, rep_msg));
+#endif
 		return -EINVAL;
 	}
 
@@ -2498,10 +2523,12 @@ static int cm_rep_handler(struct cm_work
 		break;
 	default:
 		ret = -EINVAL;
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_rep_unknown_err(
 			IBA_GET(CM_REP_LOCAL_COMM_ID, rep_msg),
 			IBA_GET(CM_REP_REMOTE_COMM_ID, rep_msg),
 			cm_id_priv->id.state);
+#endif
 		spin_unlock_irq(&cm_id_priv->lock);
 		goto error;
 	}
@@ -2518,8 +2545,10 @@ static int cm_rep_handler(struct cm_work
 		spin_unlock(&cm.lock);
 		spin_unlock_irq(&cm_id_priv->lock);
 		ret = -EINVAL;
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_insert_failed_err(
 			 IBA_GET(CM_REP_REMOTE_COMM_ID, rep_msg));
+#endif
 		goto error;
 	}
 	/* Check for a stale connection. */
@@ -2535,9 +2564,11 @@ static int cm_rep_handler(struct cm_work
 			     IB_CM_REJ_STALE_CONN, CM_MSG_RESPONSE_REP,
 			     NULL, 0);
 		ret = -EINVAL;
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_staleconn_err(
 			IBA_GET(CM_REP_LOCAL_COMM_ID, rep_msg),
 			IBA_GET(CM_REP_REMOTE_COMM_ID, rep_msg));
+#endif
 
 		if (cur_cm_id_priv) {
 			ib_send_cm_dreq(&cur_cm_id_priv->id, NULL, 0);
@@ -2663,7 +2694,9 @@ static int cm_send_dreq_locked(struct cm
 		return -EINVAL;
 
 	if (cm_id_priv->id.state != IB_CM_ESTABLISHED) {
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_dreq_skipped(&cm_id_priv->id);
+#endif
 		return -EINVAL;
 	}
 
@@ -2682,7 +2715,9 @@ static int cm_send_dreq_locked(struct cm
 	msg->timeout_ms = cm_id_priv->timeout_ms;
 	msg->context[1] = (void *) (unsigned long) IB_CM_DREQ_SENT;
 
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 	trace_icm_send_dreq(&cm_id_priv->id);
+#endif
 	ret = ib_post_send_mad(msg, NULL);
 	if (ret) {
 		cm_enter_timewait(cm_id_priv);
@@ -2737,7 +2772,9 @@ static int cm_send_drep_locked(struct cm
 		return -EINVAL;
 
 	if (cm_id_priv->id.state != IB_CM_DREQ_RCVD) {
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_send_drep_err(&cm_id_priv->id);
+#endif
 		kfree(private_data);
 		return -EINVAL;
 	}
@@ -2752,7 +2789,9 @@ static int cm_send_drep_locked(struct cm
 	cm_format_drep((struct cm_drep_msg *) msg->mad, cm_id_priv,
 		       private_data, private_data_len);
 
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 	trace_icm_send_drep(&cm_id_priv->id);
+#endif
 	ret = ib_post_send_mad(msg, NULL);
 	if (ret) {
 		cm_free_msg(msg);
@@ -2802,9 +2841,11 @@ static int cm_issue_drep(struct cm_port
 	IBA_SET(CM_DREP_LOCAL_COMM_ID, drep_msg,
 		IBA_GET(CM_DREQ_REMOTE_COMM_ID, dreq_msg));
 
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 	trace_icm_issue_drep(
 		IBA_GET(CM_DREQ_LOCAL_COMM_ID, dreq_msg),
 		IBA_GET(CM_DREQ_REMOTE_COMM_ID, dreq_msg));
+#endif
 	ret = ib_post_send_mad(msg, NULL);
 	if (ret)
 		cm_free_response_msg(msg);
@@ -2826,9 +2867,11 @@ static int cm_dreq_handler(struct cm_wor
 		atomic_long_inc(&work->port->counters[CM_RECV_DUPLICATES]
 						     [CM_DREQ_COUNTER]);
 		cm_issue_drep(work->port, work->mad_recv_wc);
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_no_priv_err(
 			IBA_GET(CM_DREQ_LOCAL_COMM_ID, dreq_msg),
 			IBA_GET(CM_DREQ_REMOTE_COMM_ID, dreq_msg));
+#endif
 		return -EINVAL;
 	}
 
@@ -2872,7 +2915,9 @@ static int cm_dreq_handler(struct cm_wor
 						     [CM_DREQ_COUNTER]);
 		goto unlock;
 	default:
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_dreq_unknown_err(&cm_id_priv->id);
+#endif
 		goto unlock;
 	}
 	cm_id_priv->id.state = IB_CM_DREQ_RCVD;
@@ -2957,11 +3002,15 @@ static int cm_send_rej_locked(struct cm_
 			      state);
 		break;
 	default:
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_send_unknown_rej_err(&cm_id_priv->id);
+#endif
 		return -EINVAL;
 	}
 
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 	trace_icm_send_rej(&cm_id_priv->id, reason);
+#endif
 	ret = ib_post_send_mad(msg, NULL);
 	if (ret) {
 		cm_free_msg(msg);
@@ -3070,7 +3119,9 @@ static int cm_rej_handler(struct cm_work
 		}
 		fallthrough;
 	default:
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_rej_unknown_err(&cm_id_priv->id);
+#endif
 		spin_unlock_irq(&cm_id_priv->lock);
 		goto out;
 	}
@@ -3126,7 +3177,9 @@ int ib_send_cm_mra(struct ib_cm_id *cm_i
 		}
 		fallthrough;
 	default:
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_send_mra_unknown_err(&cm_id_priv->id);
+#endif
 		ret = -EINVAL;
 		goto error_unlock;
 	}
@@ -3141,7 +3194,9 @@ int ib_send_cm_mra(struct ib_cm_id *cm_i
 		cm_format_mra((struct cm_mra_msg *) msg->mad, cm_id_priv,
 			      msg_response, service_timeout,
 			      private_data, private_data_len);
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_send_mra(cm_id);
+#endif
 		ret = ib_post_send_mad(msg, NULL);
 		if (ret)
 			goto error_free_msg;
@@ -3233,7 +3288,9 @@ static int cm_mra_handler(struct cm_work
 						     [CM_MRA_COUNTER]);
 		fallthrough;
 	default:
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_mra_unknown_err(&cm_id_priv->id);
+#endif
 		goto out;
 	}
 
@@ -3522,7 +3579,9 @@ int ib_send_cm_sidr_req(struct ib_cm_id
 	msg->timeout_ms = cm_id_priv->timeout_ms;
 	msg->context[1] = (void *)(unsigned long)IB_CM_SIDR_REQ_SENT;
 
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 	trace_icm_send_sidr_req(&cm_id_priv->id);
+#endif
 	ret = ib_post_send_mad(msg, NULL);
 	if (ret)
 		goto out_free;
@@ -3684,7 +3743,9 @@ static int cm_send_sidr_rep_locked(struc
 
 	cm_format_sidr_rep((struct cm_sidr_rep_msg *) msg->mad, cm_id_priv,
 			   param);
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 	trace_icm_send_sidr_rep(&cm_id_priv->id);
+#endif
 	ret = ib_post_send_mad(msg, NULL);
 	if (ret) {
 		cm_free_msg(msg);
@@ -3786,7 +3847,9 @@ static void cm_process_send_error(struct
 	    wc_status == IB_WC_WR_FLUSH_ERR)
 		goto out_unlock;
 
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 	trace_icm_mad_send_err(state, wc_status);
+#endif
 	switch (state) {
 	case IB_CM_REQ_SENT:
 	case IB_CM_MRA_REQ_RCVD:
@@ -3901,7 +3964,9 @@ static void cm_work_handler(struct work_
 		ret = cm_timewait_handler(work);
 		break;
 	default:
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_handler_err(work->cm_event.event);
+#endif
 		ret = -EINVAL;
 		break;
 	}
@@ -3936,7 +4001,9 @@ static int cm_establish(struct ib_cm_id
 		ret = -EISCONN;
 		break;
 	default:
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_establish_err(cm_id);
+#endif
 		ret = -EINVAL;
 		break;
 	}
@@ -4124,7 +4191,9 @@ static int cm_init_qp_init_attr(struct c
 		ret = 0;
 		break;
 	default:
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_qp_init_err(&cm_id_priv->id);
+#endif
 		ret = -EINVAL;
 		break;
 	}
@@ -4177,7 +4246,9 @@ static int cm_init_qp_rtr_attr(struct cm
 		ret = 0;
 		break;
 	default:
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_qp_rtr_err(&cm_id_priv->id);
+#endif
 		ret = -EINVAL;
 		break;
 	}
@@ -4239,7 +4310,9 @@ static int cm_init_qp_rts_attr(struct cm
 		ret = 0;
 		break;
 	default:
+#if defined(HAVE_TRACE_EVENTS_H) && !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_qp_rts_err(&cm_id_priv->id);
+#endif
 		ret = -EINVAL;
 		break;
 	}
