[openib-general] [PATCH 3/3] iWARP CM
Tom Tucker
tom at opengridcomputing.com
Wed Mar 8 07:56:30 PST 2006
This patch provides the implementation of the iWARP CM:
core/Makefile
core/iwcm.c
Signed-off-by: Tom Tucker <tom at opengridcomputing.com>
Index: Makefile
===================================================================
--- Makefile (revision 5632)
+++ Makefile (working copy)
@@ -1,8 +1,9 @@
EXTRA_CFLAGS += -Idrivers/infiniband/include -Idrivers/infiniband/ulp/ipoib
-obj-$(CONFIG_INFINIBAND) += ib_core.o ib_mad.o ib_ping.o ib_cm.o \
+obj-$(CONFIG_INFINIBAND) += ib_core.o ib_mad.o ib_ping.o \
+ ib_cm.o iw_cm.o \
ib_sa.o ib_at.o ib_addr.o rdma_cm.o \
- ib_local_sa.o findex.o
+ ib_local_sa.o findex.o
obj-$(CONFIG_INFINIBAND_USER_MAD) += ib_umad.o
obj-$(CONFIG_INFINIBAND_USER_ACCESS) += ib_uverbs.o ib_ucm.o ib_uat.o rdma_ucm.o
@@ -17,6 +18,8 @@
ib_cm-y := cm.o
+iw_cm-y := iwcm.o
+
rdma_cm-y := cma.o
rdma_ucm-y := ucma.o
Index: iwcm.c
===================================================================
--- iwcm.c (revision 0)
+++ iwcm.c (revision 0)
@@ -0,0 +1,722 @@
+/*
+ * Copyright (c) 2004, 2005 Intel Corporation. All rights reserved.
+ * Copyright (c) 2004 Topspin Corporation. All rights reserved.
+ * Copyright (c) 2004, 2005 Voltaire Corporation. All rights reserved.
+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.
+ * Copyright (c) 2005 Network Appliance, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses. You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+#include <linux/dma-mapping.h>
+#include <linux/err.h>
+#include <linux/idr.h>
+#include <linux/interrupt.h>
+#include <linux/pci.h>
+#include <linux/rbtree.h>
+#include <linux/spinlock.h>
+#include <linux/workqueue.h>
+
+#include <rdma/ib_cache.h>
+#include <rdma/ib_cm.h>
+#include <rdma/iw_cm.h>
+
+#include "cm_msgs.h"
+
+MODULE_AUTHOR("Tom Tucker");
+MODULE_DESCRIPTION("iWARP CM");
+MODULE_LICENSE("Dual BSD/GPL");
+
+static void iwcm_add_one(struct ib_device *device);
+static void iwcm_remove_one(struct ib_device *device);
+struct iwcm_id_private;
+
+static struct ib_client iwcm_client = {
+ .name = "iwcm",
+ .add = iwcm_add_one,
+ .remove = iwcm_remove_one
+};
+
+static struct {
+ spinlock_t lock;
+ struct list_head device_list;
+ rwlock_t device_lock;
+ struct workqueue_struct *wq;
+} iwcm;
+
+struct iwcm_device;
+struct iwcm_port {
+ struct iwcm_device *iwcm_dev;
+ struct sockaddr_in local_addr;
+ u8 port_num;
+};
+
+struct iwcm_device {
+ struct list_head list;
+ struct ib_device *device;
+ struct iwcm_port port[0];
+};
+
+struct iwcm_id_private {
+ struct iw_cm_id id;
+
+ spinlock_t lock;
+ wait_queue_head_t wait;
+ atomic_t refcount;
+};
+
+struct iwcm_work {
+ struct work_struct work;
+ struct iwcm_id_private *cm_id;
+ struct iw_cm_event event;
+};
+
+/* Called whenever a reference added for a cm_id */
+static inline void iwcm_addref_id(struct iwcm_id_private *cm_id_priv)
+{
+ atomic_inc(&cm_id_priv->refcount);
+}
+
+/* Called whenever releasing a reference to a cm id */
+static inline void iwcm_deref_id(struct iwcm_id_private *cm_id_priv)
+{
+ if (atomic_dec_and_test(&cm_id_priv->refcount))
+ wake_up(&cm_id_priv->wait);
+}
+
+static void cm_event_handler(struct iw_cm_id *cm_id, struct iw_cm_event *event);
+
+struct iw_cm_id *iw_create_cm_id(struct ib_device *device,
+ iw_cm_handler cm_handler,
+ void *context)
+{
+ struct iwcm_id_private *iwcm_id_priv;
+
+ iwcm_id_priv = kmalloc(sizeof *iwcm_id_priv, GFP_KERNEL);
+ if (!iwcm_id_priv)
+ return ERR_PTR(-ENOMEM);
+
+ memset(iwcm_id_priv, 0, sizeof *iwcm_id_priv);
+ iwcm_id_priv->id.state = IW_CM_STATE_IDLE;
+ iwcm_id_priv->id.device = device;
+ iwcm_id_priv->id.cm_handler = cm_handler;
+ iwcm_id_priv->id.context = context;
+ iwcm_id_priv->id.event_handler = cm_event_handler;
+
+ spin_lock_init(&iwcm_id_priv->lock);
+ init_waitqueue_head(&iwcm_id_priv->wait);
+ atomic_set(&iwcm_id_priv->refcount, 1);
+
+ return &iwcm_id_priv->id;
+
+}
+EXPORT_SYMBOL(iw_create_cm_id);
+
+void iw_destroy_cm_id(struct iw_cm_id *cm_id)
+{
+ struct iwcm_id_private *iwcm_id_priv;
+ unsigned long flags;
+ int ret = 0;
+
+ iwcm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
+
+ spin_lock_irqsave(&iwcm_id_priv->lock, flags);
+ switch (cm_id->state) {
+ case IW_CM_STATE_LISTEN:
+ cm_id->state = IW_CM_STATE_IDLE;
+ spin_unlock_irqrestore(&iwcm_id_priv->lock, flags);
+ ret = cm_id->device->iwcm->destroy_listen(cm_id);
+ break;
+
+ case IW_CM_STATE_CONN_RECV:
+ case IW_CM_STATE_CONN_SENT:
+ case IW_CM_STATE_ESTABLISHED:
+ cm_id->state = IW_CM_STATE_IDLE;
+ spin_unlock_irqrestore(&iwcm_id_priv->lock, flags);
+ ret = cm_id->device->iwcm->disconnect(cm_id,1);
+ break;
+
+ case IW_CM_STATE_IDLE:
+ spin_unlock_irqrestore(&iwcm_id_priv->lock, flags);
+ break;
+
+ default:
+ spin_unlock_irqrestore(&iwcm_id_priv->lock, flags);
+ printk(KERN_ERR "%s:%s:%u Illegal state %d for iw_cm_id.\n",
+ __FILE__, __FUNCTION__, __LINE__, cm_id->state);
+ ;
+ }
+
+ atomic_dec(&iwcm_id_priv->refcount);
+ wait_event(iwcm_id_priv->wait, !atomic_read(&iwcm_id_priv->refcount));
+
+ kfree(iwcm_id_priv);
+}
+EXPORT_SYMBOL(iw_destroy_cm_id);
+
+int iw_cm_listen(struct iw_cm_id *cm_id, int backlog)
+{
+ struct iwcm_id_private *iwcm_id_priv;
+ unsigned long flags;
+ int ret = 0;
+
+ if (cm_id->device == 0 || cm_id->device->iwcm == 0)
+ return -EINVAL;
+
+ iwcm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
+ spin_lock_irqsave(&iwcm_id_priv->lock, flags);
+ if (cm_id->state != IW_CM_STATE_IDLE) {
+ spin_unlock_irqrestore(&iwcm_id_priv->lock, flags);
+ return -EBUSY;
+ }
+ cm_id->state = IW_CM_STATE_LISTEN;
+ spin_unlock_irqrestore(&iwcm_id_priv->lock, flags);
+
+ ret = cm_id->device->iwcm->create_listen(cm_id, backlog);
+ if (ret != 0)
+ cm_id->state = IW_CM_STATE_IDLE;
+
+ return ret;
+}
+EXPORT_SYMBOL(iw_cm_listen);
+
+int iw_cm_getpeername(struct iw_cm_id *cm_id,
+ struct sockaddr_in* local_addr,
+ struct sockaddr_in* remote_addr)
+{
+ if (cm_id->device == 0)
+ return -EINVAL;
+
+ if (cm_id->device->iwcm == 0)
+ return -EINVAL;
+
+ /* Make sure there's a connection */
+ if (cm_id->state != IW_CM_STATE_ESTABLISHED)
+ return -ENOTCONN;
+
+ return cm_id->device->iwcm->getpeername(cm_id, local_addr, remote_addr);
+}
+EXPORT_SYMBOL(iw_cm_getpeername);
+
+int iw_cm_reject(struct iw_cm_id *cm_id,
+ const void *private_data,
+ u8 private_data_len)
+{
+ struct iwcm_id_private *iwcm_id_priv;
+ unsigned long flags;
+ int ret;
+
+ if (cm_id->device == 0 || cm_id->device->iwcm == 0)
+ return -EINVAL;
+
+ iwcm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
+
+ spin_lock_irqsave(&iwcm_id_priv->lock, flags);
+ switch (cm_id->state) {
+ case IW_CM_STATE_CONN_RECV:
+ spin_unlock_irqrestore(&iwcm_id_priv->lock, flags);
+ ret = cm_id->device->iwcm->reject(cm_id, private_data,
+ private_data_len);
+ cm_id->state = IW_CM_STATE_IDLE;
+ break;
+ default:
+ spin_unlock_irqrestore(&iwcm_id_priv->lock, flags);
+ ret = -EINVAL;
+ }
+
+ return ret;
+}
+EXPORT_SYMBOL(iw_cm_reject);
+
+int iw_cm_accept(struct iw_cm_id *cm_id,
+ const void *private_data,
+ u8 private_data_len)
+{
+ struct iwcm_id_private *iwcm_id_priv;
+ unsigned long flags;
+ int ret;
+
+ if (cm_id->device == 0 || cm_id->device->iwcm == 0)
+ return -EINVAL;
+
+ iwcm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
+
+ spin_lock_irqsave(&iwcm_id_priv->lock, flags);
+ switch (cm_id->state) {
+ case IW_CM_STATE_CONN_RECV:
+ spin_unlock_irqrestore(&iwcm_id_priv->lock, flags);
+ ret = cm_id->device->iwcm->accept(cm_id, private_data,
+ private_data_len);
+ if (ret == 0) {
+ struct iw_cm_event event;
+ event.event = IW_CM_EVENT_ESTABLISHED;
+ event.provider_id = cm_id->provider_id;
+ event.status = 0;
+ event.local_addr = cm_id->local_addr;
+ event.remote_addr = cm_id->remote_addr;
+ event.private_data = 0;
+ event.private_data_len = 0;
+ cm_event_handler(cm_id, &event);
+ }
+
+ break;
+ default:
+ spin_unlock_irqrestore(&iwcm_id_priv->lock, flags);
+ ret = -EINVAL;
+ }
+
+ return ret;
+}
+EXPORT_SYMBOL(iw_cm_accept);
+
+int iw_cm_connect(struct iw_cm_id *cm_id,
+ const void *pdata,
+ u8 pdata_len)
+{
+ struct iwcm_id_private *cm_id_priv;
+ int ret = 0;
+ unsigned long flags;
+
+ if (cm_id->device == 0 || cm_id->device->iwcm == 0)
+ return -EINVAL;
+
+ cm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
+ spin_lock_irqsave(&cm_id_priv->lock, flags);
+ if (cm_id->state != IW_CM_STATE_IDLE) {
+ spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+ return -EBUSY;
+ }
+ cm_id->state = IW_CM_STATE_CONN_SENT;
+ spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+
+ ret = cm_id->device->iwcm->connect(cm_id, pdata, pdata_len);
+ if (ret != 0)
+ cm_id->state = IW_CM_STATE_IDLE;
+
+ return ret;
+}
+EXPORT_SYMBOL(iw_cm_connect);
+
+int iw_cm_disconnect(struct iw_cm_id *cm_id)
+{
+ struct iwcm_id_private *iwcm_id_priv;
+ unsigned long flags;
+ int ret;
+
+ if (cm_id->device == 0 || cm_id->device->iwcm == 0 || cm_id->qp == 0)
+ return -EINVAL;
+
+ iwcm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
+ spin_lock_irqsave(&iwcm_id_priv->lock, flags);
+ switch (cm_id->state) {
+ case IW_CM_STATE_ESTABLISHED:
+ cm_id->state = IW_CM_STATE_CLOSING;
+ spin_unlock_irqrestore(&iwcm_id_priv->lock, flags);
+ ret = cm_id->device->iwcm->disconnect(cm_id, 1);
+ if (ret == 0) {
+ struct iw_cm_event event;
+ event.event = IW_CM_EVENT_LLP_DISCONNECT;
+ event.provider_id = cm_id->provider_id;
+ event.status = 0;
+ event.local_addr = cm_id->local_addr;
+ event.remote_addr = cm_id->remote_addr;
+ event.private_data = 0;
+ event.private_data_len = 0;
+ cm_event_handler(cm_id, &event);
+ }
+ cm_id->state = IW_CM_STATE_IDLE;
+ break;
+ default:
+ spin_unlock_irqrestore(&iwcm_id_priv->lock, flags);
+ ret = -EINVAL;
+ }
+
+ return ret;
+}
+EXPORT_SYMBOL(iw_cm_disconnect);
+
+static void iwcm_add_one(struct ib_device *device)
+{
+ struct iwcm_device *iwcm_dev;
+ struct iwcm_port *port;
+ unsigned long flags;
+ u8 i;
+
+ if (rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IWARP)
+ return;
+
+ iwcm_dev = kmalloc(sizeof(*iwcm_dev) + sizeof(*port) *
+ device->phys_port_cnt, GFP_KERNEL);
+ if (!iwcm_dev)
+ return;
+
+ iwcm_dev->device = device;
+
+ for (i = 1; i <= device->phys_port_cnt; i++) {
+ port = &iwcm_dev->port[i-1];
+ port->iwcm_dev = iwcm_dev;
+ port->port_num = i;
+ }
+
+ ib_set_client_data(device, &iwcm_client, iwcm_dev);
+
+ write_lock_irqsave(&iwcm.device_lock, flags);
+ list_add_tail(&iwcm_dev->list, &iwcm.device_list);
+ write_unlock_irqrestore(&iwcm.device_lock, flags);
+ return;
+}
+
+static void iwcm_remove_one(struct ib_device *device)
+{
+ struct iwcm_device *iwcm_dev;
+ unsigned long flags;
+
+ iwcm_dev = ib_get_client_data(device, &iwcm_client);
+ if (!iwcm_dev)
+ return;
+
+ write_lock_irqsave(&iwcm.device_lock, flags);
+ list_del(&iwcm_dev->list);
+ write_unlock_irqrestore(&iwcm.device_lock, flags);
+
+ kfree(iwcm_dev);
+}
+
+/* Handles an inbound connect request. The function creates a new
+ * iw_cm_id to represent the new connection and inherits the client
+ * callback function and other attributes from the listening parent.
+ *
+ * The work item contains a pointer to the listen_cm_id and the event. The
+ * listen_cm_id contains the client cm_handler, context and device. These are
+ * copied when the device is cloned. The event contains the new four tuple.
+ */
+static int cm_conn_req_handler(struct iwcm_work *work)
+{
+ struct iw_cm_id *cm_id;
+ struct iwcm_id_private *cm_id_priv;
+ int rc;
+
+ /* If the status was not successful, ignore request */
+ if (work->event.status) {
+ printk(KERN_ERR "%s:%d Bad status=%d for connection request. "
+ "Should be filtered by provider\n",
+ __FUNCTION__, __LINE__,
+ work->event.status);
+ return work->event.status;
+ }
+ cm_id = iw_create_cm_id(work->cm_id->id.device,
+ work->cm_id->id.cm_handler,
+ work->cm_id->id.context);
+ if (IS_ERR(cm_id))
+ return PTR_ERR(cm_id);
+
+ cm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
+ cm_id_priv->id.local_addr = work->event.local_addr;
+ cm_id_priv->id.remote_addr = work->event.remote_addr;
+ cm_id_priv->id.provider_id = work->event.provider_id;
+ cm_id_priv->id.state = IW_CM_STATE_CONN_RECV;
+
+ /* Call the client CM handler */
+ iwcm_addref_id(cm_id_priv);
+ rc = cm_id->cm_handler(cm_id, &work->event);
+ iwcm_deref_id(cm_id_priv);
+ if (rc) {
+ cm_id->state = IW_CM_STATE_IDLE;
+ iw_destroy_cm_id(cm_id);
+ }
+ kfree(work);
+ return 0;
+}
+
+/*
+ * Handles the transition to established state on the passive side.
+ */
+static int cm_conn_est_handler(struct iwcm_work *work)
+{
+ struct iwcm_id_private *cm_id_priv;
+ unsigned long flags;
+ int ret = 0;
+
+ cm_id_priv = work->cm_id;
+ spin_lock_irqsave(&cm_id_priv->lock, flags);
+ if (cm_id_priv->id.state != IW_CM_STATE_CONN_RECV) {
+ spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+ printk(KERN_ERR "%s:%d Invalid cm_id state=%d "
+ "for established event\n", __FUNCTION__, __LINE__,
+ cm_id_priv->id.state);
+ ret = -EINVAL;
+ goto error_out;
+ }
+
+ if (work->event.status == 0) {
+ cm_id_priv = work->cm_id;
+ cm_id_priv->id.local_addr = work->event.local_addr;
+ cm_id_priv->id.remote_addr = work->event.remote_addr;
+ cm_id_priv->id.state = IW_CM_STATE_ESTABLISHED;
+ } else
+ cm_id_priv->id.state = IW_CM_STATE_IDLE;
+
+ spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+
+ /* Call the client CM handler */
+ ret = cm_id_priv->id.cm_handler(&cm_id_priv->id, &work->event);
+ if (ret) {
+ cm_id_priv->id.state = IW_CM_STATE_IDLE;
+ iw_destroy_cm_id(&cm_id_priv->id);
+ }
+
+ error_out:
+ kfree(work);
+ return ret;
+}
+
+/*
+ * Handles the reply to our connect request. There are three
+ * possibilities:
+ * - If the cm_id is in the wrong state when the event is
+ * delivered, the event is ignored. [What should we do when the
+ * provider does something crazy?]
+ * - If the remote peer accepts the connection, we update the 4-tuple
+ * in the cm_id with the remote peer info, move the cm_id to the
+ * ESTABLISHED state and deliver the event to the client.
+ * - If the remote peer rejects the connection, or there is some
+ * connection error, move the cm_id to the IDLE state, and deliver
+ * the event to the client.
+ */
+static int cm_conn_rep_handler(struct iwcm_work *work)
+{
+ struct iwcm_id_private *cm_id_priv;
+ unsigned long flags;
+ int ret = 0;
+
+ cm_id_priv = work->cm_id;
+ spin_lock_irqsave(&cm_id_priv->lock, flags);
+ if (cm_id_priv->id.state != IW_CM_STATE_CONN_SENT) {
+ spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+ printk(KERN_ERR "%s:%d Invalid cm_id state=%d "
+ "for connect reply event\n", __FUNCTION__, __LINE__,
+ cm_id_priv->id.state);
+ ret = -EINVAL;
+ goto error_out;
+ }
+
+ if (work->event.status == 0) {
+ cm_id_priv = work->cm_id;
+ cm_id_priv->id.local_addr = work->event.local_addr;
+ cm_id_priv->id.remote_addr = work->event.remote_addr;
+ cm_id_priv->id.state = IW_CM_STATE_ESTABLISHED;
+ } else
+ cm_id_priv->id.state = IW_CM_STATE_IDLE;
+
+ spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+
+ /* Call the client CM handler */
+ ret = cm_id_priv->id.cm_handler(&cm_id_priv->id, &work->event);
+ if (ret) {
+ cm_id_priv->id.state = IW_CM_STATE_IDLE;
+ iw_destroy_cm_id(&cm_id_priv->id);
+ }
+
+ error_out:
+ kfree(work);
+ return ret;
+}
+
+static int cm_disconnect_handler(struct iwcm_work *work)
+{
+ struct iwcm_id_private *cm_id_priv;
+ int ret = 0;
+
+ cm_id_priv = work->cm_id;
+
+ cm_id_priv->id.state = IW_CM_STATE_IDLE;
+
+ /* Call the client CM handler */
+ ret = cm_id_priv->id.cm_handler(&cm_id_priv->id, &work->event);
+ if (ret)
+ iw_destroy_cm_id(&cm_id_priv->id);
+
+ kfree(work);
+ return ret;
+}
+
+static void cm_work_handler(void *arg)
+{
+ struct iwcm_work *work = (struct iwcm_work*)arg;
+ struct iwcm_id_private *cm_id_priv = work->cm_id;
+ int rc;
+
+ switch (work->event.event) {
+ case IW_CM_EVENT_CONNECT_REQUEST:
+ rc = cm_conn_req_handler(work);
+ break;
+ case IW_CM_EVENT_CONNECT_REPLY:
+ rc = cm_conn_rep_handler(work);
+ break;
+ case IW_CM_EVENT_ESTABLISHED:
+ rc = cm_conn_est_handler(work);
+ break;
+ case IW_CM_EVENT_LLP_DISCONNECT:
+ case IW_CM_EVENT_LLP_TIMEOUT:
+ case IW_CM_EVENT_LLP_RESET:
+ case IW_CM_EVENT_CLOSE:
+ rc = cm_disconnect_handler(work);
+ break;
+ }
+
+ /* The reference was done in cm_event_handler. */
+ iwcm_deref_id(cm_id_priv);
+}
+
+/* IW CM provider event callback handler. This function is called on
+ * interrupt context. The function builds a work queue element
+ * and enqueues it for processing on a work queue thread. This allows
+ * CM client callback functions to block.
+ */
+static void cm_event_handler(struct iw_cm_id *cm_id,
+ struct iw_cm_event *event)
+{
+ struct iwcm_work *work;
+ struct iwcm_id_private *cm_id_priv;
+
+ work = kmalloc(sizeof *work, GFP_ATOMIC);
+ if (!work)
+ return;
+
+ cm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
+
+ /*
+ * Reference cm_id_priv until the work is completed in
+ * cm_work_handler.
+ */
+ iwcm_addref_id(cm_id_priv);
+ INIT_WORK(&work->work, cm_work_handler, work);
+ work->cm_id = cm_id_priv;
+ work->event = *event;
+ queue_work(iwcm.wq, &work->work);
+}
+
+static int iwcm_init_qp_init_attr(struct iwcm_id_private *cm_id_priv,
+ struct ib_qp_attr *qp_attr,
+ int *qp_attr_mask)
+{
+ unsigned long flags;
+ int ret;
+
+ spin_lock_irqsave(&cm_id_priv->lock, flags);
+ switch (cm_id_priv->id.state) {
+ case IW_CM_STATE_IDLE:
+ case IW_CM_STATE_CONN_SENT:
+ case IW_CM_STATE_CONN_RECV:
+ case IW_CM_STATE_ESTABLISHED:
+ *qp_attr_mask = IB_QP_STATE | IB_QP_ACCESS_FLAGS;
+ qp_attr->qp_access_flags = IB_ACCESS_LOCAL_WRITE |
+ IB_ACCESS_REMOTE_WRITE|
+ IB_ACCESS_REMOTE_READ;
+ ret = 0;
+ break;
+ default:
+ ret = -EINVAL;
+ break;
+ }
+ spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+ return ret;
+}
+
+static int iwcm_init_qp_rts_attr(struct iwcm_id_private *cm_id_priv,
+ struct ib_qp_attr *qp_attr,
+ int *qp_attr_mask)
+{
+ unsigned long flags;
+ int ret;
+
+ spin_lock_irqsave(&cm_id_priv->lock, flags);
+ switch (cm_id_priv->id.state) {
+ case IW_CM_STATE_IDLE:
+ case IW_CM_STATE_CONN_SENT:
+ case IW_CM_STATE_CONN_RECV:
+ case IW_CM_STATE_ESTABLISHED:
+ *qp_attr_mask = IB_QP_STATE;
+ ret = 0;
+ break;
+ default:
+ ret = -EINVAL;
+ break;
+ }
+ spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+ return ret;
+}
+
+int iw_cm_init_qp_attr(struct iw_cm_id *cm_id,
+ struct ib_qp_attr *qp_attr,
+ int *qp_attr_mask)
+{
+ struct iwcm_id_private *cm_id_priv;
+ int ret;
+
+ cm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
+ switch (qp_attr->qp_state) {
+ case IB_QPS_INIT:
+ case IB_QPS_RTR:
+ ret = iwcm_init_qp_init_attr(cm_id_priv,
+ qp_attr, qp_attr_mask);
+ break;
+ case IB_QPS_RTS:
+ ret = iwcm_init_qp_rts_attr(cm_id_priv,
+ qp_attr, qp_attr_mask);
+ break;
+ default:
+ ret = -EINVAL;
+ break;
+ }
+ return ret;
+}
+EXPORT_SYMBOL(iw_cm_init_qp_attr);
+
+static int __init iw_cm_init(void)
+{
+ memset(&iwcm, 0, sizeof iwcm);
+ INIT_LIST_HEAD(&iwcm.device_list);
+ rwlock_init(&iwcm.device_lock);
+ spin_lock_init(&iwcm.lock);
+ iwcm.wq = create_workqueue("iw_cm");
+ if (!iwcm.wq)
+ return -ENOMEM;
+
+ return ib_register_client(&iwcm_client);
+}
+
+static void __exit iw_cm_cleanup(void)
+{
+ ib_unregister_client(&iwcm_client);
+}
+
+module_init(iw_cm_init);
+module_exit(iw_cm_cleanup);
More information about the general
mailing list