[openib-general] [PATCH 4/5] Get rid of static rdev table.

Steve Wise swise at opengridcomputing.com
Thu Feb 8 12:26:42 PST 2007


From: Steve Wise <swise at opengridcomputing.com>

Use a liked list.

Signed-off-by: Steve Wise <swise at opengridcomputing.com>
---

 drivers/infiniband/hw/cxgb3/core/cxio_hal.c |   57 +++++++++------------------
 drivers/infiniband/hw/cxgb3/core/cxio_hal.h |    2 -
 2 files changed, 19 insertions(+), 40 deletions(-)

diff --git a/drivers/infiniband/hw/cxgb3/core/cxio_hal.c b/drivers/infiniband/hw/cxgb3/core/cxio_hal.c
index 2c4e351..acffe16 100644
--- a/drivers/infiniband/hw/cxgb3/core/cxio_hal.c
+++ b/drivers/infiniband/hw/cxgb3/core/cxio_hal.c
@@ -43,49 +43,28 @@ #include "cxio_hal.h"
 #include "cxgb3_offload.h"
 #include "sge_defs.h"
 
-static struct cxio_rdev *rdev_tbl[T3_MAX_NUM_RNIC];
+static LIST_HEAD(rdev_list);
 static cxio_hal_ev_callback_func_t cxio_ev_cb = NULL;
 
 static inline struct cxio_rdev *cxio_hal_find_rdev_by_name(char *dev_name)
 {
-	int i;
-	for (i = 0; i < T3_MAX_NUM_RNIC; i++)
-		if (rdev_tbl[i])
-			if (!strcmp(rdev_tbl[i]->dev_name, dev_name))
-				return rdev_tbl[i];
+	struct cxio_rdev *rdev;
+
+	list_for_each_entry(rdev, &rdev_list, entry)
+		if (!strcmp(rdev->dev_name, dev_name))
+			return rdev;
 	return NULL;
 }
 
 static inline struct cxio_rdev *cxio_hal_find_rdev_by_t3cdev(struct t3cdev
 							     *tdev)
 {
-	int i;
-	for (i = 0; i < T3_MAX_NUM_RNIC; i++)
-		if (rdev_tbl[i])
-			if (rdev_tbl[i]->t3cdev_p == tdev)
-				return rdev_tbl[i];
-	return NULL;
-}
-
-static inline int cxio_hal_add_rdev(struct cxio_rdev *rdev_p)
-{
-	int i;
-	for (i = 0; i < T3_MAX_NUM_RNIC; i++)
-		if (!rdev_tbl[i]) {
-			rdev_tbl[i] = rdev_p;
-			break;
-		}
-	return (i == T3_MAX_NUM_RNIC);
-}
+	struct cxio_rdev *rdev;
 
-static inline void cxio_hal_delete_rdev(struct cxio_rdev *rdev_p)
-{
-	int i;
-	for (i = 0; i < T3_MAX_NUM_RNIC; i++)
-		if (rdev_tbl[i] == rdev_p) {
-			rdev_tbl[i] = NULL;
-			break;
-		}
+	list_for_each_entry(rdev, &rdev_list, entry)
+		if (rdev->t3cdev_p == tdev)
+			return rdev;
+	return NULL;
 }
 
 int cxio_hal_cq_op(struct cxio_rdev *rdev_p, struct t3_cq *cq,
@@ -937,8 +916,7 @@ int cxio_rdev_open(struct cxio_rdev *rde
 		return -EINVAL;
 	}
 
-	if (cxio_hal_add_rdev(rdev_p))
-		return -ENOMEM;
+	list_add_tail(&rdev_p->entry, &rdev_list);
 
 	PDBG("%s opening rnic dev %s\n", __FUNCTION__, rdev_p->dev_name);
 	memset(&rdev_p->ctrl_qp, 0, sizeof(rdev_p->ctrl_qp));
@@ -1018,7 +996,7 @@ err3:
 err2:
 	cxio_hal_destroy_ctrl_qp(rdev_p);
 err1:
-	cxio_hal_delete_rdev(rdev_p);
+	list_del(&rdev_p->entry);
 	return err;
 }
 
@@ -1027,7 +1005,7 @@ void cxio_rdev_close(struct cxio_rdev *r
 	if (rdev_p) {
 		cxio_hal_pblpool_destroy(rdev_p);
 		cxio_hal_rqtpool_destroy(rdev_p);
-		cxio_hal_delete_rdev(rdev_p);
+		list_del(&rdev_p->entry);
 		rdev_p->t3cdev_p->ulp = NULL;
 		cxio_hal_destroy_ctrl_qp(rdev_p);
 		cxio_hal_destroy_resource(rdev_p->rscp);
@@ -1038,7 +1016,6 @@ int __init cxio_hal_init(void)
 {
 	if (cxio_hal_init_rhdl_resource(T3_MAX_NUM_RI))
 		return -ENOMEM;
-	memset(rdev_tbl, 0, T3_MAX_NUM_RNIC * sizeof(void *));
 	t3_register_cpl_handler(CPL_ASYNC_NOTIF, cxio_hal_ev_handler);
 	return 0;
 }
@@ -1046,9 +1023,11 @@ int __init cxio_hal_init(void)
 void __exit cxio_hal_exit(void)
 {
 	int i;
+	struct cxio_rdev *rdev, *tmp;
+
 	t3_register_cpl_handler(CPL_ASYNC_NOTIF, NULL);
-	for (i = 0; i < T3_MAX_NUM_RNIC; i++)
-		cxio_rdev_close(rdev_tbl[i]);
+	list_for_each_entry_safe(rdev, tmp, &rdev_list, entry)
+		cxio_rdev_close(rdev);
 	cxio_hal_destroy_rhdl_resource();
 }
 
diff --git a/drivers/infiniband/hw/cxgb3/core/cxio_hal.h b/drivers/infiniband/hw/cxgb3/core/cxio_hal.h
index d5ae282..8fb2999 100644
--- a/drivers/infiniband/hw/cxgb3/core/cxio_hal.h
+++ b/drivers/infiniband/hw/cxgb3/core/cxio_hal.h
@@ -47,7 +47,6 @@ #define T3_CTRL_QP_SIZE_LOG2  8
 #define T3_CTRL_CQ_ID    0
 
 /* TBD */
-#define T3_MAX_NUM_RNIC  8
 #define T3_MAX_NUM_RI (1<<15)
 #define T3_MAX_NUM_QP (1<<15)
 #define T3_MAX_NUM_CQ (1<<15)
@@ -106,6 +105,7 @@ struct cxio_rdev {
 	struct cxio_ucontext uctx;
 	struct gen_pool *pbl_pool;
 	struct gen_pool *rqt_pool;
+	struct list_head entry;
 };
 
 static inline int cxio_num_stags(struct cxio_rdev *rdev_p)




More information about the general mailing list