[openib-general] [PATCH] embed ib_mad_recv_buf into ib_mad_recv_wc

Sean Hefty mshefty at ichips.intel.com
Fri Dec 10 12:10:50 PST 2004


This patch replaces a pointer to struct ib_mad_recv_buf in struct ib_mad_recv_wc
by embedding the recv_buf directly.  It saves having to allocate and dereference
a pointer.

Patch touches mad.c, user_mad.c, and sa_query.c + header files.

- Sean


Index: include/ib_mad.h
===================================================================
--- include/ib_mad.h	(revision 1321)
+++ include/ib_mad.h	(working copy)
@@ -215,7 +215,7 @@
  */
 struct ib_mad_recv_wc {
 	struct ib_wc		*wc;
-	struct ib_mad_recv_buf	*recv_buf;
+	struct ib_mad_recv_buf	recv_buf;
 	int			mad_len;
 };
 
Index: core/user_mad.c
===================================================================
--- core/user_mad.c	(revision 1321)
+++ core/user_mad.c	(working copy)
@@ -148,7 +148,7 @@
 
 	memset(packet, 0, sizeof *packet);
 
-	memcpy(packet->mad.data, mad_recv_wc->recv_buf->mad, sizeof packet->mad.data);
+	memcpy(packet->mad.data, mad_recv_wc->recv_buf.mad, sizeof packet->mad.data);
 	packet->mad.status        = 0;
 	packet->mad.qpn 	  = cpu_to_be32(mad_recv_wc->wc->src_qp);
 	packet->mad.lid 	  = cpu_to_be16(mad_recv_wc->wc->slid);
Index: core/mad.c
===================================================================
--- core/mad.c	(revision 1321)
+++ core/mad.c	(working copy)
@@ -80,7 +80,7 @@
 /* Forward declarations */
 static int method_in_use(struct ib_mad_mgmt_method_table **method,
 			 struct ib_mad_reg_req *mad_reg_req);
-static void remove_mad_reg_req(struct ib_mad_agent_private *priv); 
+static void remove_mad_reg_req(struct ib_mad_agent_private *priv);
 static int ib_mad_post_receive_mads(struct ib_mad_qp_info *qp_info,
 				    struct ib_mad_private *mad);
 static void cancel_mads(struct ib_mad_agent_private *mad_agent_priv);
@@ -696,11 +696,10 @@
 			mad_priv->header.recv_wc.wc = &wc;
 			mad_priv->header.recv_wc.mad_len =
 				sizeof(struct ib_mad);
