public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <shemminger@osdl.org>
To: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] iWARP Connection Manager.
Date: Wed, 31 May 2006 11:40:59 -0700	[thread overview]
Message-ID: <20060531114059.704ef1f1@localhost.localdomain> (raw)
In-Reply-To: 20060531182652.3308.1244.stgit@stevo-desktop

On Wed, 31 May 2006 13:26:52 -0500
Steve Wise <swise@opengridcomputing.com> wrote:

> 
> This patch provides the new files implementing the iWARP Connection
> Manager.
> ---
> 
>  drivers/infiniband/core/iwcm.c |  887 ++++++++++++++++++++++++++++++++++++++++
>  include/rdma/iw_cm.h           |  254 +++++++++++
>  include/rdma/iw_cm_private.h   |   62 +++
>  3 files changed, 1203 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c
> new file mode 100644
> index 0000000..5657ee8
> --- /dev/null
> +++ b/drivers/infiniband/core/iwcm.c
> @@ -0,0 +1,887 @@
> +/*
> + * 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.
> + *
> + */

Shouldn't all the EXPORT_SYMBOL's in this new code be EXPORT_SYMBOL_GPL
to impede use of binary vendor module's?


> +#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/iw_cm.h>
> +#include <rdma/iw_cm_private.h>
> +#include <rdma/ib_addr.h>
> +
> +MODULE_AUTHOR("Tom Tucker");
> +MODULE_DESCRIPTION("iWARP CM");
> +MODULE_LICENSE("Dual BSD/GPL");
> +
> +static struct workqueue_struct *iwcm_wq;
> +struct iwcm_work {
> +	struct work_struct work;
> +	struct iwcm_id_private *cm_id;
> +	struct list_head list;
> +	struct iw_cm_event event;
> +};
> +
> +/* 
> + * Release a reference on cm_id. If the last reference is being removed
> + * and iw_destroy_cm_id is waiting, wake up the waiting thread.
> + */
> +static int iwcm_deref_id(struct iwcm_id_private *cm_id_priv)
> +{
> +	int ret = 0;
> +
> +	BUG_ON(atomic_read(&cm_id_priv->refcount)==0);
> +	if (atomic_dec_and_test(&cm_id_priv->refcount)) {
> +		BUG_ON(!list_empty(&cm_id_priv->work_list));
> +		if (waitqueue_active(&cm_id_priv->destroy_wait)) {
> +			BUG_ON(cm_id_priv->state != IW_CM_STATE_DESTROYING);
> +			BUG_ON(test_bit(IWCM_F_CALLBACK_DESTROY,
> +					&cm_id_priv->flags));
> +			ret = 1;
> +			wake_up(&cm_id_priv->destroy_wait);
> +		}
> +	}
> +
> +	return ret;
> +}
> +
> +static void add_ref(struct iw_cm_id *cm_id)
> +{
> +	struct iwcm_id_private *cm_id_priv;
> +	cm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
> +	atomic_inc(&cm_id_priv->refcount);
> +}
> +
> +static void rem_ref(struct iw_cm_id *cm_id)
> +{
> +	struct iwcm_id_private *cm_id_priv;
> +	cm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
> +	iwcm_deref_id(cm_id_priv);
> +}
> +
> +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 *cm_id_priv;
> +
> +	cm_id_priv = kzalloc(sizeof *cm_id_priv, GFP_KERNEL);

Please put paren's after sizeof, it is not required by C but it
is easier to read.

> +
> +/* 
> + * CM_ID <-- CLOSING
> + *
> + * Block if a passive or active connection is currenlty being processed. Then
> + * process the event as follows:
> + * - If we are ESTABLISHED, move to CLOSING and modify the QP state
> + *   based on the abrupt flag 
> + * - If the connection is already in the CLOSING or IDLE state, the peer is
> + *   disconnecting concurrently with us and we've already seen the 
> + *   DISCONNECT event -- ignore the request and return 0
> + * - Disconnect on a listening endpoint returns -EINVAL
> + */
> +int iw_cm_disconnect(struct iw_cm_id *cm_id, int abrupt)
> +{
> +	struct iwcm_id_private *cm_id_priv;
> +	unsigned long flags;
> +	int ret = 0;
> +
> +	cm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
> +	/* Wait if we're currently in a connect or accept downcall */
> +	wait_event(cm_id_priv->connect_wait, 
> +		   !test_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags));
> +
> +	spin_lock_irqsave(&cm_id_priv->lock, flags);
> +	switch (cm_id_priv->state) {
> +	case IW_CM_STATE_ESTABLISHED:
> +		cm_id_priv->state = IW_CM_STATE_CLOSING;
> +		spin_unlock_irqrestore(&cm_id_priv->lock, flags);
> +		if (cm_id_priv->qp)	{ /* QP could be <nul> for user-mode client */
> +			if (abrupt)
> +				ret = iwcm_modify_qp_err(cm_id_priv->qp);
> +			else
> +				ret = iwcm_modify_qp_sqd(cm_id_priv->qp);
> +			/* 
> +			 * If both sides are disconnecting the QP could
> +			 * already be in ERR or SQD states
> +			 */
> +			ret = 0;
> +		}
> +		else
> +			ret = -EINVAL;
> +		break;
> +	case IW_CM_STATE_LISTEN:
> +		spin_unlock_irqrestore(&cm_id_priv->lock, flags);
> +		ret = -EINVAL;
> +		break;
> +	case IW_CM_STATE_CLOSING:
> +		/* remote peer closed first */
> +	case IW_CM_STATE_IDLE:	
> +		/* accept or connect returned !0 */
> +		spin_unlock_irqrestore(&cm_id_priv->lock, flags);
> +		break;
> +	case IW_CM_STATE_CONN_RECV:
> +		/* 
> +		 * App called disconnect before/without calling accept after
> +		 * connect_request event delivered.
> +		 */
> +		spin_unlock_irqrestore(&cm_id_priv->lock, flags);
> +		break;
> +	case IW_CM_STATE_CONN_SENT:
> +		/* Can only get here if wait above fails */
> +	default:		
> +		BUG_ON(1);
> +	}

Switch statement's like this where the case does the unlock are error prone
because of the many code paths.

If you just recode slightly by using a separate return in the ESTABLISHED
case, then you can move the unlock outside of the switch.


  reply	other threads:[~2006-05-31 18:41 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-31 18:26 [PATCH 0/2][RFC] iWARP Core Support Steve Wise
2006-05-31 18:26 ` [PATCH 1/2] iWARP Connection Manager Steve Wise
2006-05-31 18:40   ` Stephen Hemminger [this message]
2006-05-31 19:24     ` Roland Dreier
2006-05-31 20:47       ` Muli Ben-Yehuda
2006-05-31 20:58       ` Steve Wise
2006-05-31 21:01         ` Stephen Hemminger
2006-05-31 21:54           ` Roland Dreier
2006-05-31 22:22             ` Steve Wise
2006-05-31 22:22   ` Sean Hefty
2006-06-01 17:00     ` Steve Wise
2006-06-01 21:09       ` Sean Hefty
2006-06-01 22:21         ` [openib-general] " Tom Tucker
2006-06-01 17:11     ` Tom Tucker
2006-05-31 18:26 ` [PATCH 2/2] iWARP Core Changes Steve Wise
2006-05-31 18:36   ` Stephen Hemminger
2006-05-31 19:17   ` Roland Dreier
2006-05-31 20:30     ` Steve Wise
2006-05-31 20:32       ` Roland Dreier
2006-05-31 21:26   ` Sean Hefty

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060531114059.704ef1f1@localhost.localdomain \
    --to=shemminger@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox