From: Maher Sanalla <msanalla@nvidia.com>
Subject: [PATCH] BACKPORT: drivers/infiniband/core/mad.c

Change-Id: I51136e6809fae4248f3539115f22abad6effdeb3
---
 drivers/infiniband/core/mad.c | 113 +++++++++++++++++++++++++++-------
 1 file changed, 90 insertions(+), 23 deletions(-)

--- a/drivers/infiniband/core/mad.c
+++ b/drivers/infiniband/core/mad.c
@@ -55,6 +55,7 @@
 #include "opa_smi.h"
 #include "agent.h"
 
+#ifndef MLX_DISABLE_TRACEPOINTS
 #define CREATE_TRACE_POINTS
 #include <trace/events/ib_mad.h>
 
@@ -75,6 +76,7 @@ static void create_mad_addr_info(struct
 	entry->dlid = rdma_ah_get_dlid(&attr);
 }
 #endif
+#endif
 
 static int mad_sendq_size = IB_MAD_QP_SEND_SIZE;
 static int mad_recvq_size = IB_MAD_QP_RECV_SIZE;
@@ -146,11 +148,9 @@ static int send_sa_cc_mad(struct ib_mad_
 /*
  * Timeout FIFO functions - implements FIFO with timeout mechanism
  */
-
 static void activate_timeout_handler_task(struct timer_list *t)
 {
 	struct to_fifo *tf;
-
 	tf = from_timer(tf, t, timer);
 	del_timer(&tf->timer);
 	queue_work(tf->workq, &tf->work);
@@ -807,30 +807,46 @@ struct ib_mad_agent *ib_register_mad_age
 	/* Validate parameters */
 	qpn = get_spl_qp_index(qp_type);
 	if (qpn == -1) {
+#ifdef RATELIMIT_STATE_INIT
 		dev_dbg_ratelimited(&device->dev, "%s: invalid QP Type %d\n",
 				    __func__, qp_type);
+#else
+		dev_notice(&device->dev,"%s: invalid QP Type %d\n",__func__, qp_type);
+#endif
 		goto error1;
 	}
 
 	if (rmpp_version && rmpp_version != IB_MGMT_RMPP_VERSION) {
+#ifdef RATELIMIT_STATE_INIT
 		dev_dbg_ratelimited(&device->dev,
 				    "%s: invalid RMPP Version %u\n",
 				    __func__, rmpp_version);
+#else
+		dev_notice(&device->dev,"%s: invalid RMPP Version%u\n",__func__, rmpp_version);
+#endif
 		goto error1;
 	}
 
 	/* Validate MAD registration request if supplied */
 	if (mad_reg_req) {
 		if (mad_reg_req->mgmt_class_version >= MAX_MGMT_VERSION) {
+#ifdef RATELIMIT_STATE_INIT
 			dev_dbg_ratelimited(&device->dev,
 					    "%s: invalid Class Version %u\n",
 					    __func__,
 					    mad_reg_req->mgmt_class_version);
+#else
+		dev_notice(&device->dev,"%s: invalid Class Version %u\n",__func__, mad_reg_req->mgmt_class_version);
+#endif
 			goto error1;
 		}
 		if (!recv_handler) {
+#ifdef RATELIMIT_STATE_INIT
 			dev_dbg_ratelimited(&device->dev,
 					    "%s: no recv_handler\n", __func__);
+#else
+		dev_notice(&device->dev,"%s:  no recv_handler\n",__func__);
+#endif
 			goto error1;
 		}
 		if (mad_reg_req->mgmt_class >= MAX_MGMT_CLASS) {
@@ -840,9 +856,13 @@ struct ib_mad_agent *ib_register_mad_age
 			 */
 			if (mad_reg_req->mgmt_class !=
 			    IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) {
+#ifdef RATELIMIT_STATE_INIT
 				dev_dbg_ratelimited(&device->dev,
 					"%s: Invalid Mgmt Class 0x%x\n",
 					__func__, mad_reg_req->mgmt_class);
+#else
+		dev_notice(&device->dev,"%s: Invalid Mgmt Class 0x%x\n",__func__, mad_reg_req->mgmt_class);
+#endif
 				goto error1;
 			}
 		} else if (mad_reg_req->mgmt_class == 0) {
@@ -850,9 +870,13 @@ struct ib_mad_agent *ib_register_mad_age
 			 * Class 0 is reserved in IBA and is used for
 			 * aliasing of IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
 			 */
+#ifdef RATELIMIT_STATE_INIT
 			dev_dbg_ratelimited(&device->dev,
 					    "%s: Invalid Mgmt Class 0\n",
 					    __func__);
+#else
+		dev_notice(&device->dev,"%s: Invalid Mgmt Class 0\n",__func__);
+#endif
 			goto error1;
 		} else if (is_vendor_class(mad_reg_req->mgmt_class)) {
 			/*
@@ -860,19 +884,27 @@ struct ib_mad_agent *ib_register_mad_age
 			 * ensure supplied OUI is not zero
 			 */
 			if (!is_vendor_oui(mad_reg_req->oui)) {
+#ifdef RATELIMIT_STATE_INIT
 				dev_dbg_ratelimited(&device->dev,
 					"%s: No OUI specified for class 0x%x\n",
 					__func__,
 					mad_reg_req->mgmt_class);
+#else
+		dev_notice(&device->dev,"%s: No OUI specified for class 0x%x\n",__func__, mad_reg_req->mgmt_class);
+#endif
 				goto error1;
 			}
 		}
 		/* Make sure class supplied is consistent with RMPP */
 		if (!ib_is_mad_class_rmpp(mad_reg_req->mgmt_class)) {
 			if (rmpp_version) {
+#ifdef RATELIMIT_STATE_INIT
 				dev_dbg_ratelimited(&device->dev,
 					"%s: RMPP version for non-RMPP class 0x%x\n",
 					__func__, mad_reg_req->mgmt_class);
+#else
+		dev_notice(&device->dev,"%s: RMPP version for non-RMPP class 0x%x\n",__func__, mad_reg_req->mgmt_class);
+#endif
 				goto error1;
 			}
 		}
@@ -883,9 +915,13 @@ struct ib_mad_agent *ib_register_mad_age
 					IB_MGMT_CLASS_SUBN_LID_ROUTED) &&
 			    (mad_reg_req->mgmt_class !=
 					IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)) {
+#ifdef RATELIMIT_STATE_INIT
 				dev_dbg_ratelimited(&device->dev,
 					"%s: Invalid SM QP type: class 0x%x\n",
 					__func__, mad_reg_req->mgmt_class);
+#else
+		dev_notice(&device->dev,"%s: Invalid SM QP type: class 0x%x\n",__func__, mad_reg_req->mgmt_class);
+#endif
 				goto error1;
 			}
 		} else {
@@ -893,9 +929,13 @@ struct ib_mad_agent *ib_register_mad_age
 					IB_MGMT_CLASS_SUBN_LID_ROUTED) ||
 			    (mad_reg_req->mgmt_class ==
 					IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)) {
+#ifdef RATELIMIT_STATE_INIT
 				dev_dbg_ratelimited(&device->dev,
 					"%s: Invalid GS QP type: class 0x%x\n",
 					__func__, mad_reg_req->mgmt_class);
+#else
+		dev_notice(&device->dev,"%s: Invalid GS QP type: class 0x%x\n",__func__, mad_reg_req->mgmt_class);
+#endif
 				goto error1;
 			}
 		}
