[openib-general] [PATCH] ib_mad: Consolidate registration and agent locks

Hal Rosenstock halr at voltaire.com
Tue Sep 14 07:29:12 PDT 2004


ib_mad: Consolidate registration and agent locks

Index: access/ib_mad.c
===================================================================
--- access/ib_mad.c	(revision 821)
+++ access/ib_mad.c	(working copy)
@@ -86,7 +86,7 @@
 
 
 /*
- * ib_register_mad_agent eg - Register to send/receive MADs
+ * ib_register_mad_agent - Register to send/receive MADs
  */
 struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
 					   u8 port,
@@ -130,14 +130,14 @@
 			goto error1;
 		}
 		if (mad_reg_req->mgmt_class >= MAX_MGMT_CLASS) {
-			/* IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE is only one currently allowed
*/
+			/* IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE is the only one currently
allowed */
 			if (mad_reg_req->mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) {
 				ret = ERR_PTR(-EINVAL);
 				goto error1;
 			}
 		} else if (mad_reg_req->mgmt_class == 0) {
 			/* 
-			 * Class 0 is reserved in IBA and is used here for 
+			 * Class 0 is reserved in IBA and is used for 
 			 * aliasing of IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
 			 */
 			ret = ERR_PTR(-EINVAL);
@@ -213,24 +213,21 @@
 	mad_agent->hi_tid = ++ib_mad_client_id;
 
 	/* Add mad agent into agent list */
-	spin_lock_irqsave(&port_priv->agent_lock, flags);
 	list_add_tail(&mad_agent_priv->agent_list, &port_priv->agent_list);
-	spin_unlock_irqrestore(&port_priv->agent_lock, flags);
 
 	ret2 = add_mad_reg_req(mad_reg_req, mad_agent_priv);
-	spin_unlock_irqrestore(&port_priv->reg_lock, flags);
 	if (ret2) {
 		ret = ERR_PTR(ret2);	
 		goto error3;	
 	}
+	spin_unlock_irqrestore(&port_priv->reg_lock, flags);
 
 	return mad_agent;
 
 error3:
 	/* Remove mad agent from agent list */
-	spin_lock_irqsave(&port_priv->agent_lock, flags);
 	list_del(&mad_agent_priv->agent_list);
-	spin_unlock_irqrestore(&port_priv->agent_lock, flags);
+	spin_unlock_irqrestore(&port_priv->reg_lock, flags);
 
 	/* Release allocated structures */
 	kfree(reg_req);
@@ -252,9 +249,14 @@
 	int not_found = 1;
 	unsigned long flags, flags2;
 
+	/*
+	 * Rather than walk all the mad agent lists on all the mad ports,
+	 * might use device in mad_agent and port number from mad agent QP
+	 * but this approach has some downsides
+	 */
 	spin_lock_irqsave(&ib_mad_port_list_lock, flags);
 	list_for_each_entry(entry, &ib_mad_port_list, port_list) {
-		spin_lock_irqsave(&entry->agent_lock, flags2);
+		spin_lock_irqsave(&entry->reg_lock, flags2);
 		list_for_each_entry_safe(entry2, temp, 
 					 &entry->agent_list, agent_list) {
 			if (entry2->agent == mad_agent) {
@@ -269,7 +271,7 @@
 				break;
 			}
 		}
-		spin_unlock_irqrestore(&entry->agent_lock, flags2);	
+		spin_unlock_irqrestore(&entry->reg_lock, flags2);	
 	}
 	spin_unlock_irqrestore(&ib_mad_port_list_lock, flags);
 	return not_found;
@@ -664,7 +666,7 @@
 {
 	struct ib_mad_recv_wc recv_wc;
 	struct ib_mad_private *recv;
-	unsigned long flags, flags2;
+	unsigned long flags;
 	u32 qp_num;
 	struct ib_mad_agent_private *mad_agent;
 	int solicited;
@@ -711,7 +713,6 @@
 
 	/* Determine corresponding MAD agent for incoming receive MAD */
 	spin_lock_irqsave(&port_priv->reg_lock, flags);
-	spin_lock_irqsave(&port_priv->agent_lock, flags2);
 	/* First, determine whether MAD was solicited */
 	solicited = solicited_mad(recv->header.recv_buf.mad);
 	/* Now, find the mad agent */
@@ -730,7 +731,6 @@
 		mad_agent->agent->recv_handler(mad_agent->agent,
 					       &recv_wc);
 	}
-	spin_unlock_irqrestore(&port_priv->agent_lock, flags2);
 	spin_unlock_irqrestore(&port_priv->reg_lock, flags);
 
 	/* Repost receive request */
@@ -1324,7 +1324,6 @@
 		       port_priv->qp[i]->qp_num);
 	}
 
-	spin_lock_init(&port_priv->agent_lock);
 	spin_lock_init(&port_priv->reg_lock);
 	spin_lock_init(&port_priv->recv_list_lock);
 	spin_lock_init(&port_priv->send_list_lock);
Index: access/ib_mad_priv.h
===================================================================
--- access/ib_mad_priv.h	(revision 821)
+++ access/ib_mad_priv.h	(working copy)
@@ -133,11 +133,9 @@
 	struct ib_pd *pd;
 	struct ib_mr *mr;
 
-	spinlock_t agent_lock;
-	struct list_head agent_list;
-
 	spinlock_t reg_lock;
 	struct ib_mad_mgmt_class_table *version[MAX_MGMT_VERSION];
+	struct list_head agent_list;
 
 	spinlock_t send_list_lock;
 	struct list_head send_posted_mad_list;





More information about the general mailing list