[openib-general] [PATCH] [CM] add OS administered service IDs

Sean Hefty sean.hefty at intel.com
Tue Jun 7 10:50:14 PDT 2005


The following patch adds support for OS administered service IDs.

Signed-off-by: Sean Hefty <sean.hefty at intel.com>


Index: include/ib_cm.h
===================================================================
--- include/ib_cm.h	(revision 2563)
+++ include/ib_cm.h	(working copy)
@@ -311,16 +311,20 @@ struct ib_cm_id *ib_create_cm_id(ib_cm_h
  */
 void ib_destroy_cm_id(struct ib_cm_id *cm_id);
 
+#define IB_CM_ASSIGN_SERVICE_ID  __constant_cpu_to_be64(0x0200000000000000ULL)
+
 /**
  * ib_cm_listen - Initiates listening on the specified service ID for
  *   connection and service ID resolution requests.
  * @cm_id: Connection identifier associated with the listen request.
  * @service_id: Service identifier matched against incoming connection
  *   and service ID resolution requests.  The service ID should be specified
- *   network-byte order.
+ *   network-byte order.  If set to IB_CM_ASSIGN_SERVICE_ID, the CM will
+ *   assign a service ID to the caller.
  * @service_mask: Mask applied to service ID used to listen across a
  *   range of service IDs.  If set to 0, the service ID is matched
- *   exactly.
+ *   exactly.  This parameter is ignored if %service_id is set to
+ *   IB_CM_ASSIGN_SERVICE_ID.
  */
 int ib_cm_listen(struct ib_cm_id *cm_id,
 		 u64 service_id,
Index: core/cm.c
===================================================================
--- core/cm.c	(revision 2563)
+++ core/cm.c	(working copy)
@@ -64,6 +64,7 @@ static struct ib_cm {
 	struct list_head device_list;
 	rwlock_t device_lock;
 	struct rb_root listen_service_table;
+	u64 listen_service_id;
 	/* struct rb_root peer_service_table; todo: fix peer to peer */
 	struct rb_root remote_qp_table;
 	struct rb_root remote_id_table;
@@ -718,14 +719,23 @@ int ib_cm_listen(struct ib_cm_id *cm_id,
 	unsigned long flags;
 	int ret = 0;
 
+	if ((service_id & IB_CM_ASSIGN_SERVICE_ID) == IB_CM_ASSIGN_SERVICE_ID &&
+	    (service_id != IB_CM_ASSIGN_SERVICE_ID))
+		return -EINVAL;
+
 	cm_id_priv = container_of(cm_id, struct cm_id_private, id);
 	BUG_ON(cm_id->state != IB_CM_IDLE);
 
 	cm_id->state = IB_CM_LISTEN;
-	cm_id->service_id = service_id;
-	cm_id->service_mask = service_mask ? service_mask : ~0ULL;
 
 	spin_lock_irqsave(&cm.lock, flags);
+	if (service_id == IB_CM_ASSIGN_SERVICE_ID) {
+		cm_id->service_id = __cpu_to_be64(cm.listen_service_id++);
+		cm_id->service_mask = ~0ULL;
+	} else {
+		cm_id->service_id = service_id;
+		cm_id->service_mask = service_mask ? service_mask : ~0ULL;
+	}
 	cur_cm_id_priv = cm_insert_listen(cm_id_priv);
 	spin_unlock_irqrestore(&cm.lock, flags);
 
@@ -3251,6 +3261,7 @@ static int __init ib_cm_init(void)
 	rwlock_init(&cm.device_lock);
 	spin_lock_init(&cm.lock);
 	cm.listen_service_table = RB_ROOT;
+	cm.listen_service_id = __constant_be64_to_cpu(IB_CM_ASSIGN_SERVICE_ID);
 	cm.remote_id_table = RB_ROOT;
 	cm.remote_qp_table = RB_ROOT;
 	cm.remote_sidr_table = RB_ROOT;






More information about the general mailing list