@@ -910,8 +950,12 @@ struct ib_mad_agent *ib_register_mad_age
 	/* Validate device and port */
 	port_priv = ib_get_mad_port(device, port_num);
 	if (!port_priv) {
+#ifdef RATELIMIT_STATE_INIT
 		dev_dbg_ratelimited(&device->dev, "%s: Invalid port %u\n",
 				    __func__, port_num);
+#else
+		dev_notice(&device->dev,"%s: Invalid port %d\n",__func__, port_num);
+#endif
 		ret = ERR_PTR(-ENODEV);
 		goto error1;
 	}
@@ -920,8 +964,12 @@ struct ib_mad_agent *ib_register_mad_age
 	 * will not have QP0.
 	 */
 	if (!port_priv->qp_info[qpn].qp) {
+#ifdef RATELIMIT_STATE_INIT
 		dev_dbg_ratelimited(&device->dev, "%s: QP %d not supported\n",
 				    __func__, qpn);
+#else
+		dev_notice(&device->dev,"%s: QP %d not supported\n",__func__, qpn);
+#endif
 		ret = ERR_PTR(-EPROTONOSUPPORT);
 		goto error1;
 	}
@@ -968,7 +1016,6 @@ struct ib_mad_agent *ib_register_mad_age
 		ret = ERR_PTR(ret2);
 		goto error4;
 	}
