[openib-general] [PATCH] ib_mad: In struct ib_mad_device_private, make qp0 and qp1 an array

Hal Rosenstock halr at voltaire.com
Fri Sep 10 12:11:42 PDT 2004


ib_mad: In struct ib_mad_device_private, make qp0 and qp1 an array

Index: ib_mad.c
===================================================================
--- ib_mad.c	(revision 761)
+++ ib_mad.c	(working copy)
@@ -243,10 +243,7 @@
 	mad_agent->recv_handler = recv_handler;
 	mad_agent->send_handler = send_handler;
 	mad_agent->context = context;
-	if (qp_type == IB_QPT_GSI)
-		mad_agent->qp = priv->qp1;
-	else
-		mad_agent->qp = priv->qp0;
+	mad_agent->qp = priv->qp[qp_type];
 	mad_agent->hi_tid = ++ib_mad_client_id;
 
 	/* Add to mad agent list */
@@ -788,7 +785,6 @@
 {
 	struct ib_mad_private *mad_priv;
 	struct ib_sge sg_list;
-	struct ib_qp *qp;
 	struct ib_recv_wr recv_wr;
 	struct ib_recv_wr *bad_recv_wr;
 	IB_MAD_RECV_LIST_LOCK_VAR;
@@ -817,11 +813,6 @@
 	recv_wr.recv_flags = IB_RECV_SIGNALED;
 	recv_wr.wr_id = (unsigned long)mad_priv;
 
-	if (qp_type == IB_QPT_GSI)
-		qp = priv->qp1;
-	else
-		qp = priv->qp0;
-
 	/* Link receive WR into posted receive MAD list */
 	IB_MAD_RECV_LIST_LOCK(priv);
 	list_add_tail((struct list_head *)mad_priv,
&priv->recv_posted_mad_list);
@@ -830,7 +821,7 @@
 	pci_unmap_addr_set(&mad_priv->header.buf, mapping, sg_list.addr);
 
 	/* Now, post receive WR */
-	if (ib_post_recv(qp, &recv_wr, &bad_recv_wr)) {
+	if (ib_post_recv(priv->qp[qp_type], &recv_wr, &bad_recv_wr)) {
 		/* Unlink from posted receive MAD list */
 		IB_MAD_RECV_LIST_LOCK(priv);
 		list_del((struct list_head *)mad_priv);
@@ -1039,14 +1030,9 @@
 static int ib_mad_device_start(struct ib_mad_device_private *priv)
 {
 	int ret, i;
-	struct ib_qp *qp;
 
 	for (i = 0; i < 2; i++) {
-		if (i == 0)
-			qp = priv->qp0;
-		else
-			qp = priv->qp1;
-		ret = ib_mad_change_qp_state_to_init(qp, priv->port);
+		ret = ib_mad_change_qp_state_to_init(priv->qp[i], priv->port);
 		if (ret) {
 			printk(KERN_ERR "Could not change QP%d state to INIT\n", i);
 			return ret;
@@ -1066,17 +1052,13 @@
 	}
 
 	for (i = 0; i < 2; i++) {
-		if (i == 0)
-			qp = priv->qp0;
-		else
-			qp = priv->qp1;
-		ret = ib_mad_change_qp_state_to_rtr(qp);
+		ret = ib_mad_change_qp_state_to_rtr(priv->qp[i]);
 		if (ret) {
 			printk(KERN_ERR "Could not change QP%d state to RTR\n", i);
 			goto error;
 		}
 
-		ret = ib_mad_change_qp_state_to_rts(qp);
+		ret = ib_mad_change_qp_state_to_rts(priv->qp[i]);
 		if (ret) {
 			printk(KERN_ERR "Could not change QP%d state to RTS\n", i);
 			goto error;
@@ -1089,11 +1071,7 @@
 error:
 	ib_mad_return_posted_recv_mads(priv);
 	for (i = 0; i < 2; i++) {
-		if (i == 0)
-			qp = priv->qp0;
-		else
-			qp = priv->qp1;
-		ib_mad_change_qp_state_to_reset(qp);
+		ib_mad_change_qp_state_to_reset(priv->qp[i]);
 	}
 
 	return ret;
@@ -1105,16 +1083,11 @@
 static void ib_mad_device_stop(struct ib_mad_device_private *priv)
 {
 	int i;
-	struct ib_qp *qp;
 
 	IB_MAD_DEVICE_SET_DOWN(priv);
 
 	for (i = 0; i < 2; i++) {
-		if (i == 0)
-			qp = priv->qp0;
-		else
-			qp = priv->qp1;
-		ib_mad_change_qp_state_to_reset(qp);
+		ib_mad_change_qp_state_to_reset(priv->qp[i]);
 	}
 
 	ib_mad_return_posted_recv_mads(priv);
@@ -1151,7 +1124,6 @@
 		.size = (unsigned long) high_memory - PAGE_OFFSET
 	};
 	struct ib_device_attr device_attr;
-	struct ib_qp *qp;
 	struct ib_qp_init_attr qp_init_attr;
 	struct ib_qp_cap qp_cap;
 	struct ib_mad_device_private *entry, *priv = NULL,
@@ -1219,10 +1191,6 @@
 	}
 
 	for (i = 0; i < 2; i++) {
-		if (i == 0)
-			qp = priv->qp0;
-		else
-			qp = priv->qp1;
 		memset(&qp_init_attr, 0, sizeof qp_init_attr);
 		qp_init_attr.send_cq = priv->cq;
 		qp_init_attr.recv_cq = priv->cq;
@@ -1237,16 +1205,16 @@
 		else
 			qp_init_attr.qp_type = IB_QPT_GSI;
 		qp_init_attr.port_num = priv->port;
-		qp = ib_create_qp(priv->pd, &qp_init_attr, &qp_cap);
-		if (IS_ERR(qp)) {
+		priv->qp[i] = ib_create_qp(priv->pd, &qp_init_attr, &qp_cap);
+		if (IS_ERR(priv->qp[i])) {
 			printk(KERN_ERR "Could not create ib_mad QP%d\n", i);
-			ret = PTR_ERR(qp);
+			ret = PTR_ERR(priv->qp[i]);
 			if (i == 0)
 				goto error6;		
 			else
 				goto error7;
 			}
-		printk(KERN_DEBUG "Created ib_mad QP %d\n", qp->qp_num);
+		printk(KERN_DEBUG "Created ib_mad QP %d\n", priv->qp[i]->qp_num);
 	}
 
 	spin_lock_init(&priv->recv_list_lock);
@@ -1268,9 +1236,9 @@
 	return 0;
 
 error8:
-	ib_destroy_qp(priv->qp1);
+	ib_destroy_qp(priv->qp[1]);
 error7:
-	ib_destroy_qp(priv->qp0);
+	ib_destroy_qp(priv->qp[0]);
 error6:
 	ib_dereg_mr(priv->mr);
 error5:
@@ -1313,8 +1281,8 @@
 
 	ib_mad_device_stop(priv);
 	ib_mad_thread_stop(priv);
-	ib_destroy_qp(priv->qp1);
-	ib_destroy_qp(priv->qp0);
+	ib_destroy_qp(priv->qp[1]);
+	ib_destroy_qp(priv->qp[0]);
 	ib_dereg_mr(priv->mr);
 	ib_dealloc_pd(priv->pd);
 	ib_destroy_cq(priv->cq);
Index: ib_mad_priv.h
===================================================================
--- ib_mad_priv.h	(revision 760)
+++ ib_mad_priv.h	(working copy)
@@ -125,8 +125,7 @@
 	int port;
 	int up;
 	struct ib_mad_mgmt_class_table *version[MAX_MGMT_VERSION];
-	struct ib_qp *qp0;
-	struct ib_qp *qp1;
+	struct ib_qp *qp[2];
 	struct ib_cq *cq;
 	struct ib_pd *pd;
 	struct ib_mr *mr;





More information about the general mailing list