-			INIT_LIST_HEAD(&mad_priv->header.recv_buf.list);
-			mad_priv->header.recv_buf.grh = NULL;
-			mad_priv->header.recv_buf.mad = &mad_priv->mad.mad;
-			mad_priv->header.recv_wc.recv_buf =
-				&mad_priv->header.recv_buf;
+			INIT_LIST_HEAD(&mad_priv->header.recv_wc.recv_buf.list);
+			mad_priv->header.recv_wc.recv_buf.grh = NULL;
+			mad_priv->header.recv_wc.recv_buf.mad =
+				&mad_priv->mad.mad;
 			if (atomic_read(&mad_agent_priv->qp_info->snoop_count))
 				snoop_recv(mad_agent_priv->qp_info,
 					   &mad_priv->header.recv_wc,
@@ -906,11 +905,12 @@
 	 * Walk receive buffer list associated with this WC
 	 * No need to remove them from list of receive buffers
 	 */
-	list_for_each_entry(entry, &mad_recv_wc->recv_buf->list, list) {
+	list_for_each_entry(entry, &mad_recv_wc->recv_buf.list, list) {
 		/* Free previous receive buffer */
 		kmem_cache_free(ib_mad_cache, priv);
-		mad_priv_hdr = container_of(entry, struct ib_mad_private_header,
-					    recv_buf);
+		mad_priv_hdr = container_of(mad_recv_wc,
+					    struct ib_mad_private_header,
+					    recv_wc);
 		priv = container_of(mad_priv_hdr, struct ib_mad_private,
 				    header);
 	}
@@ -1462,7 +1462,7 @@
 		struct ib_mad_private *recv)
 {
 	/* Until we have RMPP, all receives are reassembled!... */
-	INIT_LIST_HEAD(&recv->header.recv_buf.list);
+	INIT_LIST_HEAD(&recv->header.recv_wc.recv_buf.list);
 	return recv;
 }
 
@@ -1553,7 +1553,6 @@
 	struct ib_mad_private *recv, *response;
 	struct ib_mad_list_head *mad_list;
 	struct ib_mad_agent_private *mad_agent;
-	struct ib_smp *smp;
 	int solicited;
 
 	response = kmem_cache_alloc(ib_mad_cache, GFP_KERNEL);
@@ -1577,32 +1576,30 @@
 	/* Setup MAD receive work completion from "normal" work completion */
 	recv->header.recv_wc.wc = wc;
 	recv->header.recv_wc.mad_len = sizeof(struct ib_mad);
-	recv->header.recv_wc.recv_buf = &recv->header.recv_buf;
-	recv->header.recv_buf.mad = (struct ib_mad *)&recv->mad;
-	recv->header.recv_buf.grh = &recv->grh;
+	recv->header.recv_wc.recv_buf.mad = &recv->mad.mad;
+	recv->header.recv_wc.recv_buf.grh = &recv->grh;
 
 	if (atomic_read(&qp_info->snoop_count))
 		snoop_recv(qp_info, &recv->header.recv_wc, IB_MAD_SNOOP_RECVS);
 
 	/* Validate MAD */
-	if (!validate_mad(recv->header.recv_buf.mad, qp_info->qp->qp_num))
+	if (!validate_mad(&recv->mad.mad, qp_info->qp->qp_num))
 		goto out;
 
-	if (recv->header.recv_buf.mad->mad_hdr.mgmt_class ==
+	if (recv->mad.mad.mad_hdr.mgmt_class ==
 	    IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) {
-		smp = (struct ib_smp *)recv->header.recv_buf.mad;
-		if (!smi_handle_dr_smp_recv(smp,
+		if (!smi_handle_dr_smp_recv(&recv->mad.smp,
 					    port_priv->device->node_type,
 					    port_priv->port_num,
 					    port_priv->device->phys_port_cnt))
 			goto out;
-		if (!smi_check_forward_dr_smp(smp))
+		if (!smi_check_forward_dr_smp(&recv->mad.smp))
 			goto local;
-		if (!smi_handle_dr_smp_send(smp,
+		if (!smi_handle_dr_smp_send(&recv->mad.smp,
 					    port_priv->device->node_type,
 					    port_priv->port_num))
 			goto out;
-		if (!smi_check_local_dr_smp(smp,
+		if (!smi_check_local_dr_smp(&recv->mad.smp,
 					    port_priv->device,
 					    port_priv->port_num))
 			goto out;
@@ -1625,7 +1622,7 @@
 		ret = port_priv->device->process_mad(port_priv->device, 0,
 						     port_priv->port_num,
 						     wc->slid,
-						     recv->header.recv_buf.mad,
+						     &recv->mad.mad,
 						     &response->mad.mad);
 		if (ret & IB_MAD_RESULT_SUCCESS) {
 			if (ret & IB_MAD_RESULT_CONSUMED)
@@ -1642,9 +1639,8 @@
 	}
 
 	/* Determine corresponding MAD agent for incoming receive MAD */
-	solicited = solicited_mad(recv->header.recv_buf.mad);
-	mad_agent = find_mad_agent(port_priv, recv->header.recv_buf.mad,
-				   solicited);
+	solicited = solicited_mad(&recv->mad.mad);
+	mad_agent = find_mad_agent(port_priv, &recv->mad.mad, solicited);
 	if (mad_agent) {
 		ib_mad_complete_recv(mad_agent, recv, solicited);
 		/*
Index: core/mad_priv.h
===================================================================
--- core/mad_priv.h	(revision 1321)
+++ core/mad_priv.h	(working copy)
@@ -90,7 +90,6 @@
 struct ib_mad_private_header {
 	struct ib_mad_list_head mad_list;
 	struct ib_mad_recv_wc recv_wc;
-	struct ib_mad_recv_buf recv_buf;
 	DECLARE_PCI_UNMAP_ADDR(mapping)
 } __attribute__ ((packed));
 
Index: core/sa_query.c
===================================================================
--- core/sa_query.c	(revision 1321)
+++ core/sa_query.c	(working copy)
@@ -728,9 +728,9 @@
 	if (query) {
 		if (mad_recv_wc->wc->status == IB_WC_SUCCESS)
 			query->callback(query,
-					mad_recv_wc->recv_buf->mad->mad_hdr.status ?
+					mad_recv_wc->recv_buf.mad->mad_hdr.status ?
 					-EINVAL : 0,
-					(struct ib_sa_mad *) mad_recv_wc->recv_buf->mad);
+					(struct ib_sa_mad *) mad_recv_wc->recv_buf.mad);
 		else
 			query->callback(query, -EIO, NULL);
 	}



More information about the general mailing list