[openib-general] [PATCH] ib_mad: Replace MAD agent list with client ID table

Hal Rosenstock halr at voltaire.com
Sun Sep 12 17:21:29 PDT 2004


ib_mad: Replace MAD agent list with client ID table

Index: ib_mad.c
===================================================================
--- ib_mad.c	(revision 794)
+++ ib_mad.c	(working copy)
@@ -68,8 +68,7 @@
 
 static kmem_cache_t *ib_mad_cache;
 static struct list_head ib_mad_port_list;
-static struct list_head ib_mad_agent_list;
-static u32 ib_mad_client_id = 0;
+static struct ib_mad_agent_private
*ib_mad_client_table[IB_MAD_MAX_CLIENTS];
 
 /*
  * Locks
@@ -78,8 +77,8 @@
 /* Port list lock */
 static spinlock_t ib_mad_port_list_lock = SPIN_LOCK_UNLOCKED;
 
-/* Agent list lock */
-static spinlock_t ib_mad_agent_list_lock = SPIN_LOCK_UNLOCKED;
+/* Client list lock */
+static spinlock_t ib_mad_client_table_lock = SPIN_LOCK_UNLOCKED;
 
 
 /* Forward declarations */
@@ -112,7 +111,7 @@
 	struct ib_mad_reg_req *reg_req = NULL;
 	struct ib_mad_mgmt_class_table *class;
 	struct ib_mad_mgmt_method_table *method;
-	int ret2;
+	int ret2, i;
 	unsigned long flags;
 	u8 mgmt_class;
 
@@ -215,12 +214,17 @@
 	mad_agent->send_handler = send_handler;
 	mad_agent->context = context;
 	mad_agent->qp = priv->qp[qp_type];
-	mad_agent->hi_tid = ++ib_mad_client_id;
 
-	/* Add to mad agent list */
-	spin_lock_irqsave(&ib_mad_agent_list_lock, flags);
-	list_add_tail(&mad_agent_priv->agent_list, &ib_mad_agent_list);
-	spin_unlock_irqrestore(&ib_mad_agent_list_lock, flags);
+	/* Add mad agent into client table */
+	spin_lock_irqsave(&ib_mad_client_table_lock, flags);
+	for (i = 0; i < IB_MAD_MAX_CLIENTS; i++) {
+		if (ib_mad_client_table[i] == NULL) {
+			mad_agent->hi_tid = i;
+			ib_mad_client_table[i] = mad_agent_priv;
+			break;
+		}
+	}
+	spin_unlock_irqrestore(&ib_mad_client_table_lock, flags);
 
 	ret2 = add_mad_reg_req(mad_reg_req, mad_agent_priv);
 	spin_unlock_irqrestore(&priv->reg_lock, flags);
@@ -232,10 +236,10 @@
 	return mad_agent;
 
 error3:
-	/* Remove from mad agent list */
-	spin_lock_irqsave(&ib_mad_agent_list_lock, flags);
-	list_del(&mad_agent_priv->agent_list);
-	spin_unlock_irqrestore(&ib_mad_agent_list_lock, flags);
+	/* Remove mad agent from client table */
+	spin_lock_irqsave(&ib_mad_client_table_lock, flags);
+	ib_mad_client_table[mad_agent->hi_tid] = NULL;
+	spin_unlock_irqrestore(&ib_mad_client_table_lock, flags);
 
 	/* Release allocated structures */
 	kfree(reg_req);
@@ -252,23 +256,24 @@
  */
 int ib_mad_dereg(struct ib_mad_agent *mad_agent)
 {
-	struct ib_mad_agent_private *entry, *temp;
+	int i;
 	unsigned long flags;
 
-	spin_lock_irqsave(&ib_mad_agent_list_lock, flags);
-	list_for_each_entry_safe(entry, temp, &ib_mad_agent_list, agent_list)
{
-		if (entry->agent == mad_agent) {
-			remove_mad_reg_req(entry);
-			list_del(&entry->agent_list);
+	spin_lock_irqsave(&ib_mad_client_table_lock, flags);
+	for (i = 0; i < IB_MAD_MAX_CLIENTS; i++) {
+		if (ib_mad_client_table[i]->agent == mad_agent) {
+			remove_mad_reg_req(ib_mad_client_table[i]);
+			
+			/* Release allocated structures */
+			kfree(ib_mad_client_table[i]->reg_req);
+			kfree(ib_mad_client_table[i]->agent);
+			kfree(ib_mad_client_table[i]);
 
-			/* Release allocated structures */
-			kfree(entry->reg_req);
-			kfree(entry->agent);
-			kfree(entry);
+			ib_mad_client_table[i] = NULL;	
 			break;
 		}
 	}
-	spin_unlock_irqrestore(&ib_mad_agent_list_lock, flags);
+	spin_unlock_irqrestore(&ib_mad_client_table_lock, flags);
 
 	return 0;
 }
@@ -1257,6 +1262,7 @@
 	ib_dealloc_pd(priv->pd);
 	ib_destroy_cq(priv->cq);
 	/* Handle deallocation of MAD registration tables!!! */
+
 	kfree(priv);
 	device->mad = NULL;
 
@@ -1360,6 +1366,8 @@
 
 static int __init ib_mad_init_module(void)
 {
+	int i;
+
 	ib_mad_cache = kmem_cache_create("ib_mad",
 					 sizeof(struct ib_mad_private),
 					 0,
@@ -1372,8 +1380,11 @@
 	}
 
 	INIT_LIST_HEAD(&ib_mad_port_list);
-	INIT_LIST_HEAD(&ib_mad_agent_list);
 
+	for (i = 0; i < IB_MAD_MAX_CLIENTS; i++) {
+		ib_mad_client_table[i] = NULL;
+	}
+
 	ib_device_notifier_register(&mad_notifier);
 
 	return 0;
Index: ib_mad_priv.h
===================================================================
--- ib_mad_priv.h	(revision 794)
+++ ib_mad_priv.h	(working copy)
@@ -60,7 +60,9 @@
 #include <linux/kthread.h>
 
 
-#define IB_MAD_QPS_CORE		2 /* Always QP0 and QP1 */
+#define IB_MAD_MAX_CLIENTS	32
+
+#define IB_MAD_QPS_CORE		2 /* Always QP0 and QP1 as a minimum */
 #define IB_MAD_QPS_SUPPORTED	2
 
 /* QP and CQ parameters */
@@ -96,7 +98,6 @@
 } __attribute__ ((packed));
 
 struct ib_mad_agent_private {
-	struct list_head agent_list;
 	struct ib_mad_agent *agent;
 	struct ib_mad_reg_req *reg_req;
 	u8 rmpp_version;
Index: TODO
===================================================================
--- TODO	(revision 794)
+++ TODO	(working copy)
@@ -3,7 +3,6 @@
 OpenIB MAD Layer
 
 Short Term
-Client ID table
 Use wait queue and wait_event rather than signals and semaphores
 Finish receive path coding
 





More information about the general mailing list