-
 	/*
 	 * The mlx4 driver uses the top byte to distinguish which virtual
 	 * function generated the MAD, so we must avoid using it.
@@ -985,6 +1032,7 @@ struct ib_mad_agent *ib_register_mad_age
 	 * Make sure MAD registration (if supplied)
 	 * is non overlapping with any existing ones
 	 */
+
 	spin_lock_irq(&port_priv->reg_lock);
 	if (mad_reg_req) {
 		mgmt_class = convert_mgmt_class(mad_reg_req->mgmt_class);
@@ -1012,19 +1060,20 @@ struct ib_mad_agent *ib_register_mad_age
 					if (is_vendor_method_in_use(
 							vendor_class,
 							mad_reg_req))
-						goto error6;
+       					goto error6;
 				}
 			}
 			ret2 = add_oui_reg_req(mad_reg_req, mad_agent_priv);
 		}
 		if (ret2) {
 			ret = ERR_PTR(ret2);
-			goto error6;
+				goto error6;
 		}
 	}
 	spin_unlock_irq(&port_priv->reg_lock);
-
+#ifndef MLX_DISABLE_TRACEPOINTS
 	trace_ib_mad_create_agent(mad_agent_priv);
+#endif
 	return &mad_agent_priv->agent;
 error6:
 	spin_unlock_irq(&port_priv->reg_lock);
@@ -1049,10 +1098,10 @@ static inline void deref_mad_agent(struc
 static void unregister_mad_agent(struct ib_mad_agent_private *mad_agent_priv)
 {
 	struct ib_mad_port_private *port_priv;
-
+#ifndef MLX_DISABLE_TRACEPOINTS
 	/* Note that we could still be handling received MADs */
 	trace_ib_mad_unregister_agent(mad_agent_priv);
-
+#endif
 	/*
 	 * Canceling all sends results in dropping received response
 	 * MADs, preventing us from queuing additional work
@@ -1296,9 +1345,9 @@ static int handle_outgoing_dr_smp(struct
 	 */
 	if (opa && smp->class_version == OPA_SM_CLASS_VERSION) {
 		u32 opa_drslid;
-
+#ifndef MLX_DISABLE_TRACEPOINTS
 		trace_ib_mad_handle_out_opa_smi(opa_smp);
-
+#endif
 		if ((opa_get_smp_direction(opa_smp)
 		     ? opa_smp->route.dr.dr_dlid : opa_smp->route.dr.dr_slid) ==
 		     OPA_LID_PERMISSIVE &&
@@ -1324,8 +1373,9 @@ static int handle_outgoing_dr_smp(struct
 		    opa_smi_check_local_returning_smp(opa_smp, device) == IB_SMI_DISCARD)
 			goto out;
 	} else {
+#ifndef MLX_DISABLE_TRACEPOINTS
 		trace_ib_mad_handle_out_ib_smi(smp);
-
+#endif
 		if ((ib_get_smp_direction(smp) ? smp->dr_dlid : smp->dr_slid) ==
 		     IB_LID_PERMISSIVE &&
 		     smi_handle_dr_smp_send(smp, rdma_cap_ib_switch(device), port_num) ==
@@ -1719,7 +1769,9 @@ int ib_send_mad(struct ib_mad_send_wr_pr
 
 	spin_lock_irqsave(&qp_info->send_queue.lock, flags);
 	if (qp_info->send_queue.count < qp_info->send_queue.max_active) {
+#ifndef MLX_DISABLE_TRACEPOINTS
 		trace_ib_mad_ib_send_mad(mad_send_wr, qp_info);
+#endif
 		ret = ib_post_send(mad_agent->qp, &mad_send_wr->send_wr.wr,
 				   NULL);
 		list = &qp_info->send_queue.list;
@@ -2345,7 +2397,6 @@ out:
 		deref_mad_agent(mad_agent);
 		mad_agent = NULL;
 	}
-
 	return mad_agent;
 }
 
@@ -2600,9 +2651,9 @@ static enum smi_action handle_ib_smi(con
 {
 	enum smi_forward_action retsmi;
 	struct ib_smp *smp = (struct ib_smp *)recv->mad;
-
+#ifndef MLX_DISABLE_TRACEPOINTS
 	trace_ib_mad_handle_ib_smi(smp);
-
+#endif
 	if (smi_handle_dr_smp_recv(smp,
 				   rdma_cap_ib_switch(port_priv->device),
 				   port_num,
@@ -2687,9 +2738,9 @@ handle_opa_smi(struct ib_mad_port_privat
 {
 	enum smi_forward_action retsmi;
 	struct opa_smp *smp = (struct opa_smp *)recv->mad;
-
+#ifndef MLX_DISABLE_TRACEPOINTS
 	trace_ib_mad_handle_opa_smi(smp);
-
+#endif
 	if (opa_smi_handle_dr_smp_recv(smp,
 				   rdma_cap_ib_switch(port_priv->device),
 				   port_num,
@@ -2810,10 +2861,10 @@ static void ib_mad_recv_done(struct ib_c
 	/* Validate MAD */
 	if (!validate_mad((const struct ib_mad_hdr *)recv->mad, qp_info, opa))
 		goto out;
-
+#ifndef MLX_DISABLE_TRACEPOINTS
 	trace_ib_mad_recv_done_handler(qp_info, wc,
 				       (struct ib_mad_hdr *)recv->mad);
-
+#endif
 	mad_size = recv->mad_size;
 	response = alloc_mad_private(mad_size, GFP_KERNEL);
 	if (!response)
@@ -2860,7 +2911,9 @@ static void ib_mad_recv_done(struct ib_c
 
 	mad_agent = find_mad_agent(port_priv, (const struct ib_mad_hdr *)recv->mad);
 	if (mad_agent) {
+#ifndef MLX_DISABLE_TRACEPOINTS
 		trace_ib_mad_recv_done_agent(mad_agent);
+#endif
 		ib_mad_complete_recv(mad_agent, &recv->header.recv_wc);
 		/*
 		 * recv is freed up in error cases in ib_mad_complete_recv
@@ -3030,10 +3083,10 @@ static void ib_mad_send_done(struct ib_c
 				   mad_list);
 	send_queue = mad_list->mad_queue;
 	qp_info = send_queue->qp_info;
-
+#ifndef MLX_DISABLE_TRACEPOINTS
 	trace_ib_mad_send_done_agent(mad_send_wr->mad_agent_priv);
 	trace_ib_mad_send_done_handler(mad_send_wr, wc);
-
+#endif
 retry:
 	ib_dma_unmap_single(mad_send_wr->send_buf.mad_agent->device,
 			    mad_send_wr->header_mapping,
@@ -3062,7 +3115,9 @@ retry:
 	ib_mad_complete_send_wr(mad_send_wr, &mad_send_wc);
 
 	if (queued_send_wr) {
+#ifndef MLX_DISABLE_TRACEPOINTS
 		trace_ib_mad_send_done_resend(queued_send_wr, qp_info);
+#endif
 		ret = ib_post_send(qp_info->qp, &queued_send_wr->send_wr.wr,
 				   NULL);
 		if (ret) {
@@ -3110,7 +3165,9 @@ static bool ib_mad_send_error(struct ib_
 		if (mad_send_wr->retry) {
 			/* Repost send */
 			mad_send_wr->retry = 0;
+#ifndef MLX_DISABLE_TRACEPOINTS
 			trace_ib_mad_error_handler(mad_send_wr, qp_info);
+#endif
 			ret = ib_post_send(qp_info->qp, &mad_send_wr->send_wr.wr,
 					   NULL);
 			if (!ret)
@@ -4059,10 +4116,14 @@ static ssize_t sa_cc_attr_show(struct ko
 	return sa->show(cc_obj, buf);
 }
 
+#ifdef CONFIG_COMPAT_IS_CONST_KOBJECT_SYSFS_OPS
 static const struct sysfs_ops sa_cc_sysfs_ops = {
-	.show = sa_cc_attr_show,
-	.store = sa_cc_attr_store,
-};
+#else
+	static struct sysfs_ops sa_cc_sysfs_ops = {
+#endif
+		.show = sa_cc_attr_show,
+		.store = sa_cc_attr_store,
+	};
 
 #define SA_CC_ATTR(_name) struct sa_cc_attribute sa_cc_attr_##_name = \
 	__ATTR(_name, 0644, _name##_show, _name##_store)
@@ -4080,11 +4141,17 @@ static struct attribute *sa_cc_default_a
 	NULL
 };
 
+#ifdef HAVE_KOBJ_TYPE_DEFAULT_GROUPS
 ATTRIBUTE_GROUPS(sa_cc_default);
+#endif
 
 static struct kobj_type sa_cc_type = {
 	.sysfs_ops = &sa_cc_sysfs_ops,
+#ifdef HAVE_KOBJ_TYPE_DEFAULT_GROUPS
 	.default_groups = sa_cc_default_groups
+#else
+	.default_attrs = sa_cc_default_attrs
+#endif
 };
 
 static void cleanup_sa_cc_sysfs_ports(struct sa_cc_data *cc_obj)
