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

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

--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -33,6 +33,9 @@
 MODULE_AUTHOR("Sean Hefty");
 MODULE_DESCRIPTION("InfiniBand CM");
 MODULE_LICENSE("Dual BSD/GPL");
+#ifdef RETPOLINE_MLNX
+MODULE_INFO(retpoline, "Y");
+#endif
 
 #define CM_DESTROY_ID_WAIT_TIMEOUT 10000 /* msecs */
 static const char * const ibcm_rej_reason_strs[] = {
@@ -1572,7 +1575,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(MLX_DISABLE_TRACEPOINTS)
 	trace_icm_send_req(&cm_id_priv->id);
+#endif
 	ret = ib_post_send_mad(msg, NULL);
 	if (ret)
 		goto out_free;
@@ -1619,9 +1624,11 @@ static int cm_issue_rej(struct cm_port *
 		IBA_SET_MEM(CM_REJ_ARI, rej_msg, ari, ari_length);
 	}
 
+#if !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);
@@ -1973,7 +1980,9 @@ static void cm_dup_req_handler(struct cm
 	}
 	spin_unlock_irq(&cm_id_priv->lock);
 
+#if !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;
@@ -2137,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(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;
@@ -2289,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(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_send_rep_err(cm_id_priv->id.local_id, cm_id->state);
+#endif
 		ret = -EINVAL;
 		goto out;
 	}
@@ -2305,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(MLX_DISABLE_TRACEPOINTS)
 	trace_icm_send_rep(cm_id);
+#endif
 	ret = ib_post_send_mad(msg, NULL);
 	if (ret)
 		goto out_free;
@@ -2366,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(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_send_cm_rtu_err(cm_id);
+#endif
 		ret = -EINVAL;
 		goto error;
 	}
@@ -2380,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(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);
@@ -2462,7 +2481,9 @@ static void cm_dup_rep_handler(struct cm
 		goto unlock;
 	spin_unlock_irq(&cm_id_priv->lock);
 
+#if !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;
@@ -2486,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(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_remote_no_priv_err(
 			 IBA_GET(CM_REP_REMOTE_COMM_ID, rep_msg));
+#endif
 		return -EINVAL;
 	}
 
@@ -2500,10 +2523,12 @@ static int cm_rep_handler(struct cm_work
 		break;
 	default:
 		ret = -EINVAL;
+#if !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;
 	}
@@ -2520,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(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. */
@@ -2537,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(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);
@@ -2665,7 +2694,9 @@ static int cm_send_dreq_locked(struct cm
 		return -EINVAL;
 
 	if (cm_id_priv->id.state != IB_CM_ESTABLISHED) {
+#if !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_dreq_skipped(&cm_id_priv->id);
+#endif
 		return -EINVAL;
 	}
 
@@ -2684,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(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);
@@ -2739,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(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_send_drep_err(&cm_id_priv->id);
+#endif
 		kfree(private_data);
 		return -EINVAL;
 	}
@@ -2754,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(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);
@@ -2804,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(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);
@@ -2828,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(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;
 	}
 
@@ -2874,7 +2915,9 @@ static int cm_dreq_handler(struct cm_wor
 						     [CM_DREQ_COUNTER]);
 		goto unlock;
 	default:
+#if !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;
@@ -2933,7 +2976,9 @@ static int cm_send_rej_locked(struct cm_
 	    (ari && ari_length > IB_CM_REJ_ARI_LENGTH))
 		return -EINVAL;
 
+#if !defined(MLX_DISABLE_TRACEPOINTS)
 	trace_icm_send_rej(&cm_id_priv->id, reason);
+#endif
 
 	switch (state) {
 	case IB_CM_REQ_SENT:
@@ -2961,7 +3006,9 @@ static int cm_send_rej_locked(struct cm_
 			      state);
 		break;
 	default:
+#if !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_send_unknown_rej_err(&cm_id_priv->id);
+#endif
 		return -EINVAL;
 	}
 
@@ -3073,7 +3120,9 @@ static int cm_rej_handler(struct cm_work
 		}
 		fallthrough;
 	default:
+#if !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_rej_unknown_err(&cm_id_priv->id);
+#endif
 		spin_unlock_irq(&cm_id_priv->lock);
 		goto out;
 	}
@@ -3129,7 +3178,9 @@ int ib_send_cm_mra(struct ib_cm_id *cm_i
 		}
 		fallthrough;
 	default:
+#if !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_send_mra_unknown_err(&cm_id_priv->id);
+#endif
 		ret = -EINVAL;
 		goto error_unlock;
 	}
@@ -3144,7 +3195,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(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_send_mra(cm_id);
+#endif
 		ret = ib_post_send_mad(msg, NULL);
 		if (ret)
 			goto error_free_msg;
@@ -3236,7 +3289,9 @@ static int cm_mra_handler(struct cm_work
 						     [CM_MRA_COUNTER]);
 		fallthrough;
 	default:
+#if !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_mra_unknown_err(&cm_id_priv->id);
+#endif
 		goto out;
 	}
 
@@ -3524,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(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;
@@ -3685,7 +3742,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(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);
@@ -3787,7 +3846,9 @@ static void cm_process_send_error(struct
 	    wc_status == IB_WC_WR_FLUSH_ERR)
 		goto out_unlock;
 
+#if !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:
@@ -3902,7 +3963,9 @@ static void cm_work_handler(struct work_
 		ret = cm_timewait_handler(work);
 		break;
 	default:
+#if !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_handler_err(work->cm_event.event);
+#endif
 		ret = -EINVAL;
 		break;
 	}
@@ -3937,7 +4000,9 @@ static int cm_establish(struct ib_cm_id
 		ret = -EISCONN;
 		break;
 	default:
+#if !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_establish_err(cm_id);
+#endif
 		ret = -EINVAL;
 		break;
 	}
@@ -4134,7 +4199,9 @@ static int cm_init_qp_init_attr(struct c
 		ret = 0;
 		break;
 	default:
+#if !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_qp_init_err(&cm_id_priv->id);
+#endif
 		ret = -EINVAL;
 		break;
 	}
@@ -4187,7 +4254,9 @@ static int cm_init_qp_rtr_attr(struct cm
 		ret = 0;
 		break;
 	default:
+#if !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_qp_rtr_err(&cm_id_priv->id);
+#endif
 		ret = -EINVAL;
 		break;
 	}
@@ -4249,7 +4318,9 @@ static int cm_init_qp_rts_attr(struct cm
 		ret = 0;
 		break;
 	default:
+#if !defined(MLX_DISABLE_TRACEPOINTS)
 		trace_icm_qp_rts_err(&cm_id_priv->id);
+#endif
 		ret = -EINVAL;
 		break;
 	}
