Provide a mechanism to dispatch CM events to a registered client of each
RDMA device.

To avoid reporting QP events to all registered clients, a new CM event
handler was added to each ib_device.

Signed-off-by: Sean Hefty <[EMAIL PROTECTED]>
---
Can one of the iWarp vendors see if this event_handling is generic
enough for their use as well?

Index: include/rdma/ib_verbs.h
===================================================================
--- include/rdma/ib_verbs.h     (revision 8626)
+++ include/rdma/ib_verbs.h     (working copy)
@@ -874,6 +874,7 @@ struct ib_device {
 
        u32                           flags;
 
+       void                       (*cm_handler)(struct ib_event *);
        int                        (*query_device)(struct ib_device *device,
                                                   struct ib_device_attr 
*device_attr);
        int                        (*query_port)(struct ib_device *device,
@@ -1069,6 +1070,11 @@ int ib_register_event_handler  (struct i
 int ib_unregister_event_handler(struct ib_event_handler *event_handler);
 void ib_dispatch_event(struct ib_event *event);
 
+int ib_register_cm_handler(struct ib_device *device,
+                          void (*cm_handler)(struct ib_event *));
+void ib_unregister_cm_handler(struct ib_device *device);
+void ib_dispatch_cm_event(struct ib_event *event);
+
 int ib_query_device(struct ib_device *device,
                    struct ib_device_attr *device_attr);
 
Index: core/device.c
===================================================================
--- core/device.c       (revision 8626)
+++ core/device.c       (working copy)
@@ -478,6 +478,67 @@ void ib_dispatch_event(struct ib_event *
 EXPORT_SYMBOL(ib_dispatch_event);
 
 /**
+ * ib_register_cm_handler - Register a CM event handler
+ * @device:Device to register with
+ * @cm_handler:Handler to register
+ *
+ * ib_register_cm_handler() registers an event handler that will be
+ * called back when asynchronous communication events occurs.
+ * This callback may occur in interrupt context.
+ */
+int ib_register_cm_handler(struct ib_device *device,
+                          void (*cm_handler)(struct ib_event *))
+{
+       unsigned long flags;
+       int ret = 0;
+
+       spin_lock_irqsave(&device->event_handler_lock, flags);
+       if (!device->cm_handler)
+               device->cm_handler = cm_handler;
+       else
+               ret = -EBUSY;
+       spin_unlock_irqrestore(&device->event_handler_lock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL(ib_register_cm_handler);
+
+/**
+ * ib_unregister_cm_handler - Unregister a CM event handler
+ * @cm_handler:Handler to unregister
+ *
+ * Unregister a CM event handler registered with ib_register_cm_handler().
+ */
+void ib_unregister_cm_handler(struct ib_device *device)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&device->event_handler_lock, flags);
+       device->cm_handler = NULL;
+       spin_unlock_irqrestore(&device->event_handler_lock, flags);
+}
+EXPORT_SYMBOL(ib_unregister_cm_handler);
+
+/**
+ * ib_dispatch_cm_event - Dispatch an asynchronous CM event
+ * @event:Event to dispatch
+ *
+ * Low-level drivers must call ib_dispatch_cm_event() to dispatch the
+ * event to any registered CM event handler when an asynchronous
+ * communication event occurs.
+ */
+void ib_dispatch_cm_event(struct ib_event *event)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&event->device->event_handler_lock, flags);
+       if (event->device->cm_handler)
+               event->device->cm_handler(event);
+       spin_unlock_irqrestore(&event->device->event_handler_lock, flags);
+}
+EXPORT_SYMBOL(ib_dispatch_cm_event);
+
+/**
  * ib_query_device - Query IB device attributes
  * @device:Device to query
  * @device_attr:Device attributes


_______________________________________________
openib-general mailing list
[email protected]
http://openib.org/mailman/listinfo/openib-general

To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general

Reply via email to