iWARP Core Support
cover iWARP Core Support
This patchset defines the modifications to the Linux infiniband subsystem to support iWARP devices. We're submitting it for review now with the goal for inclusion in the 2.6.19 kernel. This code has gone through several reviews in the openib-general list. Now we are submitting it for external review by the linux community.
This StGIT patchset is cloned from Roland Dreier's infiniband.git for-2.6.18 branch. The patchset consists of 2 patches:
1 - New iWARP CM implementation.
2 - Core changes to support iWARP.
PATCH 1/2 iWARP Connection Manager.
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(-)
drivers/infiniband/core/iwcm.c new file +887 -0
@@ -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. +* +*/ +#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 ); +if (!cm_id_priv) +return ERR_PTR (-ENOMEM ); + + cm_id_priv->state =IW_CM_STATE_IDLE ; + cm_id_priv->id.device = device; + cm_id_priv->id.cm_handler = cm_handler; + cm_id_priv->id.context = context; + cm_id_priv->id.event_handler = cm_event_handler; + cm_id_priv->id.add_ref = add_ref; + cm_id_priv->id.rem_ref = rem_ref; +spin_lock_init (&cm_id_priv->lock); +atomic_set (&cm_id_priv->refcount,1 ); +init_waitqueue_head (&cm_id_priv->connect_wait); +init_waitqueue_head (&cm_id_priv->destroy_wait); +INIT_LIST_HEAD (&cm_id_priv->work_list); + +return &cm_id_priv->id; +} +EXPORT_SYMBOL (iw_create_cm_id); + + +static int iwcm_modify_qp_err (struct ib_qp *qp) +{ +struct ib_qp_attr qp_attr; + +if (!qp) +return -EINVAL ; + + qp_attr.qp_state =IB_QPS_ERR ; +return ib_modify_qp (qp, &qp_attr,IB_QP_STATE ); +} + +/* +* This is really the RDMAC CLOSING state. It is most similar to the +* IB SQD QP state. +*/ +static int iwcm_modify_qp_sqd (struct ib_qp *qp) +{ +struct ib_qp_attr qp_attr; + +BUG_ON (qp ==NULL ); + qp_attr.qp_state =IB_QPS_SQD ; +return ib_modify_qp (qp, &qp_attr,IB_QP_STATE ); +} + +/* +* 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 ); + } + +return ret; +} +EXPORT_SYMBOL (iw_cm_disconnect); + +/* +* CM_ID <-- DESTROYING +* +* Clean up all resources associated with the connection and release +* the initial reference taken by iw_create_cm_id. +*/ +static void destroy_cm_id (struct iw_cm_id *cm_id) +{ +struct iwcm_id_private *cm_id_priv; +unsigned long flags; +int ret; + + cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); +/* Wait if we're currently in a connect or accept downcall. A +* listening endpoint should never block here. */ +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_LISTEN : + cm_id_priv->state =IW_CM_STATE_DESTROYING ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +/* destroy the listening endpoint */ + ret = cm_id->device->iwcm->destroy_listen (cm_id); +break ; +case IW_CM_STATE_ESTABLISHED : + cm_id_priv->state =IW_CM_STATE_DESTROYING ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +/* Abrupt close of the connection */ + (void )iwcm_modify_qp_err (cm_id_priv->qp); +break ; +case IW_CM_STATE_IDLE : +case IW_CM_STATE_CLOSING : + cm_id_priv->state =IW_CM_STATE_DESTROYING ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +break ; +case IW_CM_STATE_CONN_RECV : +/* +* App called destroy before/without calling accept after +* receiving connection request event notification. +*/ + cm_id_priv->state =IW_CM_STATE_DESTROYING ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +break ; +case IW_CM_STATE_CONN_SENT : +case IW_CM_STATE_DESTROYING : +default : +BUG_ON (1 ); +break ; + } + +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->qp) { + cm_id_priv->id.device->iwcm->rem_ref (cm_id_priv->qp); + cm_id_priv->qp =NULL ; + } +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + + (void )iwcm_deref_id (cm_id_priv); +} + +/* +* This function is only called by the application thread and cannot +* be called by the event thread. The function will wait for all +* references to be released on the cm_id and then kfree the cm_id +* object. +*/ +void iw_destroy_cm_id (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); +BUG_ON (test_bit (IWCM_F_CALLBACK_DESTROY , &cm_id_priv->flags)); + +destroy_cm_id (cm_id); + +wait_event (cm_id_priv->destroy_wait, + !atomic_read (&cm_id_priv->refcount)); + +kfree (cm_id_priv); +} +EXPORT_SYMBOL (iw_destroy_cm_id); + +/* +* CM_ID <-- LISTEN +* +* Start listening for connect requests. Generates one CONNECT_REQUEST +* event for each inbound connect request. +*/ +int iw_cm_listen (struct iw_cm_id *cm_id,int backlog) +{ +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); +spin_lock_irqsave (&cm_id_priv->lock, flags); +switch (cm_id_priv->state) { +case IW_CM_STATE_IDLE : + cm_id_priv->state =IW_CM_STATE_LISTEN ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + ret = cm_id->device->iwcm->create_listen (cm_id, backlog); +if (ret) + cm_id_priv->state =IW_CM_STATE_IDLE ; +break ; +default : +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + ret = -EINVAL ; + } + +return ret; +} +EXPORT_SYMBOL (iw_cm_listen); + +/* +* CM_ID <-- IDLE +* +* Rejects an inbound connection request. No events are generated. +*/ +int iw_cm_reject (struct iw_cm_id *cm_id, +const void *private_data, +u8 private_data_len) +{ +struct iwcm_id_private *cm_id_priv; +unsigned long flags; +int ret; + + cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); +set_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); + +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->state !=IW_CM_STATE_CONN_RECV ) { +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +wake_up_all (&cm_id_priv->connect_wait); +return -EINVAL ; + } + cm_id_priv->state =IW_CM_STATE_IDLE ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + + ret = cm_id->device->iwcm->reject (cm_id, private_data, + private_data_len); + +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +wake_up_all (&cm_id_priv->connect_wait); + +return ret; +} +EXPORT_SYMBOL (iw_cm_reject); + +/* +* CM_ID <-- ESTABLISHED +* +* Accepts an inbound connection request and generates an ESTABLISHED +* event. Callers of iw_cm_disconnect and iw_destroy_cm_id will block +* until the ESTABLISHED event is received from the provider. +*/ +int iw_cm_accept (struct iw_cm_id *cm_id, +struct iw_cm_conn_param *iw_param) +{ +struct iwcm_id_private *cm_id_priv; +struct ib_qp *qp; +unsigned long flags; +int ret; + + cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); +set_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); + +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->state !=IW_CM_STATE_CONN_RECV ) { +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +wake_up_all (&cm_id_priv->connect_wait); +return -EINVAL ; + } +/* Get the ib_qp given the QPN */ + qp = cm_id->device->iwcm->get_qp (cm_id->device, iw_param->qpn); +if (!qp) { +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +return -EINVAL ; + } + cm_id->device->iwcm->add_ref (qp); + cm_id_priv->qp = qp; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + + ret = cm_id->device->iwcm->accept (cm_id, iw_param); +if (ret) { +/* An error on accept precludes provider events */ +BUG_ON (cm_id_priv->state !=IW_CM_STATE_CONN_RECV ); + cm_id_priv->state =IW_CM_STATE_IDLE ; +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->qp) { + cm_id->device->iwcm->rem_ref (qp); + cm_id_priv->qp =NULL ; + } +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +printk ("Accept failed, ret=%d\n" , ret); +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +wake_up_all (&cm_id_priv->connect_wait); + } + +return ret; +} +EXPORT_SYMBOL (iw_cm_accept); + +/* +* Active Side: CM_ID <-- CONN_SENT +* +* If successful, results in the generation of a CONNECT_REPLY +* event. iw_cm_disconnect and iw_cm_destroy will block until the +* CONNECT_REPLY event is received from the provider. +*/ +int iw_cm_connect (struct iw_cm_id *cm_id,struct iw_cm_conn_param *iw_param) +{ +struct iwcm_id_private *cm_id_priv; +int ret =0 ; +unsigned long flags; +struct ib_qp *qp; + + cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); +set_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); + +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->state !=IW_CM_STATE_IDLE ) { +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +wake_up_all (&cm_id_priv->connect_wait); +return -EINVAL ; + } + +/* Get the ib_qp given the QPN */ + qp = cm_id->device->iwcm->get_qp (cm_id->device, iw_param->qpn); +if (!qp) { +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +return -EINVAL ; + } + cm_id->device->iwcm->add_ref (qp); + cm_id_priv->qp = qp; + cm_id_priv->state =IW_CM_STATE_CONN_SENT ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + + ret = cm_id->device->iwcm->connect (cm_id, iw_param); +if (ret) { +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->qp) { + cm_id->device->iwcm->rem_ref (qp); + cm_id_priv->qp =NULL ; + } +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +BUG_ON (cm_id_priv->state !=IW_CM_STATE_CONN_SENT ); + cm_id_priv->state =IW_CM_STATE_IDLE ; +printk ("Connect failed, ret=%d\n" , ret); +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +wake_up_all (&cm_id_priv->connect_wait); + } + +return ret; +} +EXPORT_SYMBOL (iw_cm_connect); + +/* +* Passive Side: new CM_ID <-- CONN_RECV +* +* 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. +* +* An error on the child should not affect the parent, so this +* function does not return a value. +*/ +static void cm_conn_req_handler (struct iwcm_id_private *listen_id_priv, +struct iw_cm_event *iw_event) +{ +unsigned long flags; +struct iw_cm_id *cm_id; +struct iwcm_id_private *cm_id_priv; +int ret; + +/* The provider should never generate a connection request +* event with a bad status. +*/ +BUG_ON (iw_event->status); + +/* We could be destroying the listening id. If so, ignore this +* upcall. */ +spin_lock_irqsave (&listen_id_priv->lock, flags); +if (listen_id_priv->state !=IW_CM_STATE_LISTEN ) { +spin_unlock_irqrestore (&listen_id_priv->lock, flags); +return ; + } +spin_unlock_irqrestore (&listen_id_priv->lock, flags); + + cm_id =iw_create_cm_id (listen_id_priv->id.device, + listen_id_priv->id.cm_handler, + listen_id_priv->id.context); +/* If the cm_id could not be created, ignore the request */ +if (IS_ERR (cm_id)) +return ; + + cm_id->provider_data = iw_event->provider_data; + cm_id->local_addr = iw_event->local_addr; + cm_id->remote_addr = iw_event->remote_addr; + + cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); + cm_id_priv->state =IW_CM_STATE_CONN_RECV ; + +/* Call the client CM handler */ + ret = cm_id->cm_handler (cm_id, iw_event); +if (ret) { +printk ("destroying child id %p, ret=%d\n" , + cm_id, ret); +set_bit (IWCM_F_CALLBACK_DESTROY , &cm_id_priv->flags); +destroy_cm_id (cm_id); +if (atomic_read (&cm_id_priv->refcount)==0 ) +kfree (cm_id); + } +} + +/* +* Passive Side: CM_ID <-- ESTABLISHED +* +* The provider generated an ESTABLISHED event which means that +* the MPA negotion has completed successfully and we are now in MPA +* FPDU mode. +* +* This event can only be received in the CONN_RECV state. If the +* remote peer closed, the ESTABLISHED event would be received followed +* by the CLOSE event. If the app closes, it will block until we wake +* it up after processing this event. +*/ +static int cm_conn_est_handler (struct iwcm_id_private *cm_id_priv, +struct iw_cm_event *iw_event) +{ +unsigned long flags; +int ret =0 ; + +spin_lock_irqsave (&cm_id_priv->lock, flags); + +/* We clear the CONNECT_WAIT bit here to allow the callback +* function to call iw_cm_disconnect. Calling iw_destroy_cm_id +* from a callback handler is not allowed */ +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +switch (cm_id_priv->state) { +case IW_CM_STATE_CONN_RECV : + cm_id_priv->state =IW_CM_STATE_ESTABLISHED ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + ret = cm_id_priv->id.cm_handler (&cm_id_priv->id, iw_event); +break ; +default : +BUG_ON (1 ); + } +wake_up_all (&cm_id_priv->connect_wait); + +return ret; +} + +/* +* Active Side: CM_ID <-- ESTABLISHED +* +* The app has called connect and is waiting for the established event to +* post it's requests to the server. This event will wake up anyone +* blocked in iw_cm_disconnect or iw_destroy_id. +*/ +static int cm_conn_rep_handler (struct iwcm_id_private *cm_id_priv, +struct iw_cm_event *iw_event) +{ +unsigned long flags; +int ret =0 ; + +spin_lock_irqsave (&cm_id_priv->lock, flags); +/* Clear the connect wait bit so a callback function calling +* iw_cm_disconnect will not wait and deadlock this thread */ +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +switch (cm_id_priv->state) { +case IW_CM_STATE_CONN_SENT : +if (iw_event->status ==IW_CM_EVENT_STATUS_ACCEPTED ) { + cm_id_priv->id.local_addr = iw_event->local_addr; + cm_id_priv->id.remote_addr = iw_event->remote_addr; + cm_id_priv->state =IW_CM_STATE_ESTABLISHED ; + }else { +/* REJECTED or RESET */ + cm_id_priv->id.device->iwcm->rem_ref (cm_id_priv->qp); + cm_id_priv->qp =NULL ; + cm_id_priv->state =IW_CM_STATE_IDLE ; + } +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + ret = cm_id_priv->id.cm_handler (&cm_id_priv->id, iw_event); +break ; +default : +BUG_ON (1 ); + } +/* Wake up waiters on connect complete */ +wake_up_all (&cm_id_priv->connect_wait); + +return ret; +} + +/* +* CM_ID <-- CLOSING +* +* If in the ESTABLISHED state, move to CLOSING. +*/ +static void cm_disconnect_handler (struct iwcm_id_private *cm_id_priv, +struct iw_cm_event *iw_event) +{ +unsigned long flags; + +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->state ==IW_CM_STATE_ESTABLISHED ) + cm_id_priv->state =IW_CM_STATE_CLOSING ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +} + +/* +* CM_ID <-- IDLE +* +* If in the ESTBLISHED or CLOSING states, the QP will have have been +* moved by the provider to the ERR state. Disassociate the CM_ID from +* the QP, move to IDLE, and remove the 'connected' reference. +* +* If in some other state, the cm_id was destroyed asynchronously. +* This is the last reference that will result in waking up +* the app thread blocked in iw_destroy_cm_id. +*/ +static int cm_close_handler (struct iwcm_id_private *cm_id_priv, +struct iw_cm_event *iw_event) +{ +unsigned long flags; +int ret =0 ; +/* TT */ printk ("%s:%d cm_id_priv=%p, state=%d\n" , + __FUNCTION__, __LINE__, + cm_id_priv,cm_id_priv->state); +spin_lock_irqsave (&cm_id_priv->lock, flags); + +if (cm_id_priv->qp) { + cm_id_priv->id.device->iwcm->rem_ref (cm_id_priv->qp); + cm_id_priv->qp =NULL ; + } +switch (cm_id_priv->state) { +case IW_CM_STATE_ESTABLISHED : +case IW_CM_STATE_CLOSING : + cm_id_priv->state =IW_CM_STATE_IDLE ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + ret = cm_id_priv->id.cm_handler (&cm_id_priv->id, iw_event); +break ; +case IW_CM_STATE_DESTROYING : +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +break ; +default : +BUG_ON (1 ); + } + +return ret; +} + +static int process_event (struct iwcm_id_private *cm_id_priv, +struct iw_cm_event *iw_event) +{ +int ret =0 ; + +switch (iw_event->event) { +case IW_CM_EVENT_CONNECT_REQUEST : +cm_conn_req_handler (cm_id_priv, iw_event); +break ; +case IW_CM_EVENT_CONNECT_REPLY : + ret =cm_conn_rep_handler (cm_id_priv, iw_event); +break ; +case IW_CM_EVENT_ESTABLISHED : + ret =cm_conn_est_handler (cm_id_priv, iw_event); +break ; +case IW_CM_EVENT_DISCONNECT : +cm_disconnect_handler (cm_id_priv, iw_event); +break ; +case IW_CM_EVENT_CLOSE : + ret =cm_close_handler (cm_id_priv, iw_event); +break ; +default : +BUG_ON (1 ); + } + +return ret; +} + +/* +* Process events on the work_list for the cm_id. If the callback +* function requests that the cm_id be deleted, a flag is set in the +* cm_id flags to indicate that when the last reference is +* removed, the cm_id is to be destroyed. This is necessary to +* distinguish between an object that will be destroyed by the app +* thread asleep on the destroy_wait list vs. an object destroyed +* here synchronously when the last reference is removed. +*/ +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; +unsigned long flags; +int empty; +int ret =0 ; + +spin_lock_irqsave (&cm_id_priv->lock, flags); + empty =list_empty (&cm_id_priv->work_list); +while (!empty) { + work =list_entry (cm_id_priv->work_list.next, + struct iwcm_work, list); +list_del_init (&work->list); + empty =list_empty (&cm_id_priv->work_list); +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + + ret =process_event (cm_id_priv, &work->event); +kfree (work); +if (ret) { +set_bit (IWCM_F_CALLBACK_DESTROY , &cm_id_priv->flags); +destroy_cm_id (&cm_id_priv->id); + } +BUG_ON (atomic_read (&cm_id_priv->refcount)==0 ); +if (iwcm_deref_id (cm_id_priv)) +return ; + +if (atomic_read (&cm_id_priv->refcount)==0 && +test_bit (IWCM_F_CALLBACK_DESTROY , &cm_id_priv->flags)) { +kfree (cm_id_priv); +return ; + } +spin_lock_irqsave (&cm_id_priv->lock, flags); + } +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +} + +/* +* This function is called on interrupt context. Schedule events on +* the iwcm_wq thread to allow callback functions to downcall into +* the CM and/or block. Events are queued to a per-CM_ID +* work_list. If this is the first event on the work_list, the work +* element is also queued on the iwcm_wq thread. +* +* Each event holds a reference on the cm_id. Until the last posted +* event has been delivered and processed, the cm_id cannot be +* deleted. +*/ +static void cm_event_handler (struct iw_cm_id *cm_id, +struct iw_cm_event *iw_event) +{ +struct iwcm_work *work; +struct iwcm_id_private *cm_id_priv; +unsigned long flags; + + work =kmalloc (sizeof *work,GFP_ATOMIC ); +if (!work) +return ; + + cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); +atomic_inc (&cm_id_priv->refcount); + +INIT_WORK (&work->work, cm_work_handler, work); + work->cm_id = cm_id_priv; + work->event = *iw_event; + +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (list_empty (&cm_id_priv->work_list)) { +list_add_tail (&work->list, &cm_id_priv->work_list); +queue_work (iwcm_wq, &work->work); + }else +list_add_tail (&work->list, &cm_id_priv->work_list); +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +} + +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->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->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 =0 ; + 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 ) +{ + iwcm_wq =create_singlethread_workqueue ("iw_cm_wq" ); +if (!iwcm_wq) +return -ENOMEM ; + +return 0 ; +} + +static void __exit iw_cm_cleanup(void) +{ +destroy_workqueue (iwcm_wq); +} + +module_init (iw_cm_init); +module_exit (iw_cm_cleanup);
include/rdma/iw_cm.h new file +254 -0
254 lines not on this page · raw message
include/rdma/iw_cm_private.h new file +62 -0
62 lines not on this page · raw message
Re: [PATCH 1/2] iWARP Connection Manager.
Quoted 43 lines · On Wed, 31 May 2006 13:26:52 -0500 Steve Wise <[email protected]>…
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(-)drivers/infiniband/core/iwcm.c new file +27
-0@@ -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. +*
drivers/infiniband/core/iwcm.c line 37
Quoted 10 lines
drivers/infiniband/core/iwcm.c new file +10
-0+* 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?
Quoted 60 lines
drivers/infiniband/core/iwcm.c new file +60
-0+#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); +}
drivers/infiniband/core/iwcm.c line 107
Quoted 10 lines
drivers/infiniband/core/iwcm.c new file +10
-0+ +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.
Quoted 55 lines
drivers/infiniband/core/iwcm.c new file +55
-0+ +/* +* 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 : +/*
drivers/infiniband/core/iwcm.c line 216
Quoted 10 lines
drivers/infiniband/core/iwcm.c new file +10
-0+* 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.
Re: [PATCH 1/2] iWARP Connection Manager.
Quoted 4 lines
drivers/infiniband/core/iwcm.c line 107
Quoted 1 line
drivers/infiniband/core/iwcm.c new file +1
-0+ 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.
I disagree -- I hate seeing sizeof look like a function call.
- R.
Re: [PATCH 1/2] iWARP Connection Manager.
Quoted 7 lines · Roland Dreier
Quoted 4 lines
drivers/infiniband/core/iwcm.c line 107
Quoted 1 line
drivers/infiniband/core/iwcm.c new file +1
-0+ 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.
I disagree -- I hate seeing sizeof look like a function call.
For the most part, drivers/infiniband/core uses sizeof without parentheses. So I think the correct answer here is to keep the iwcm.c file in line with the rest of the core.
Steve.
Re: [PATCH 1/2] iWARP Connection Manager.
Quoted 6 lines · On Wed, 31 May 2006 15:58:00 -0500 Steve Wise <[email protected]>…
Quoted 5 lines · Roland Dreier
Quoted 4 lines
drivers/infiniband/core/iwcm.c line 107
Quoted 1 line
drivers/infiniband/core/iwcm.c new file +1
-0+ 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.
Quoted 8 lines
Quoted 2 lines
I disagree -- I hate seeing sizeof look like a function call.
For the most part,
drivers/infiniband/coreuses sizeof without parentheses. So I think the correct answer here is to keep theiwcm.cfile in line with the rest of the core.
Make yours right, Bunk will "fix" infiniband core. The kernel style matters not the subsystem. In Documentation/CodingStyle
Chapter 13: Allocating memory
The kernel provides the following general purpose memory allocators:kmalloc(), kzalloc(), kcalloc(), and vmalloc(). Please refer to the API documentation for further information about them.
The preferred form for passing a size of a struct is the following:
p = kmalloc(sizeof(*p), ...);
The alternative form where struct name is spelled out hurts readability and introduces an opportunity for a bug when the pointer variable type is changed but the corresponding sizeof that is passed to a memory allocator is not.
Casting the return value which is a void pointer is redundant. The conversion from void pointer to any other pointer type is guaranteed by the C programming language.
Re: [PATCH 1/2] iWARP Connection Manager.
This is a silly thing to argue about, but...
Quoted 7 lines
The preferred form for passing a size of a struct is the following:
p = kmalloc(sizeof(*p), ...);The alternative form where struct name is spelled out hurts readability and introduces an opportunity for a bug when the pointer variable type is changed but the corresponding sizeof that is passed to a memory allocator is not.
I would argue that this is talking about sizeof(*p) vs. sizeof (struct foo) rather than sizeof(*p) vs. sizeof *p.
You wouldn't write:
return(*p);
but rather
return *p;
And sizeof is an operator not a function, so I think the same usage would apply.
With that said the prevalent kernel usage does seem to be sizeof(*foo) (by about 10 to 1). But I can't help feeling it looks silly.
- R.
Re: [PATCH 1/2] iWARP Connection Manager.
so be it.
iwcm.c and the ammasso files will all use sizeof().
Steve.
Quoted 33 lines · Roland Dreier
This is a silly thing to argue about, but...
Quoted 7 lines
The preferred form for passing a size of a struct is the following:
p = kmalloc(sizeof(*p), ...);The alternative form where struct name is spelled out hurts readability and introduces an opportunity for a bug when the pointer variable type is changed but the corresponding sizeof that is passed to a memory allocator is not.
I would argue that this is talking about
sizeof(*p)vs. sizeof (struct foo) rather thansizeof(*p)vs. sizeof *p.You wouldn't write:
return(*p);but rather
return *p;And sizeof is an operator not a function, so I think the same usage would apply.
With that said the prevalent kernel usage does seem to be
sizeof(*foo)(by about 10 to 1). But I can't help feeling it looks silly.- R.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 1/2] iWARP Connection Manager.
In reply to Roland DreierQuoted 6 lines · Roland Dreier
Quoted 4 lines
drivers/infiniband/core/iwcm.c line 107
Quoted 1 line
drivers/infiniband/core/iwcm.c new file +1
-0+ 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.
I disagree -- I hate seeing sizeof look like a function call.
CodingStyle isn't explicit on this issue, but it does use parens in an example demonstrating how to pass the size of a struct to kmalloc.
(grepping and comparing numbers for both usages in the code left as an exercise to the bored).
Cheers,
Muli
Re: [PATCH 1/2] iWARP Connection Manager.
In reply to Steve WiseQuoted 7 lines · Steve Wise
drivers/infiniband/core/iwcm.c new file +7
-0+/* +* 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 ;
drivers/infiniband/core/iwcm.c line 78
Quoted 10 lines
drivers/infiniband/core/iwcm.c new file +10
-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);
We recently changed the RDMA CM, IB CM, and a couple of other modules from using wait objects to completions. This avoids a race condition between decrementing the reference count, which allows destruction to proceed, and calling wake_up on a freed cm_id. My guess is that you may need to do the same.
Can you also explain the use of the return value here? It's ignored below in rem_ref() and destroy_cm_id().
Quoted 27 lines
drivers/infiniband/core/iwcm.c new file +26
-0+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); +} + +/* +* 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 +*/
drivers/infiniband/core/iwcm.c line 174
Quoted 10 lines
drivers/infiniband/core/iwcm.c new file +10
-0+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));
Am I understanding this check correctly? You're checking to see if the user has called iw_cm_disconnect() at the same time that they called iw_cm_connect() or iw_cm_accept(). Are connect / accept blocking, or are you just waiting for an event?
Quoted 47 lines
drivers/infiniband/core/iwcm.c new file +47
-0+ +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 ); + } + +return ret; +} +EXPORT_SYMBOL (iw_cm_disconnect); +static void destroy_cm_id (struct iw_cm_id *cm_id)
drivers/infiniband/core/iwcm.c line 238
Quoted 10 lines
drivers/infiniband/core/iwcm.c new file +10
-0+{ +struct iwcm_id_private *cm_id_priv; +unsigned long flags; +int ret; + + cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); +/* Wait if we're currently in a connect or accept downcall. A +* listening endpoint should never block here. */ +wait_event (cm_id_priv->connect_wait, + !test_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags));
Same question/comment as above.
Quoted 26 lines
drivers/infiniband/core/iwcm.c new file +26
-0+ +spin_lock_irqsave (&cm_id_priv->lock, flags); +switch (cm_id_priv->state) { +case IW_CM_STATE_LISTEN : + cm_id_priv->state =IW_CM_STATE_DESTROYING ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +/* destroy the listening endpoint */ + ret = cm_id->device->iwcm->destroy_listen (cm_id); +break ; +case IW_CM_STATE_ESTABLISHED : + cm_id_priv->state =IW_CM_STATE_DESTROYING ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +/* Abrupt close of the connection */ + (void )iwcm_modify_qp_err (cm_id_priv->qp); +break ; +case IW_CM_STATE_IDLE : +case IW_CM_STATE_CLOSING : + cm_id_priv->state =IW_CM_STATE_DESTROYING ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +break ; +case IW_CM_STATE_CONN_RECV : +/* +* App called destroy before/without calling accept after +* receiving connection request event notification. +*/ + cm_id_priv->state =IW_CM_STATE_DESTROYING ;
drivers/infiniband/core/iwcm.c line 274
Quoted 10 lines
drivers/infiniband/core/iwcm.c new file +10
-0+spin_unlock_irqrestore (&cm_id_priv->lock, flags); +break ; +case IW_CM_STATE_CONN_SENT : +case IW_CM_STATE_DESTROYING : +default : +BUG_ON (1 ); +break ; + } + +spin_lock_irqsave (&cm_id_priv->lock, flags);
As an alternative, you could hold the lock from above, an let the LISTEN / ESTABLISHED state checks release and reacquire.
Quoted 95 lines
drivers/infiniband/core/iwcm.c new file +95
-0+if (cm_id_priv->qp) { + cm_id_priv->id.device->iwcm->rem_ref (cm_id_priv->qp); + cm_id_priv->qp =NULL ; + } +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + + (void )iwcm_deref_id (cm_id_priv); +} + +/* +* This function is only called by the application thread and cannot +* be called by the event thread. The function will wait for all +* references to be released on the cm_id and then kfree the cm_id +* object. +*/ +void iw_destroy_cm_id (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); +BUG_ON (test_bit (IWCM_F_CALLBACK_DESTROY , &cm_id_priv->flags)); + +destroy_cm_id (cm_id); + +wait_event (cm_id_priv->destroy_wait, + !atomic_read (&cm_id_priv->refcount)); + +kfree (cm_id_priv); +} +EXPORT_SYMBOL (iw_destroy_cm_id); + +/* +* CM_ID <-- LISTEN +* +* Start listening for connect requests. Generates one CONNECT_REQUEST +* event for each inbound connect request. +*/ +int iw_cm_listen (struct iw_cm_id *cm_id,int backlog) +{ +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); +spin_lock_irqsave (&cm_id_priv->lock, flags); +switch (cm_id_priv->state) { +case IW_CM_STATE_IDLE : + cm_id_priv->state =IW_CM_STATE_LISTEN ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + ret = cm_id->device->iwcm->create_listen (cm_id, backlog); +if (ret) + cm_id_priv->state =IW_CM_STATE_IDLE ; +break ; +default : +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + ret = -EINVAL ; + } + +return ret; +} +EXPORT_SYMBOL (iw_cm_listen); + +/* +* CM_ID <-- IDLE +* +* Rejects an inbound connection request. No events are generated. +*/ +int iw_cm_reject (struct iw_cm_id *cm_id, +const void *private_data, +u8 private_data_len) +{ +struct iwcm_id_private *cm_id_priv; +unsigned long flags; +int ret; + + cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); +set_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); + +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->state !=IW_CM_STATE_CONN_RECV ) { +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +wake_up_all (&cm_id_priv->connect_wait); +return -EINVAL ; + } + cm_id_priv->state =IW_CM_STATE_IDLE ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + + ret = cm_id->device->iwcm->reject (cm_id, private_data, + private_data_len); + +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +wake_up_all (&cm_id_priv->connect_wait); + +return ret;
drivers/infiniband/core/iwcm.c line 379
Quoted 10 lines
drivers/infiniband/core/iwcm.c new file +10
-0+} +EXPORT_SYMBOL (iw_cm_reject); + +/* +* CM_ID <-- ESTABLISHED +* +* Accepts an inbound connection request and generates an ESTABLISHED +* event. Callers of iw_cm_disconnect and iw_destroy_cm_id will block +* until the ESTABLISHED event is received from the provider. +*/
This makes it sound like we're just waiting for an event.
Quoted 149 lines
drivers/infiniband/core/iwcm.c new file +149
-0+int iw_cm_accept (struct iw_cm_id *cm_id, +struct iw_cm_conn_param *iw_param) +{ +struct iwcm_id_private *cm_id_priv; +struct ib_qp *qp; +unsigned long flags; +int ret; + + cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); +set_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); + +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->state !=IW_CM_STATE_CONN_RECV ) { +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +wake_up_all (&cm_id_priv->connect_wait); +return -EINVAL ; + } +/* Get the ib_qp given the QPN */ + qp = cm_id->device->iwcm->get_qp (cm_id->device, iw_param->qpn); +if (!qp) { +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +return -EINVAL ; + } + cm_id->device->iwcm->add_ref (qp); + cm_id_priv->qp = qp; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + + ret = cm_id->device->iwcm->accept (cm_id, iw_param); +if (ret) { +/* An error on accept precludes provider events */ +BUG_ON (cm_id_priv->state !=IW_CM_STATE_CONN_RECV ); + cm_id_priv->state =IW_CM_STATE_IDLE ; +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->qp) { + cm_id->device->iwcm->rem_ref (qp); + cm_id_priv->qp =NULL ; + } +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +printk ("Accept failed, ret=%d\n" , ret); +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +wake_up_all (&cm_id_priv->connect_wait); + } + +return ret; +} +EXPORT_SYMBOL (iw_cm_accept); + +/* +* Active Side: CM_ID <-- CONN_SENT +* +* If successful, results in the generation of a CONNECT_REPLY +* event. iw_cm_disconnect and iw_cm_destroy will block until the +* CONNECT_REPLY event is received from the provider. +*/ +int iw_cm_connect (struct iw_cm_id *cm_id,struct iw_cm_conn_param *iw_param) +{ +struct iwcm_id_private *cm_id_priv; +int ret =0 ; +unsigned long flags; +struct ib_qp *qp; + + cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); +set_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); + +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->state !=IW_CM_STATE_IDLE ) { +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +wake_up_all (&cm_id_priv->connect_wait); +return -EINVAL ; + } + +/* Get the ib_qp given the QPN */ + qp = cm_id->device->iwcm->get_qp (cm_id->device, iw_param->qpn); +if (!qp) { +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +return -EINVAL ; + } + cm_id->device->iwcm->add_ref (qp); + cm_id_priv->qp = qp; + cm_id_priv->state =IW_CM_STATE_CONN_SENT ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + + ret = cm_id->device->iwcm->connect (cm_id, iw_param); +if (ret) { +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->qp) { + cm_id->device->iwcm->rem_ref (qp); + cm_id_priv->qp =NULL ; + } +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +BUG_ON (cm_id_priv->state !=IW_CM_STATE_CONN_SENT ); + cm_id_priv->state =IW_CM_STATE_IDLE ; +printk ("Connect failed, ret=%d\n" , ret); +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +wake_up_all (&cm_id_priv->connect_wait); + } + +return ret; +} +EXPORT_SYMBOL (iw_cm_connect); + +/* +* Passive Side: new CM_ID <-- CONN_RECV +* +* 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. +* +* An error on the child should not affect the parent, so this +* function does not return a value. +*/ +static void cm_conn_req_handler (struct iwcm_id_private *listen_id_priv, +struct iw_cm_event *iw_event) +{ +unsigned long flags; +struct iw_cm_id *cm_id; +struct iwcm_id_private *cm_id_priv; +int ret; + +/* The provider should never generate a connection request +* event with a bad status. +*/ +BUG_ON (iw_event->status); + +/* We could be destroying the listening id. If so, ignore this +* upcall. */ +spin_lock_irqsave (&listen_id_priv->lock, flags); +if (listen_id_priv->state !=IW_CM_STATE_LISTEN ) { +spin_unlock_irqrestore (&listen_id_priv->lock, flags); +return ; + } +spin_unlock_irqrestore (&listen_id_priv->lock, flags); + + cm_id =iw_create_cm_id (listen_id_priv->id.device, + listen_id_priv->id.cm_handler, + listen_id_priv->id.context); +/* If the cm_id could not be created, ignore the request */ +if (IS_ERR (cm_id)) +return ; + + cm_id->provider_data = iw_event->provider_data; + cm_id->local_addr = iw_event->local_addr;
drivers/infiniband/core/iwcm.c line 538
Quoted 10 lines
drivers/infiniband/core/iwcm.c new file +10
-0+ cm_id->remote_addr = iw_event->remote_addr; + + cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); + cm_id_priv->state =IW_CM_STATE_CONN_RECV ; + +/* Call the client CM handler */ + ret = cm_id->cm_handler (cm_id, iw_event); +if (ret) { +printk ("destroying child id %p, ret=%d\n" , + cm_id, ret);
We probably don't always want to print a message here.
Quoted 29 lines
drivers/infiniband/core/iwcm.c new file +29
-0+set_bit (IWCM_F_CALLBACK_DESTROY , &cm_id_priv->flags); +destroy_cm_id (cm_id); +if (atomic_read (&cm_id_priv->refcount)==0 ) +kfree (cm_id); + } +} + +/* +* Passive Side: CM_ID <-- ESTABLISHED +* +* The provider generated an ESTABLISHED event which means that +* the MPA negotion has completed successfully and we are now in MPA +* FPDU mode. +* +* This event can only be received in the CONN_RECV state. If the +* remote peer closed, the ESTABLISHED event would be received followed +* by the CLOSE event. If the app closes, it will block until we wake +* it up after processing this event. +*/ +static int cm_conn_est_handler (struct iwcm_id_private *cm_id_priv, +struct iw_cm_event *iw_event) +{ +unsigned long flags; +int ret =0 ; + +spin_lock_irqsave (&cm_id_priv->lock, flags); + +/* We clear the CONNECT_WAIT bit here to allow the callback +* function to call iw_cm_disconnect. Calling iw_destroy_cm_id
drivers/infiniband/core/iwcm.c line 577
Quoted 10 lines
drivers/infiniband/core/iwcm.c new file +10
-0+* from a callback handler is not allowed */ +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +switch (cm_id_priv->state) { +case IW_CM_STATE_CONN_RECV : + cm_id_priv->state =IW_CM_STATE_ESTABLISHED ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + ret = cm_id_priv->id.cm_handler (&cm_id_priv->id, iw_event); +break ; +default : +BUG_ON (1 );
Can just BUG_ON the state and avoid the switch. Same comment applies below.
Quoted 72 lines
drivers/infiniband/core/iwcm.c new file +72
-0+ } +wake_up_all (&cm_id_priv->connect_wait); + +return ret; +} + +/* +* Active Side: CM_ID <-- ESTABLISHED +* +* The app has called connect and is waiting for the established event to +* post it's requests to the server. This event will wake up anyone +* blocked in iw_cm_disconnect or iw_destroy_id. +*/ +static int cm_conn_rep_handler (struct iwcm_id_private *cm_id_priv, +struct iw_cm_event *iw_event) +{ +unsigned long flags; +int ret =0 ; + +spin_lock_irqsave (&cm_id_priv->lock, flags); +/* Clear the connect wait bit so a callback function calling +* iw_cm_disconnect will not wait and deadlock this thread */ +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +switch (cm_id_priv->state) { +case IW_CM_STATE_CONN_SENT : +if (iw_event->status ==IW_CM_EVENT_STATUS_ACCEPTED ) { + cm_id_priv->id.local_addr = iw_event->local_addr; + cm_id_priv->id.remote_addr = iw_event->remote_addr; + cm_id_priv->state =IW_CM_STATE_ESTABLISHED ; + }else { +/* REJECTED or RESET */ + cm_id_priv->id.device->iwcm->rem_ref (cm_id_priv->qp); + cm_id_priv->qp =NULL ; + cm_id_priv->state =IW_CM_STATE_IDLE ; + } +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + ret = cm_id_priv->id.cm_handler (&cm_id_priv->id, iw_event); +break ; +default : +BUG_ON (1 ); + } +/* Wake up waiters on connect complete */ +wake_up_all (&cm_id_priv->connect_wait); + +return ret; +} + +/* +* CM_ID <-- CLOSING +* +* If in the ESTABLISHED state, move to CLOSING. +*/ +static void cm_disconnect_handler (struct iwcm_id_private *cm_id_priv, +struct iw_cm_event *iw_event) +{ +unsigned long flags; + +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->state ==IW_CM_STATE_ESTABLISHED ) + cm_id_priv->state =IW_CM_STATE_CLOSING ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +} + +/* +* CM_ID <-- IDLE +* +* If in the ESTBLISHED or CLOSING states, the QP will have have been +* moved by the provider to the ERR state. Disassociate the CM_ID from +* the QP, move to IDLE, and remove the 'connected' reference. +* +* If in some other state, the cm_id was destroyed asynchronously. +* This is the last reference that will result in waking up
drivers/infiniband/core/iwcm.c line 659
Quoted 10 lines
drivers/infiniband/core/iwcm.c new file +10
-0+* the app thread blocked in iw_destroy_cm_id. +*/ +static int cm_close_handler (struct iwcm_id_private *cm_id_priv, +struct iw_cm_event *iw_event) +{ +unsigned long flags; +int ret =0 ; +/* TT */ printk ("%s:%d cm_id_priv=%p, state=%d\n" , + __FUNCTION__, __LINE__, + cm_id_priv,cm_id_priv->state);
Will want to remove this.
- Sean
Re: [PATCH 1/2] iWARP Connection Manager.
Quoted 15 lines · Sean Hefty
Quoted 14 lines · Steve Wise
drivers/infiniband/core/iwcm.c new file +14
-0+/* +* 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,
Quoted 9 lines
drivers/infiniband/core/iwcm.c line 78
Quoted 3 lines
drivers/infiniband/core/iwcm.c new file +3
-0+ &cm_id_priv->flags)); + ret =1 ; +wake_up (&cm_id_priv->destroy_wait);We recently changed the RDMA CM, IB CM, and a couple of other modules from using
wait objects to completions. This avoids a race condition between decrementing
the reference count, which allows destruction to proceed, and callingwake_upon a freedcm_id. My guess is that you may need to do the same.
Good catch. Yes, the IW CM suffers from the same race condition. I'll change this to use completions...
Quoted 3 lines
Can you also explain the use of the return value here? It's ignored below in
rem_ref()anddestroy_cm_id().
The return value is supposed to indicate whether this call to deref _may_ have resulted in waking up another thread and the cm_id being freed. Its used in cm_work_handler(), in conjunction with setting the IWCM_F_CALLBACK_DESTROY flag to know whether the cm_id needs to be freed on the callback path.
Quoted 34 lines
Quoted 34 lines
drivers/infiniband/core/iwcm.c new file +33
-0+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); +} + +/* +* 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);
Quoted 8 lines
drivers/infiniband/core/iwcm.c line 174
Quoted 3 lines
drivers/infiniband/core/iwcm.c new file +3
-0+/* 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));Am I understanding this check correctly? You're checking to see if the user has called
iw_cm_disconnect()at the same time that they callediw_cm_connect()oriw_cm_accept(). Are connect / accept blocking, or are you just waiting for an event?
The CM must wait for the low level provider to finish a connect() or accept() operation before telling the low level provider to disconnect via modifying the iwarp QP. Regardless of whether they block, this disconnect can happen concurrently with the connect/accept so we need to hold the disconnect until the connect/accept completes.
Quoted 52 lines
Quoted 52 lines
drivers/infiniband/core/iwcm.c new file +51
-0+ +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 ); + } + +return ret; +} +EXPORT_SYMBOL (iw_cm_disconnect); +static void destroy_cm_id (struct iw_cm_id *cm_id) +{ +struct iwcm_id_private *cm_id_priv; +unsigned long flags; +int ret;
Quoted 9 lines
drivers/infiniband/core/iwcm.c line 238
Quoted 6 lines
drivers/infiniband/core/iwcm.c new file +6
-0+ + cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); +/* Wait if we're currently in a connect or accept downcall. A +* listening endpoint should never block here. */ +wait_event (cm_id_priv->connect_wait, + !test_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags));Same question/comment as above.
Same answer.
Quoted 31 lines
Quoted 31 lines
drivers/infiniband/core/iwcm.c new file +31
-0+ +spin_lock_irqsave (&cm_id_priv->lock, flags); +switch (cm_id_priv->state) { +case IW_CM_STATE_LISTEN : + cm_id_priv->state =IW_CM_STATE_DESTROYING ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +/* destroy the listening endpoint */ + ret = cm_id->device->iwcm->destroy_listen (cm_id); +break ; +case IW_CM_STATE_ESTABLISHED : + cm_id_priv->state =IW_CM_STATE_DESTROYING ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +/* Abrupt close of the connection */ + (void )iwcm_modify_qp_err (cm_id_priv->qp); +break ; +case IW_CM_STATE_IDLE : +case IW_CM_STATE_CLOSING : + cm_id_priv->state =IW_CM_STATE_DESTROYING ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +break ; +case IW_CM_STATE_CONN_RECV : +/* +* App called destroy before/without calling accept after +* receiving connection request event notification. +*/ + cm_id_priv->state =IW_CM_STATE_DESTROYING ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +break ; +case IW_CM_STATE_CONN_SENT : +case IW_CM_STATE_DESTROYING : +default :
Quoted 9 lines
drivers/infiniband/core/iwcm.c line 274
Quoted 5 lines
drivers/infiniband/core/iwcm.c new file +5
-0+BUG_ON (1 ); +break ; + } + +spin_lock_irqsave (&cm_id_priv->lock, flags);As an alternative, you could hold the lock from above, an let the LISTEN / ESTABLISHED state checks release and reacquire.
Yes, perhaps that's cleaner.
Quoted 99 lines
Quoted 99 lines
drivers/infiniband/core/iwcm.c new file +99
-0+if (cm_id_priv->qp) { + cm_id_priv->id.device->iwcm->rem_ref (cm_id_priv->qp); + cm_id_priv->qp =NULL ; + } +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + + (void )iwcm_deref_id (cm_id_priv); +} + +/* +* This function is only called by the application thread and cannot +* be called by the event thread. The function will wait for all +* references to be released on the cm_id and then kfree the cm_id +* object. +*/ +void iw_destroy_cm_id (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); +BUG_ON (test_bit (IWCM_F_CALLBACK_DESTROY , &cm_id_priv->flags)); + +destroy_cm_id (cm_id); + +wait_event (cm_id_priv->destroy_wait, + !atomic_read (&cm_id_priv->refcount)); + +kfree (cm_id_priv); +} +EXPORT_SYMBOL (iw_destroy_cm_id); + +/* +* CM_ID <-- LISTEN +* +* Start listening for connect requests. Generates one CONNECT_REQUEST +* event for each inbound connect request. +*/ +int iw_cm_listen (struct iw_cm_id *cm_id,int backlog) +{ +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); +spin_lock_irqsave (&cm_id_priv->lock, flags); +switch (cm_id_priv->state) { +case IW_CM_STATE_IDLE : + cm_id_priv->state =IW_CM_STATE_LISTEN ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + ret = cm_id->device->iwcm->create_listen (cm_id, backlog); +if (ret) + cm_id_priv->state =IW_CM_STATE_IDLE ; +break ; +default : +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + ret = -EINVAL ; + } + +return ret; +} +EXPORT_SYMBOL (iw_cm_listen); + +/* +* CM_ID <-- IDLE +* +* Rejects an inbound connection request. No events are generated. +*/ +int iw_cm_reject (struct iw_cm_id *cm_id, +const void *private_data, +u8 private_data_len) +{ +struct iwcm_id_private *cm_id_priv; +unsigned long flags; +int ret; + + cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); +set_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); + +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->state !=IW_CM_STATE_CONN_RECV ) { +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +wake_up_all (&cm_id_priv->connect_wait); +return -EINVAL ; + } + cm_id_priv->state =IW_CM_STATE_IDLE ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + + ret = cm_id->device->iwcm->reject (cm_id, private_data, + private_data_len); + +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +wake_up_all (&cm_id_priv->connect_wait); + +return ret; +} +EXPORT_SYMBOL (iw_cm_reject); + +/*
Quoted 9 lines
Quoted 6 lines
+ *
CM_ID<-- ESTABLISHED
+ *
+ * Accepts an inbound connection request and generates an ESTABLISHED
+ * event. Callers ofiw_cm_disconnectandiw_destroy_cm_idwill block
+ * until the ESTABLISHED event is received from the provider.
+ */This makes it sound like we're just waiting for an event.
disconnect/destory paths wait for the provider to complete the accept or connect operation.
Quoted 153 lines
Quoted 153 lines
drivers/infiniband/core/iwcm.c new file +153
-0+int iw_cm_accept (struct iw_cm_id *cm_id, +struct iw_cm_conn_param *iw_param) +{ +struct iwcm_id_private *cm_id_priv; +struct ib_qp *qp; +unsigned long flags; +int ret; + + cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); +set_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); + +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->state !=IW_CM_STATE_CONN_RECV ) { +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +wake_up_all (&cm_id_priv->connect_wait); +return -EINVAL ; + } +/* Get the ib_qp given the QPN */ + qp = cm_id->device->iwcm->get_qp (cm_id->device, iw_param->qpn); +if (!qp) { +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +return -EINVAL ; + } + cm_id->device->iwcm->add_ref (qp); + cm_id_priv->qp = qp; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + + ret = cm_id->device->iwcm->accept (cm_id, iw_param); +if (ret) { +/* An error on accept precludes provider events */ +BUG_ON (cm_id_priv->state !=IW_CM_STATE_CONN_RECV ); + cm_id_priv->state =IW_CM_STATE_IDLE ; +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->qp) { + cm_id->device->iwcm->rem_ref (qp); + cm_id_priv->qp =NULL ; + } +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +printk ("Accept failed, ret=%d\n" , ret); +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +wake_up_all (&cm_id_priv->connect_wait); + } + +return ret; +} +EXPORT_SYMBOL (iw_cm_accept); + +/* +* Active Side: CM_ID <-- CONN_SENT +* +* If successful, results in the generation of a CONNECT_REPLY +* event. iw_cm_disconnect and iw_cm_destroy will block until the +* CONNECT_REPLY event is received from the provider. +*/ +int iw_cm_connect (struct iw_cm_id *cm_id,struct iw_cm_conn_param *iw_param) +{ +struct iwcm_id_private *cm_id_priv; +int ret =0 ; +unsigned long flags; +struct ib_qp *qp; + + cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); +set_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); + +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->state !=IW_CM_STATE_IDLE ) { +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +wake_up_all (&cm_id_priv->connect_wait); +return -EINVAL ; + } + +/* Get the ib_qp given the QPN */ + qp = cm_id->device->iwcm->get_qp (cm_id->device, iw_param->qpn); +if (!qp) { +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +return -EINVAL ; + } + cm_id->device->iwcm->add_ref (qp); + cm_id_priv->qp = qp; + cm_id_priv->state =IW_CM_STATE_CONN_SENT ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + + ret = cm_id->device->iwcm->connect (cm_id, iw_param); +if (ret) { +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->qp) { + cm_id->device->iwcm->rem_ref (qp); + cm_id_priv->qp =NULL ; + } +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +BUG_ON (cm_id_priv->state !=IW_CM_STATE_CONN_SENT ); + cm_id_priv->state =IW_CM_STATE_IDLE ; +printk ("Connect failed, ret=%d\n" , ret); +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +wake_up_all (&cm_id_priv->connect_wait); + } + +return ret; +} +EXPORT_SYMBOL (iw_cm_connect); + +/* +* Passive Side: new CM_ID <-- CONN_RECV +* +* 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. +* +* An error on the child should not affect the parent, so this +* function does not return a value. +*/ +static void cm_conn_req_handler (struct iwcm_id_private *listen_id_priv, +struct iw_cm_event *iw_event) +{ +unsigned long flags; +struct iw_cm_id *cm_id; +struct iwcm_id_private *cm_id_priv; +int ret; + +/* The provider should never generate a connection request +* event with a bad status. +*/ +BUG_ON (iw_event->status); + +/* We could be destroying the listening id. If so, ignore this +* upcall. */ +spin_lock_irqsave (&listen_id_priv->lock, flags); +if (listen_id_priv->state !=IW_CM_STATE_LISTEN ) { +spin_unlock_irqrestore (&listen_id_priv->lock, flags); +return ; + } +spin_unlock_irqrestore (&listen_id_priv->lock, flags); + + cm_id =iw_create_cm_id (listen_id_priv->id.device, + listen_id_priv->id.cm_handler, + listen_id_priv->id.context); +/* If the cm_id could not be created, ignore the request */ +if (IS_ERR (cm_id)) +return ; + + cm_id->provider_data = iw_event->provider_data; + cm_id->local_addr = iw_event->local_addr; + cm_id->remote_addr = iw_event->remote_addr; + + cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); + cm_id_priv->state =IW_CM_STATE_CONN_RECV ;
Quoted 9 lines
drivers/infiniband/core/iwcm.c line 538
Quoted 6 lines
drivers/infiniband/core/iwcm.c new file +6
-0+ +/* Call the client CM handler */ + ret = cm_id->cm_handler (cm_id, iw_event); +if (ret) { +printk ("destroying child id %p, ret=%d\n" , + cm_id, ret);We probably don't always want to print a message here.
Yes. I'll change this to a pr_debug().
Quoted 33 lines
Quoted 33 lines
drivers/infiniband/core/iwcm.c new file +33
-0+set_bit (IWCM_F_CALLBACK_DESTROY , &cm_id_priv->flags); +destroy_cm_id (cm_id); +if (atomic_read (&cm_id_priv->refcount)==0 ) +kfree (cm_id); + } +} + +/* +* Passive Side: CM_ID <-- ESTABLISHED +* +* The provider generated an ESTABLISHED event which means that +* the MPA negotion has completed successfully and we are now in MPA +* FPDU mode. +* +* This event can only be received in the CONN_RECV state. If the +* remote peer closed, the ESTABLISHED event would be received followed +* by the CLOSE event. If the app closes, it will block until we wake +* it up after processing this event. +*/ +static int cm_conn_est_handler (struct iwcm_id_private *cm_id_priv, +struct iw_cm_event *iw_event) +{ +unsigned long flags; +int ret =0 ; + +spin_lock_irqsave (&cm_id_priv->lock, flags); + +/* We clear the CONNECT_WAIT bit here to allow the callback +* function to call iw_cm_disconnect. Calling iw_destroy_cm_id +* from a callback handler is not allowed */ +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +switch (cm_id_priv->state) { +case IW_CM_STATE_CONN_RECV :
Quoted 9 lines
drivers/infiniband/core/iwcm.c line 577
Quoted 6 lines
drivers/infiniband/core/iwcm.c new file +6
-0+ cm_id_priv->state =IW_CM_STATE_ESTABLISHED ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + ret = cm_id_priv->id.cm_handler (&cm_id_priv->id, iw_event); +break ; +default : +BUG_ON (1 );Can just
BUG_ONthe state and avoid the switch. Same comment applies below.
ok.
Quoted 76 lines
Quoted 76 lines
drivers/infiniband/core/iwcm.c new file +76
-0+ } +wake_up_all (&cm_id_priv->connect_wait); + +return ret; +} + +/* +* Active Side: CM_ID <-- ESTABLISHED +* +* The app has called connect and is waiting for the established event to +* post it's requests to the server. This event will wake up anyone +* blocked in iw_cm_disconnect or iw_destroy_id. +*/ +static int cm_conn_rep_handler (struct iwcm_id_private *cm_id_priv, +struct iw_cm_event *iw_event) +{ +unsigned long flags; +int ret =0 ; + +spin_lock_irqsave (&cm_id_priv->lock, flags); +/* Clear the connect wait bit so a callback function calling +* iw_cm_disconnect will not wait and deadlock this thread */ +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +switch (cm_id_priv->state) { +case IW_CM_STATE_CONN_SENT : +if (iw_event->status ==IW_CM_EVENT_STATUS_ACCEPTED ) { + cm_id_priv->id.local_addr = iw_event->local_addr; + cm_id_priv->id.remote_addr = iw_event->remote_addr; + cm_id_priv->state =IW_CM_STATE_ESTABLISHED ; + }else { +/* REJECTED or RESET */ + cm_id_priv->id.device->iwcm->rem_ref (cm_id_priv->qp); + cm_id_priv->qp =NULL ; + cm_id_priv->state =IW_CM_STATE_IDLE ; + } +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + ret = cm_id_priv->id.cm_handler (&cm_id_priv->id, iw_event); +break ; +default : +BUG_ON (1 ); + } +/* Wake up waiters on connect complete */ +wake_up_all (&cm_id_priv->connect_wait); + +return ret; +} + +/* +* CM_ID <-- CLOSING +* +* If in the ESTABLISHED state, move to CLOSING. +*/ +static void cm_disconnect_handler (struct iwcm_id_private *cm_id_priv, +struct iw_cm_event *iw_event) +{ +unsigned long flags; + +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->state ==IW_CM_STATE_ESTABLISHED ) + cm_id_priv->state =IW_CM_STATE_CLOSING ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +} + +/* +* CM_ID <-- IDLE +* +* If in the ESTBLISHED or CLOSING states, the QP will have have been +* moved by the provider to the ERR state. Disassociate the CM_ID from +* the QP, move to IDLE, and remove the 'connected' reference. +* +* If in some other state, the cm_id was destroyed asynchronously. +* This is the last reference that will result in waking up +* the app thread blocked in iw_destroy_cm_id. +*/ +static int cm_close_handler (struct iwcm_id_private *cm_id_priv, +struct iw_cm_event *iw_event)
Quoted 9 lines
drivers/infiniband/core/iwcm.c line 659
Quoted 6 lines
drivers/infiniband/core/iwcm.c new file +6
-0+{ +unsigned long flags; +int ret =0 ; +/* TT */ printk ("%s:%d cm_id_priv=%p, state=%d\n" , + __FUNCTION__, __LINE__, + cm_id_priv,cm_id_priv->state);Will want to remove this.
oops. yes...
Quoted 1 line
- Sean
Re: [PATCH 1/2] iWARP Connection Manager.
Quoted 38 lines · Steve Wise
Quoted 4 lines
Quoted 4 lines
drivers/infiniband/core/iwcm.c new file +4
-0+int iw_cm_disconnect (struct iw_cm_id *cm_id,int abrupt) +{ +struct iwcm_id_private *cm_id_priv; +unsigned long flags;Quoted 8 lines
drivers/infiniband/core/iwcm.c line 174
Quoted 6 lines
drivers/infiniband/core/iwcm.c new file +6
-0+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));Am I understanding this check correctly? You're checking to see if the user has called
iw_cm_disconnect()at the same time that they callediw_cm_connect()oriw_cm_accept(). Are connect / accept blocking, or are you just waiting for an event?The CM must wait for the low level provider to finish a
connect()oraccept()operation before telling the low level provider to disconnect via modifying the iwarp QP. Regardless of whether they block, this disconnect can happen concurrently with the connect/accept so we need to hold the disconnect until the connect/accept completes.Quoted 6 lines
Quoted 6 lines
drivers/infiniband/core/iwcm.c new file +6
-0+EXPORT_SYMBOL (iw_cm_disconnect); +static void destroy_cm_id (struct iw_cm_id *cm_id) +{ +struct iwcm_id_private *cm_id_priv; +unsigned long flags; +int ret;Quoted 9 lines
drivers/infiniband/core/iwcm.c line 238
Quoted 6 lines
drivers/infiniband/core/iwcm.c new file +6
-0+ + cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); +/* Wait if we're currently in a connect or accept downcall. A +* listening endpoint should never block here. */ +wait_event (cm_id_priv->connect_wait, + !test_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags));Same question/comment as above.
Quoted 1 line
Same answer.
There's a difference between trying to handle the user calling disconnect/destroy at the same time a call to accept/connect is active, versus the user calling disconnect/destroy after accept/connect have returned. In the latter case, I think you're fine. In the first case, this is allowing a user to call destroy at the same time that they're calling accept/connect. Additionally, there's no guarantee that the F_CONNECT_WAIT flag has been set by accept/connect by the time disconnect/destroy tests it.
- Sean
Re: [openib-general] Re: [PATCH 1/2] iWARP Connection Manager.
Quoted 44 lines · Sean Hefty
Quoted 41 lines · Steve Wise
Quoted 7 lines
Quoted 7 lines
drivers/infiniband/core/iwcm.c new file +7
-0+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);Quoted 8 lines
drivers/infiniband/core/iwcm.c line 174
Quoted 3 lines
drivers/infiniband/core/iwcm.c new file +3
-0+/* 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));Am I understanding this check correctly? You're checking to see if the user has called
iw_cm_disconnect()at the same time that they callediw_cm_connect()oriw_cm_accept(). Are connect / accept blocking, or are you just waiting for an event?The CM must wait for the low level provider to finish a
connect()oraccept()operation before telling the low level provider to disconnect via modifying the iwarp QP. Regardless of whether they block, this disconnect can happen concurrently with the connect/accept so we need to hold the disconnect until the connect/accept completes.Quoted 6 lines
Quoted 6 lines
drivers/infiniband/core/iwcm.c new file +6
-0+EXPORT_SYMBOL (iw_cm_disconnect); +static void destroy_cm_id (struct iw_cm_id *cm_id) +{ +struct iwcm_id_private *cm_id_priv; +unsigned long flags; +int ret;Quoted 9 lines
drivers/infiniband/core/iwcm.c line 238
Quoted 6 lines
drivers/infiniband/core/iwcm.c new file +6
-0+ + cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); +/* Wait if we're currently in a connect or accept downcall. A +* listening endpoint should never block here. */ +wait_event (cm_id_priv->connect_wait, + !test_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags));Same question/comment as above.
Quoted 1 line
Same answer.
Quoted 7 lines
There's a difference between trying to handle the user calling disconnect/destroy at the same time a call to accept/connect is active, versus the user calling disconnect/destroy after accept/connect have returned. In the latter case, I think you're fine. In the first case, this is allowing a user to call destroy at the same time that they're calling accept/connect. Additionally, there's no guarantee that the
F_CONNECT_WAITflag has been set by accept/connect by the time disconnect/destroy tests it.
The problem is that we can't synchronously cancel an outstanding connect request. Once we've asked the adapter to connect, we can't tell him to stop, we have to wait for it to fail. During the time period between when we ask to connect and the adapter says yeah-or-nay, the user hits ctrl-C. This is the case where disconnect and/or destroy gets called and we have to block it waiting for the outstanding connect request to complete.
One alternative to this approach is to do the kfree of the cm_id in the deref logic. This was the original design and leaves the object around to handle the completion of the connect and still allows the app to clean up and go away without all this waitin' around. When the adapter finally finishes and releases it's reference, the object is kfree'd.
Hope this helps.
Quoted 8 lines
- Sean
_______________________________________________
openib-general mailing list
[email protected]
http://openib.org/mailman/listinfo/openib-generalTo unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general
Re: [openib-general] Re: [PATCH 1/2] iWARP Connection Manager.
In reply to Sean HeftyQuoted 61 lines · Sean Hefty
Quoted 7 lines · Steve Wise
drivers/infiniband/core/iwcm.c new file +7
-0+/* +* 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 ;drivers/infiniband/core/iwcm.c line 78
Quoted 10 lines
drivers/infiniband/core/iwcm.c new file +10
-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);We recently changed the RDMA CM, IB CM, and a couple of other modules from using
wait objects to completions. This avoids a race condition between decrementing
the reference count, which allows destruction to proceed, and callingwake_upon a freedcm_id. My guess is that you may need to do the same.Can you also explain the use of the return value here? It's ignored below in
rem_ref()anddestroy_cm_id().Quoted 34 lines
drivers/infiniband/core/iwcm.c new file +33
-0+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); +} + +/* +* 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);
Quoted 8 lines
drivers/infiniband/core/iwcm.c line 174
Quoted 3 lines
drivers/infiniband/core/iwcm.c new file +3
-0+/* 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));Am I understanding this check correctly? You're checking to see if the user has called
iw_cm_disconnect()at the same time that they callediw_cm_connect()oriw_cm_accept(). Are connect / accept blocking, or are you just waiting for an event?
Yes. The application (or the case I saw was user-mode exit logic after ctrl-C) cleaning up at random times relative to connection establishment.
Quoted 505 lines
Quoted 48 lines
drivers/infiniband/core/iwcm.c new file +47
-0+ +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 ); + } + +return ret; +} +EXPORT_SYMBOL (iw_cm_disconnect); +static void destroy_cm_id (struct iw_cm_id *cm_id)drivers/infiniband/core/iwcm.c line 238
Quoted 10 lines
drivers/infiniband/core/iwcm.c new file +10
-0+{ +struct iwcm_id_private *cm_id_priv; +unsigned long flags; +int ret; + + cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); +/* Wait if we're currently in a connect or accept downcall. A +* listening endpoint should never block here. */ +wait_event (cm_id_priv->connect_wait, + !test_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags));Same question/comment as above.
Quoted 26 lines
drivers/infiniband/core/iwcm.c new file +26
-0+ +spin_lock_irqsave (&cm_id_priv->lock, flags); +switch (cm_id_priv->state) { +case IW_CM_STATE_LISTEN : + cm_id_priv->state =IW_CM_STATE_DESTROYING ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +/* destroy the listening endpoint */ + ret = cm_id->device->iwcm->destroy_listen (cm_id); +break ; +case IW_CM_STATE_ESTABLISHED : + cm_id_priv->state =IW_CM_STATE_DESTROYING ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +/* Abrupt close of the connection */ + (void )iwcm_modify_qp_err (cm_id_priv->qp); +break ; +case IW_CM_STATE_IDLE : +case IW_CM_STATE_CLOSING : + cm_id_priv->state =IW_CM_STATE_DESTROYING ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +break ; +case IW_CM_STATE_CONN_RECV : +/* +* App called destroy before/without calling accept after +* receiving connection request event notification. +*/ + cm_id_priv->state =IW_CM_STATE_DESTROYING ;drivers/infiniband/core/iwcm.c line 274
Quoted 10 lines
drivers/infiniband/core/iwcm.c new file +10
-0+spin_unlock_irqrestore (&cm_id_priv->lock, flags); +break ; +case IW_CM_STATE_CONN_SENT : +case IW_CM_STATE_DESTROYING : +default : +BUG_ON (1 ); +break ; + } + +spin_lock_irqsave (&cm_id_priv->lock, flags);As an alternative, you could hold the lock from above, an let the LISTEN / ESTABLISHED state checks release and reacquire.
Quoted 95 lines
drivers/infiniband/core/iwcm.c new file +95
-0+if (cm_id_priv->qp) { + cm_id_priv->id.device->iwcm->rem_ref (cm_id_priv->qp); + cm_id_priv->qp =NULL ; + } +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + + (void )iwcm_deref_id (cm_id_priv); +} + +/* +* This function is only called by the application thread and cannot +* be called by the event thread. The function will wait for all +* references to be released on the cm_id and then kfree the cm_id +* object. +*/ +void iw_destroy_cm_id (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); +BUG_ON (test_bit (IWCM_F_CALLBACK_DESTROY , &cm_id_priv->flags)); + +destroy_cm_id (cm_id); + +wait_event (cm_id_priv->destroy_wait, + !atomic_read (&cm_id_priv->refcount)); + +kfree (cm_id_priv); +} +EXPORT_SYMBOL (iw_destroy_cm_id); + +/* +* CM_ID <-- LISTEN +* +* Start listening for connect requests. Generates one CONNECT_REQUEST +* event for each inbound connect request. +*/ +int iw_cm_listen (struct iw_cm_id *cm_id,int backlog) +{ +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); +spin_lock_irqsave (&cm_id_priv->lock, flags); +switch (cm_id_priv->state) { +case IW_CM_STATE_IDLE : + cm_id_priv->state =IW_CM_STATE_LISTEN ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + ret = cm_id->device->iwcm->create_listen (cm_id, backlog); +if (ret) + cm_id_priv->state =IW_CM_STATE_IDLE ; +break ; +default : +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + ret = -EINVAL ; + } + +return ret; +} +EXPORT_SYMBOL (iw_cm_listen); + +/* +* CM_ID <-- IDLE +* +* Rejects an inbound connection request. No events are generated. +*/ +int iw_cm_reject (struct iw_cm_id *cm_id, +const void *private_data, +u8 private_data_len) +{ +struct iwcm_id_private *cm_id_priv; +unsigned long flags; +int ret; + + cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); +set_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); + +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->state !=IW_CM_STATE_CONN_RECV ) { +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +wake_up_all (&cm_id_priv->connect_wait); +return -EINVAL ; + } + cm_id_priv->state =IW_CM_STATE_IDLE ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + + ret = cm_id->device->iwcm->reject (cm_id, private_data, + private_data_len); + +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +wake_up_all (&cm_id_priv->connect_wait); + +return ret;drivers/infiniband/core/iwcm.c line 379
Quoted 10 lines
drivers/infiniband/core/iwcm.c new file +10
-0+} +EXPORT_SYMBOL (iw_cm_reject); + +/* +* CM_ID <-- ESTABLISHED +* +* Accepts an inbound connection request and generates an ESTABLISHED +* event. Callers of iw_cm_disconnect and iw_destroy_cm_id will block +* until the ESTABLISHED event is received from the provider. +*/ This makes it sound like we're just waiting for an event.
Quoted 149 lines
drivers/infiniband/core/iwcm.c new file +149
-0+int iw_cm_accept (struct iw_cm_id *cm_id, +struct iw_cm_conn_param *iw_param) +{ +struct iwcm_id_private *cm_id_priv; +struct ib_qp *qp; +unsigned long flags; +int ret; + + cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); +set_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); + +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->state !=IW_CM_STATE_CONN_RECV ) { +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +wake_up_all (&cm_id_priv->connect_wait); +return -EINVAL ; + } +/* Get the ib_qp given the QPN */ + qp = cm_id->device->iwcm->get_qp (cm_id->device, iw_param->qpn); +if (!qp) { +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +return -EINVAL ; + } + cm_id->device->iwcm->add_ref (qp); + cm_id_priv->qp = qp; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + + ret = cm_id->device->iwcm->accept (cm_id, iw_param); +if (ret) { +/* An error on accept precludes provider events */ +BUG_ON (cm_id_priv->state !=IW_CM_STATE_CONN_RECV ); + cm_id_priv->state =IW_CM_STATE_IDLE ; +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->qp) { + cm_id->device->iwcm->rem_ref (qp); + cm_id_priv->qp =NULL ; + } +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +printk ("Accept failed, ret=%d\n" , ret); +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +wake_up_all (&cm_id_priv->connect_wait); + } + +return ret; +} +EXPORT_SYMBOL (iw_cm_accept); + +/* +* Active Side: CM_ID <-- CONN_SENT +* +* If successful, results in the generation of a CONNECT_REPLY +* event. iw_cm_disconnect and iw_cm_destroy will block until the +* CONNECT_REPLY event is received from the provider. +*/ +int iw_cm_connect (struct iw_cm_id *cm_id,struct iw_cm_conn_param *iw_param) +{ +struct iwcm_id_private *cm_id_priv; +int ret =0 ; +unsigned long flags; +struct ib_qp *qp; + + cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); +set_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); + +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->state !=IW_CM_STATE_IDLE ) { +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +wake_up_all (&cm_id_priv->connect_wait); +return -EINVAL ; + } + +/* Get the ib_qp given the QPN */ + qp = cm_id->device->iwcm->get_qp (cm_id->device, iw_param->qpn); +if (!qp) { +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +return -EINVAL ; + } + cm_id->device->iwcm->add_ref (qp); + cm_id_priv->qp = qp; + cm_id_priv->state =IW_CM_STATE_CONN_SENT ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + + ret = cm_id->device->iwcm->connect (cm_id, iw_param); +if (ret) { +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->qp) { + cm_id->device->iwcm->rem_ref (qp); + cm_id_priv->qp =NULL ; + } +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +BUG_ON (cm_id_priv->state !=IW_CM_STATE_CONN_SENT ); + cm_id_priv->state =IW_CM_STATE_IDLE ; +printk ("Connect failed, ret=%d\n" , ret); +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +wake_up_all (&cm_id_priv->connect_wait); + } + +return ret; +} +EXPORT_SYMBOL (iw_cm_connect); + +/* +* Passive Side: new CM_ID <-- CONN_RECV +* +* 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. +* +* An error on the child should not affect the parent, so this +* function does not return a value. +*/ +static void cm_conn_req_handler (struct iwcm_id_private *listen_id_priv, +struct iw_cm_event *iw_event) +{ +unsigned long flags; +struct iw_cm_id *cm_id; +struct iwcm_id_private *cm_id_priv; +int ret; + +/* The provider should never generate a connection request +* event with a bad status. +*/ +BUG_ON (iw_event->status); + +/* We could be destroying the listening id. If so, ignore this +* upcall. */ +spin_lock_irqsave (&listen_id_priv->lock, flags); +if (listen_id_priv->state !=IW_CM_STATE_LISTEN ) { +spin_unlock_irqrestore (&listen_id_priv->lock, flags); +return ; + } +spin_unlock_irqrestore (&listen_id_priv->lock, flags); + + cm_id =iw_create_cm_id (listen_id_priv->id.device, + listen_id_priv->id.cm_handler, + listen_id_priv->id.context); +/* If the cm_id could not be created, ignore the request */ +if (IS_ERR (cm_id)) +return ; + + cm_id->provider_data = iw_event->provider_data; + cm_id->local_addr = iw_event->local_addr;drivers/infiniband/core/iwcm.c line 538
Quoted 10 lines
drivers/infiniband/core/iwcm.c new file +10
-0+ cm_id->remote_addr = iw_event->remote_addr; + + cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); + cm_id_priv->state =IW_CM_STATE_CONN_RECV ; + +/* Call the client CM handler */ + ret = cm_id->cm_handler (cm_id, iw_event); +if (ret) { +printk ("destroying child id %p, ret=%d\n" , + cm_id, ret);We probably don't always want to print a message here.
Quoted 29 lines
drivers/infiniband/core/iwcm.c new file +29
-0+set_bit (IWCM_F_CALLBACK_DESTROY , &cm_id_priv->flags); +destroy_cm_id (cm_id); +if (atomic_read (&cm_id_priv->refcount)==0 ) +kfree (cm_id); + } +} + +/* +* Passive Side: CM_ID <-- ESTABLISHED +* +* The provider generated an ESTABLISHED event which means that +* the MPA negotion has completed successfully and we are now in MPA +* FPDU mode. +* +* This event can only be received in the CONN_RECV state. If the +* remote peer closed, the ESTABLISHED event would be received followed +* by the CLOSE event. If the app closes, it will block until we wake +* it up after processing this event. +*/ +static int cm_conn_est_handler (struct iwcm_id_private *cm_id_priv, +struct iw_cm_event *iw_event) +{ +unsigned long flags; +int ret =0 ; + +spin_lock_irqsave (&cm_id_priv->lock, flags); + +/* We clear the CONNECT_WAIT bit here to allow the callback +* function to call iw_cm_disconnect. Calling iw_destroy_cm_id drivers/infiniband/core/iwcm.c line 577
Quoted 10 lines
drivers/infiniband/core/iwcm.c new file +10
-0+* from a callback handler is not allowed */ +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +switch (cm_id_priv->state) { +case IW_CM_STATE_CONN_RECV : + cm_id_priv->state =IW_CM_STATE_ESTABLISHED ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + ret = cm_id_priv->id.cm_handler (&cm_id_priv->id, iw_event); +break ; +default : +BUG_ON (1 );Can just
BUG_ONthe state and avoid the switch. Same comment applies below.Quoted 72 lines
drivers/infiniband/core/iwcm.c new file +72
-0+ } +wake_up_all (&cm_id_priv->connect_wait); + +return ret; +} + +/* +* Active Side: CM_ID <-- ESTABLISHED +* +* The app has called connect and is waiting for the established event to +* post it's requests to the server. This event will wake up anyone +* blocked in iw_cm_disconnect or iw_destroy_id. +*/ +static int cm_conn_rep_handler (struct iwcm_id_private *cm_id_priv, +struct iw_cm_event *iw_event) +{ +unsigned long flags; +int ret =0 ; + +spin_lock_irqsave (&cm_id_priv->lock, flags); +/* Clear the connect wait bit so a callback function calling +* iw_cm_disconnect will not wait and deadlock this thread */ +clear_bit (IWCM_F_CONNECT_WAIT , &cm_id_priv->flags); +switch (cm_id_priv->state) { +case IW_CM_STATE_CONN_SENT : +if (iw_event->status ==IW_CM_EVENT_STATUS_ACCEPTED ) { + cm_id_priv->id.local_addr = iw_event->local_addr; + cm_id_priv->id.remote_addr = iw_event->remote_addr; + cm_id_priv->state =IW_CM_STATE_ESTABLISHED ; + }else { +/* REJECTED or RESET */ + cm_id_priv->id.device->iwcm->rem_ref (cm_id_priv->qp); + cm_id_priv->qp =NULL ; + cm_id_priv->state =IW_CM_STATE_IDLE ; + } +spin_unlock_irqrestore (&cm_id_priv->lock, flags); + ret = cm_id_priv->id.cm_handler (&cm_id_priv->id, iw_event); +break ; +default : +BUG_ON (1 ); + } +/* Wake up waiters on connect complete */ +wake_up_all (&cm_id_priv->connect_wait); + +return ret; +} + +/* +* CM_ID <-- CLOSING +* +* If in the ESTABLISHED state, move to CLOSING. +*/ +static void cm_disconnect_handler (struct iwcm_id_private *cm_id_priv, +struct iw_cm_event *iw_event) +{ +unsigned long flags; + +spin_lock_irqsave (&cm_id_priv->lock, flags); +if (cm_id_priv->state ==IW_CM_STATE_ESTABLISHED ) + cm_id_priv->state =IW_CM_STATE_CLOSING ; +spin_unlock_irqrestore (&cm_id_priv->lock, flags); +} + +/* +* CM_ID <-- IDLE +* +* If in the ESTBLISHED or CLOSING states, the QP will have have been +* moved by the provider to the ERR state. Disassociate the CM_ID from +* the QP, move to IDLE, and remove the 'connected' reference. +* +* If in some other state, the cm_id was destroyed asynchronously. +* This is the last reference that will result in waking up drivers/infiniband/core/iwcm.c line 659
Quoted 10 lines
drivers/infiniband/core/iwcm.c new file +10
-0+* the app thread blocked in iw_destroy_cm_id. +*/ +static int cm_close_handler (struct iwcm_id_private *cm_id_priv, +struct iw_cm_event *iw_event) +{ +unsigned long flags; +int ret =0 ; +/* TT */ printk ("%s:%d cm_id_priv=%p, state=%d\n" , + __FUNCTION__, __LINE__, + cm_id_priv,cm_id_priv->state);Will want to remove this.
- Sean
_______________________________________________
openib-general mailing list
[email protected]
http://openib.org/mailman/listinfo/openib-generalTo unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general
PATCH 2/2 iWARP Core Changes.
In reply to Steve WiseThis patch contains modifications to the existing rdma header files, core files, drivers, and ulp files to support iWARP.
---
drivers/infiniband/core/Makefile | 4 drivers/infiniband/core/addr.c | 8 - drivers/infiniband/core/cache.c | 8 - drivers/infiniband/core/cm.c | 3 drivers/infiniband/core/cma.c | 349 +++++++++++++++++++++++--- drivers/infiniband/core/device.c | 6 drivers/infiniband/core/mad.c | 11 + drivers/infiniband/core/sa_query.c | 5 drivers/infiniband/core/smi.c | 18 + drivers/infiniband/core/sysfs.c | 18 + drivers/infiniband/core/ucm.c | 5 drivers/infiniband/core/user_mad.c | 9 - drivers/infiniband/hw/ipath/ipath_verbs.c | 2 drivers/infiniband/hw/mthca/mthca_provider.c | 2 drivers/infiniband/ulp/ipoib/ipoib_main.c | 8 + drivers/infiniband/ulp/srp/ib_srp.c | 2 include/rdma/ib_addr.h | 15 + include/rdma/ib_verbs.h | 39 +++ 18 files changed, 427 insertions(+), 85 deletions(-)
drivers/infiniband/core/Makefile +3 -1
@@ -1,7 +1,7 @@ infiniband-$(CONFIG_INFINIBAND_ADDR_TRANS) := ib_addr.o rdma_cm.o obj-$(CONFIG_INFINIBAND) += ib_core.o ib_mad.o ib_sa.o \ - ib_cm.o $(infiniband-y) + ib_cm.o iw_cm.o $(infiniband-y) obj-$(CONFIG_INFINIBAND_USER_MAD) += ib_umad.o obj-$(CONFIG_INFINIBAND_USER_ACCESS) += ib_uverbs.o ib_ucm.o
@@ -14,6 +14,8 @@ ib_sa-y := sa_query.o ib_cm-y := cm.o +iw_cm-y := iwcm.o + rdma_cm-y := cma.o ib_addr-y := addr.o
drivers/infiniband/core/addr.c +6 -2
@@ -60,12 +60,15 @@ static LIST_HEAD(req_list); static DECLARE_WORK(work, process_req, NULL);static struct workqueue_struct *addr_wq; -static int copy_addr (struct rdma_dev_addr *dev_addr,struct net_device *dev, +int copy_addr (struct rdma_dev_addr *dev_addr,struct net_device *dev,unsigned char *dst_dev_addr) {switch (dev->type) {case ARPHRD_INFINIBAND : - dev_addr->dev_type =IB_NODE_CA ; + dev_addr->dev_type =RDMA_NODE_IB_CA ; +break ; +case ARPHRD_ETHER : + dev_addr->dev_type =RDMA_NODE_RNIC ;break ;default :return -EADDRNOTAVAIL ;
@@ -77,6 +80,7 @@ static int copy_addr(struct rdma_dev_addmemcpy (dev_addr->dst_dev_addr, dst_dev_addr,MAX_ADDR_LEN );return 0 ; } +EXPORT_SYMBOL (copy_addr);int rdma_translate_ip (struct sockaddr *addr,struct rdma_dev_addr *dev_addr) {
drivers/infiniband/core/cache.c +4 -4
@@ -32,13 +32,12 @@* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * -* $Id: cache.c 1349 2004-12-16 21:09:43Z roland $ +* $Id: cache.c 6885 2006-05-03 18:22:02Z sean.hefty $ */ #include <linux/module.h> #include <linux/errno.h> #include <linux/slab.h> -#include <linux/sched.h> /* INIT_WORK, schedule_work(), flush_scheduled_work() */ #include <rdma/ib_cache.h>
@@ -62,12 +61,13 @@ struct ib_update_work {static inline int start_port (struct ib_device *device) { -return device->node_type ==IB_NODE_SWITCH ?0 :1 ; +return (device->node_type ==RDMA_NODE_IB_SWITCH ) ?0 :1 ; }static inline int end_port (struct ib_device *device) { -return device->node_type ==IB_NODE_SWITCH ?0 : device->phys_port_cnt; +return (device->node_type ==RDMA_NODE_IB_SWITCH ) ? +0 : device->phys_port_cnt; } int ib_get_cached_gid(struct ib_device *device,
drivers/infiniband/core/cm.c +3 -0
@@ -3253,6 +3253,9 @@ static void cm_add_one(struct ib_deviceint ret;u8 i; +if (rdma_node_get_transport (device->node_type) !=RDMA_TRANSPORT_IB ) +return ; + cm_dev =kmalloc (sizeof (*cm_dev) +sizeof (*port) * device->phys_port_cnt,GFP_KERNEL );if (!cm_dev)
drivers/infiniband/core/cma.c +309 -40
526 lines not on this page · raw message
drivers/infiniband/core/device.c +3 -3
@@ -30,7 +30,7 @@* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * -* $Id: device.c 1349 2004-12-16 21:09:43Z roland $ +* $Id: device.c 5943 2006-03-22 00:58:04Z roland $ */ #include <linux/module.h>
@@ -505,7 +505,7 @@ int ib_query_port(struct ib_device *devi u8 port_num, struct ib_port_attr *port_attr) { -if (device->node_type ==IB_NODE_SWITCH ) { +if (device->node_type ==RDMA_NODE_IB_SWITCH ) {if (port_num)return -EINVAL ; }else if (port_num <1 || port_num > device->phys_port_cnt)
@@ -580,7 +580,7 @@ int ib_modify_port(struct ib_device *dev u8 port_num, int port_modify_mask, struct ib_port_modify *port_modify) { - if (device->node_type == IB_NODE_SWITCH) { + if (device->node_type == RDMA_NODE_IB_SWITCH) { if (port_num) return -EINVAL; } else if (port_num < 1 || port_num > device->phys_port_cnt)
drivers/infiniband/core/mad.c +7 -4
@@ -1,5 +1,5 @@/* -* Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved. +* Copyright (c) 2004-2006 Voltaire, Inc. All rights reserved. * Copyright (c) 2005 Intel Corporation. All rights reserved. * Copyright (c) 2005 Mellanox Technologies Ltd. All rights reserved. *
@@ -31,7 +31,7 @@* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * -* $Id: mad.c 5596 2006-03-03 01:00:07Z sean.hefty $ +* $Id: mad.c 7294 2006-05-17 18:12:30Z roland $ */ #include <linux/dma-mapping.h> #include <rdma/ib_cache.h>
@@ -2877,7 +2877,10 @@ static void ib_mad_init_device(struct ib {int start, end, i; -if (device->node_type ==IB_NODE_SWITCH ) { +if (rdma_node_get_transport (device->node_type) !=RDMA_TRANSPORT_IB ) +return ; + +if (device->node_type ==RDMA_NODE_IB_SWITCH ) { start =0 ; end =0 ; }else {
@@ -2924,7 +2927,7 @@ static void ib_mad_remove_device(struct {int i, num_ports, cur_port; -if (device->node_type ==IB_NODE_SWITCH ) { +if (device->node_type ==RDMA_NODE_IB_SWITCH ) { num_ports =1 ; cur_port =0 ; }else {
drivers/infiniband/core/sa_query.c +4 -1
@@ -887,7 +887,10 @@ static void ib_sa_add_one(struct ib_devistruct ib_sa_device *sa_dev;int s, e, i; -if (device->node_type ==IB_NODE_SWITCH ) +if (rdma_node_get_transport (device->node_type) !=RDMA_TRANSPORT_IB ) +return ; + +if (device->node_type ==RDMA_NODE_IB_SWITCH ) s = e =0 ;else { s =1 ;
drivers/infiniband/core/smi.c +9 -9
@@ -34,7 +34,7 @@* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * -* $Id: smi.c 1389 2004-12-27 22:56:47Z roland $ +* $Id: smi.c 5258 2006-02-01 20:32:40Z sean.hefty $ */ #include <rdma/ib_smi.h>
@@ -64,7 +64,7 @@ int smi_handle_dr_smp_send(struct ib_smp/* C14-9:2 */ if (hop_ptr && hop_ptr < hop_cnt) { -if (node_type !=IB_NODE_SWITCH ) +if (node_type !=RDMA_NODE_IB_SWITCH )return 0 ;/* smp->return_path set when received */
@@ -77,7 +77,7 @@ int smi_handle_dr_smp_send(struct ib_smpif (hop_ptr == hop_cnt) {/* smp->return_path set when received */ smp->hop_ptr++; -return (node_type ==IB_NODE_SWITCH || +return (node_type ==RDMA_NODE_IB_SWITCH || smp->dr_dlid ==IB_LID_PERMISSIVE ); }
@@ -95,7 +95,7 @@ int smi_handle_dr_smp_send(struct ib_smp/* C14-13:2 */ if (2 <= hop_ptr && hop_ptr <= hop_cnt) { -if (node_type !=IB_NODE_SWITCH ) +if (node_type !=RDMA_NODE_IB_SWITCH )return 0 ; smp->hop_ptr--;
@@ -107,7 +107,7 @@ int smi_handle_dr_smp_send(struct ib_smpif (hop_ptr ==1 ) { smp->hop_ptr--;/* C14-13:3 -- SMPs destined for SM shouldn't be here */ -return (node_type ==IB_NODE_SWITCH || +return (node_type ==RDMA_NODE_IB_SWITCH || smp->dr_slid ==IB_LID_PERMISSIVE ); }
@@ -142,7 +142,7 @@ int smi_handle_dr_smp_recv(struct ib_smp/* C14-9:2 -- intermediate hop */ if (hop_ptr && hop_ptr < hop_cnt) { -if (node_type !=IB_NODE_SWITCH ) +if (node_type !=RDMA_NODE_IB_SWITCH )return 0 ; smp->return_path[hop_ptr] = port_num;
@@ -156,7 +156,7 @@ int smi_handle_dr_smp_recv(struct ib_smp smp->return_path[hop_ptr] = port_num;/* smp->hop_ptr updated when sending */ -return (node_type ==IB_NODE_SWITCH || +return (node_type ==RDMA_NODE_IB_SWITCH || smp->dr_dlid ==IB_LID_PERMISSIVE ); }
@@ -175,7 +175,7 @@ int smi_handle_dr_smp_recv(struct ib_smp/* C14-13:2 */ if (2 <= hop_ptr && hop_ptr <= hop_cnt) { -if (node_type !=IB_NODE_SWITCH ) +if (node_type !=RDMA_NODE_IB_SWITCH )return 0 ;/* smp->hop_ptr updated when sending */
@@ -190,7 +190,7 @@ int smi_handle_dr_smp_recv(struct ib_smpreturn 1 ; }/* smp->hop_ptr updated when sending */ -return (node_type ==IB_NODE_SWITCH ); +return (node_type ==RDMA_NODE_IB_SWITCH ); }/* C14-13:4 -- hop_ptr = 0 -> give to SM */
drivers/infiniband/core/sysfs.c +12 -6
@@ -31,7 +31,7 @@* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * -* $Id: sysfs.c 1349 2004-12-16 21:09:43Z roland $ +* $Id: sysfs.c 6940 2006-05-04 17:04:55Z roland $ */ #include "core_priv.h"
@@ -589,10 +589,16 @@ static ssize_t show_node_type(struct clareturn -ENODEV ;switch (dev->node_type) { -case IB_NODE_CA :return sprintf (buf,"%d: CA\n" , dev->node_type); -case IB_NODE_SWITCH :return sprintf (buf,"%d: switch\n" , dev->node_type); -case IB_NODE_ROUTER :return sprintf (buf,"%d: router\n" , dev->node_type); -default :return sprintf (buf,"%d: <unknown>\n" , dev->node_type); +case RDMA_NODE_IB_CA : +return sprintf (buf,"%d: CA\n" , dev->node_type); +case RDMA_NODE_RNIC : +return sprintf (buf,"%d: RNIC\n" , dev->node_type); +case RDMA_NODE_IB_SWITCH : +return sprintf (buf,"%d: switch\n" , dev->node_type); +case RDMA_NODE_IB_ROUTER : +return sprintf (buf,"%d: router\n" , dev->node_type); +default : +return sprintf (buf,"%d: <unknown>\n" , dev->node_type); } }
@@ -708,7 +714,7 @@ int ib_device_register_sysfs(struct ib_dif (ret) goto err_put; -if (device->node_type ==IB_NODE_SWITCH ) { +if (device->node_type ==RDMA_NODE_IB_SWITCH ) { ret =add_port (device,0 );if (ret) goto err_put;
drivers/infiniband/core/ucm.c +3 -2
@@ -30,7 +30,7 @@* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * -* $Id: ucm.c 4311 2005-12-05 18:42:01Z sean.hefty $ +* $Id: ucm.c 7119 2006-05-11 16:40:38Z sean.hefty $ */ #include <linux/completion.h>
@@ -1248,7 +1248,8 @@ static void ib_ucm_add_one(struct ib_dev {struct ib_ucm_device *ucm_dev; -if (!device->alloc_ucontext) +if (!device->alloc_ucontext || +rdma_node_get_transport (device->node_type) !=RDMA_TRANSPORT_IB )return ; ucm_dev =kzalloc (sizeof *ucm_dev,GFP_KERNEL );
drivers/infiniband/core/user_mad.c +6 -3
@@ -1,6 +1,6 @@/* * Copyright (c) 2004 Topspin Communications. All rights reserved. -* Copyright (c) 2005 Voltaire, Inc. All rights reserved. +* Copyright (c) 2005-2006 Voltaire, Inc. All rights reserved. * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. * * This software is available to you under a choice of one of two
@@ -31,7 +31,7 @@* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * -* $Id: user_mad.c 5596 2006-03-03 01:00:07Z sean.hefty $ +* $Id: user_mad.c 6041 2006-03-27 21:06:00Z halr $ */ #include <linux/module.h>
@@ -967,7 +967,10 @@ static void ib_umad_add_one(struct ib_destruct ib_umad_device *umad_dev;int s, e, i; -if (device->node_type ==IB_NODE_SWITCH ) +if (rdma_node_get_transport (device->node_type) !=RDMA_TRANSPORT_IB ) +return ; + +if (device->node_type ==RDMA_NODE_IB_SWITCH ) s = e =0 ;else { s =1 ;
drivers/infiniband/hw/ipath/ipath_verbs.c +1 -1
@@ -984,7 +984,7 @@ static void *ipath_register_ib_device(in (1ull <<IB_USER_VERBS_CMD_QUERY_SRQ ) | (1ull <<IB_USER_VERBS_CMD_DESTROY_SRQ ) | (1ull <<IB_USER_VERBS_CMD_POST_SRQ_RECV ); - dev->node_type =IB_NODE_CA ; + dev->node_type =RDMA_NODE_IB_CA ; dev->phys_port_cnt =1 ; dev->dma_device =ipath_layer_get_device (dd); dev->class_dev.dev = dev->dma_device;
drivers/infiniband/hw/mthca/mthca_provider.c +1 -1
@@ -1273,7 +1273,7 @@ int mthca_register_device(struct mthca_d (1ull <<IB_USER_VERBS_CMD_MODIFY_SRQ ) | (1ull <<IB_USER_VERBS_CMD_QUERY_SRQ ) | (1ull <<IB_USER_VERBS_CMD_DESTROY_SRQ ); - dev->ib_dev.node_type =IB_NODE_CA ; + dev->ib_dev.node_type =RDMA_NODE_IB_CA ; dev->ib_dev.phys_port_cnt = dev->limits.num_ports; dev->ib_dev.dma_device = &dev->pdev->dev; dev->ib_dev.class_dev.dev = &dev->pdev->dev;
drivers/infiniband/ulp/ipoib/ipoib_main.c +7 -1
@@ -1084,13 +1084,16 @@ static void ipoib_add_one(struct ib_devistruct ipoib_dev_priv *priv;int s, e, p; +if (rdma_node_get_transport (device->node_type) !=RDMA_TRANSPORT_IB ) +return ; + dev_list =kmalloc (sizeof *dev_list,GFP_KERNEL );if (!dev_list)return ;INIT_LIST_HEAD (dev_list); -if (device->node_type ==IB_NODE_SWITCH ) { +if (device->node_type ==RDMA_NODE_IB_SWITCH ) { s =0 ; e =0 ; }else {
@@ -1114,6 +1117,9 @@ static void ipoib_remove_one(struct ib_dstruct ipoib_dev_priv *priv, *tmp;struct list_head *dev_list; +if (rdma_node_get_transport (device->node_type) !=RDMA_TRANSPORT_IB ) +return ; + dev_list =ib_get_client_data (device, &ipoib_client);list_for_each_entry_safe (priv, tmp, dev_list, list) {
drivers/infiniband/ulp/srp/ib_srp.c +1 -1
@@ -1845,7 +1845,7 @@ static void srp_add_one(struct ib_deviceif (IS_ERR (srp_dev->fmr_pool)) srp_dev->fmr_pool =NULL ; -if (device->node_type ==IB_NODE_SWITCH ) { +if (device->node_type ==RDMA_NODE_IB_SWITCH ) { s =0 ; e =0 ; }else {
include/rdma/ib_addr.h +14 -1
@@ -40,7 +40,7 @@ struct rdma_dev_addr {unsigned char src_dev_addr[MAX_ADDR_LEN ];unsigned char dst_dev_addr[MAX_ADDR_LEN ];unsigned char broadcast[MAX_ADDR_LEN ]; -enum ib_node_type dev_type; +enum rdma_node_type dev_type; };/**
@@ -72,6 +72,9 @@ int rdma_resolve_ip(struct sockaddr *srcvoid rdma_addr_cancel (struct rdma_dev_addr *addr); +int copy_addr (struct rdma_dev_addr *dev_addr,struct net_device *dev, +unsigned char *dst_dev_addr); +static inline int ip_addr_size (struct sockaddr *addr) { return addr->sa_family == AF_INET6 ?
@@ -111,4 +114,14 @@ static inline void ib_addr_set_dgid(stru memcpy(dev_addr->dst_dev_addr + 4, gid, sizeof *gid); } +static inline union ib_gid *iw_addr_get_sgid (struct rdma_dev_addr * rda) +{ +return (union ib_gid *)rda->src_dev_addr; +} + +static inline union ib_gid *iw_addr_get_dgid (struct rdma_dev_addr * rda) +{ +return (union ib_gid *)rda->dst_dev_addr; +} +#endif /* IB_ADDR_H */
include/rdma/ib_verbs.h +34 -5
@@ -35,7 +35,7 @@* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * -* $Id: ib_verbs.h 1349 2004-12-16 21:09:43Z roland $ +* $Id: ib_verbs.h 6885 2006-05-03 18:22:02Z sean.hefty $ */ #if !defined(IB_VERBS_H )
@@ -56,12 +56,35 @@ union ib_gid { } global; }; -enum ib_node_type { -IB_NODE_CA =1 , -IB_NODE_SWITCH , -IB_NODE_ROUTER +enum rdma_node_type { +/* IB values map to NodeInfo:NodeType. */ +RDMA_NODE_IB_CA =1 , +RDMA_NODE_IB_SWITCH , +RDMA_NODE_IB_ROUTER , +RDMA_NODE_RNIC }; +enum rdma_transport_type { +RDMA_TRANSPORT_IB , +RDMA_TRANSPORT_IWARP +}; + +static inline enum rdma_transport_type +rdma_node_get_transport (enum rdma_node_type node_type) +{ +switch (node_type) { +case RDMA_NODE_IB_CA : +case RDMA_NODE_IB_SWITCH : +case RDMA_NODE_IB_ROUTER : +return RDMA_TRANSPORT_IB ; +case RDMA_NODE_RNIC : +return RDMA_TRANSPORT_IWARP ; +default : +BUG (); +return 0 ; + } +} +enum ib_device_cap_flags {IB_DEVICE_RESIZE_MAX_WR =1 ,IB_DEVICE_BAD_PKEY_CNTR = (1 <<1 ),
@@ -78,6 +101,9 @@ enum ib_device_cap_flags {IB_DEVICE_RC_RNR_NAK_GEN = (1 <<12 ),IB_DEVICE_SRQ_RESIZE = (1 <<13 ),IB_DEVICE_N_NOTIFY_CQ = (1 <<14 ), +IB_DEVICE_ZERO_STAG = (1 <<15 ), +IB_DEVICE_SEND_W_INV = (1 <<16 ), +IB_DEVICE_MEM_WINDOW = (1 <<17 ) }; enum ib_atomic_cap {
@@ -830,6 +856,7 @@ struct ib_cache {u8 *lmc_cache; }; +struct iw_cm_verbs ;struct ib_device {struct device *dma_device;
@@ -846,6 +873,8 @@ struct ib_device {u32 flags; +struct iw_cm_verbs * iwcm; +int (*query_device)(struct ib_device *device,struct ib_device_attr *device_attr); int (*query_port)(struct ib_device *device,
Re: [PATCH 2/2] iWARP Core Changes.
Quoted 52 lines · On Wed, 31 May 2006 13:26:55 -0500 Steve Wise <[email protected]>…
This patch contains modifications to the existing rdma header files, core files, drivers, and ulp files to support iWARP.
---drivers/infiniband/core/Makefile | 4 drivers/infiniband/core/addr.c | 8 - drivers/infiniband/core/cache.c | 8 - drivers/infiniband/core/cm.c | 3 drivers/infiniband/core/cma.c | 349 +++++++++++++++++++++++--- drivers/infiniband/core/device.c | 6 drivers/infiniband/core/mad.c | 11 + drivers/infiniband/core/sa_query.c | 5 drivers/infiniband/core/smi.c | 18 + drivers/infiniband/core/sysfs.c | 18 + drivers/infiniband/core/ucm.c | 5 drivers/infiniband/core/user_mad.c | 9 - drivers/infiniband/hw/ipath/ipath_verbs.c | 2 drivers/infiniband/hw/mthca/mthca_provider.c | 2 drivers/infiniband/ulp/ipoib/ipoib_main.c | 8 + drivers/infiniband/ulp/srp/ib_srp.c | 2 include/rdma/ib_addr.h | 15 + include/rdma/ib_verbs.h | 39 +++ 18 files changed, 427 insertions(+), 85 deletions(-)drivers/infiniband/core/Makefile +3
-1@@ -1,7 +1,7 @@ infiniband-$(CONFIG_INFINIBAND_ADDR_TRANS) := ib_addr.o rdma_cm.o obj-$(CONFIG_INFINIBAND) += ib_core.o ib_mad.o ib_sa.o \ - ib_cm.o $(infiniband-y) + ib_cm.o iw_cm.o $(infiniband-y) obj-$(CONFIG_INFINIBAND_USER_MAD) += ib_umad.o obj-$(CONFIG_INFINIBAND_USER_ACCESS) += ib_uverbs.o ib_ucm.o@@ -14,6 +14,8 @@ ib_sa-y := sa_query.o ib_cm-y := cm.o +iw_cm-y := iwcm.o + rdma_cm-y := cma.o ib_addr-y := addr.odrivers/infiniband/core/addr.c +0
-0
drivers/infiniband/core/addr.c static LIST_HEAD(req_list); · line 64
Quoted 6 lines
drivers/infiniband/core/addr.c +1
-1@@ -60,12 +60,15 @@ static LIST_HEAD(req_list); static DECLARE_WORK(work, process_req, NULL);static struct workqueue_struct *addr_wq; -static int copy_addr (struct rdma_dev_addr *dev_addr,struct net_device *dev, +int copy_addr (struct rdma_dev_addr *dev_addr,struct net_device *dev,unsigned char *dst_dev_addr)
If you have to make this global choose a better name than 'copy_addr' and change dst_dev_addr to be const.
Re: [PATCH 2/2] iWARP Core Changes.
In reply to Steve WiseQuoted 1 line
+EXPORT_SYMBOL(copy_addr);
I think if you want to export this, it needs a less generic name (something with an rdma_ prefix probably). Otherwise it's going to collide someday...
Re: [PATCH 2/2] iWARP Core Changes.
Quoted 5 lines · Roland Dreier
Quoted 1 line
+EXPORT_SYMBOL(copy_addr);
I think if you want to export this, it needs a less generic name (something with an
rdma_prefix probably). Otherwise it's going to collide someday...
ok.
The function is needed by the iwcm module, so that's why we exported it. I could change the name to rdma_copy_addr(), or make the function a static inline in a header file since its kinda small anyway...
Any preference?
Re: [PATCH 2/2] iWARP Core Changes.
Steve> The function is needed by the iwcm module, so that's why we Steve> exported it. I could change the name to rdma_copy_addr(), Steve> or make the function a static inline in a header file since Steve> its kinda small anyway...
It looks too big to inline to me, and I don't think it's on a fast path anyway. So I would export it.
- R.
Re: [PATCH 2/2] iWARP Core Changes.
In reply to Steve WiseMainly nits...
drivers/infiniband/core/addr.c static LIST_HEAD(req_list); · line 64
Quoted 3 lines · Steve Wise
drivers/infiniband/core/addr.c +1
-1-static int copy_addr (struct rdma_dev_addr *dev_addr,struct net_device *dev, +int copy_addr (struct rdma_dev_addr *dev_addr,struct net_device *dev,unsigned char *dst_dev_addr)
Might want to rename this to something like rdma_copy_addr if you're going to export it.
Quoted 7 lines
drivers/infiniband/core/cma.c +7
-0+static int cma_iw_handler (struct iw_cm_id *iw_id,struct iw_cm_event *iw_event) +{ +struct rdma_id_private *id_priv = iw_id->context; +enum rdma_cm_event_type event =0 ; +struct sockaddr_in *sin; +int ret =0 ; +
drivers/infiniband/core/cma.c static void cma_set_compare_data(enum rd · line 1027
Quoted 10 lines
drivers/infiniband/core/cma.c +10
-0+atomic_inc (&id_priv->dev_remove); + +switch (iw_event->event) { +case IW_CM_EVENT_CLOSE : + event =RDMA_CM_EVENT_DISCONNECTED ; +break ; +case IW_CM_EVENT_CONNECT_REPLY : + sin = (struct sockaddr_in *)&id_priv->id.route.addr.src_addr; + *sin = iw_event->local_addr; + sin = (struct sockaddr_in *)&id_priv->id.route.addr.dst_addr;
spacing nit - (struct sockaddr_in *) &id_priv->...
Quoted 1 line
+struct
net_device*ip_dev_find(u32 ip);
Just include header file with definition.
drivers/infiniband/core/cma.c static void cma_set_compare_data(enum rd · line 1110
Quoted 3 lines
drivers/infiniband/core/cma.c +3
-0+ sin = (struct sockaddr_in *)&new_cm_id->route.addr.src_addr; + *sin = iw_event->local_addr; + sin = (struct sockaddr_in *)&new_cm_id->route.addr.dst_addr;
same spacing nit... appears in a couple other places as well.
include/rdma/ib_addr.h static inline void ib_addr_set_dgid(stru · line 125
Quoted 9 lines
include/rdma/ib_addr.h +9
-0+static inline union ib_gid *iw_addr_get_sgid (struct rdma_dev_addr * rda) +{ +return (union ib_gid *)rda->src_dev_addr; +} + +static inline union ib_gid *iw_addr_get_dgid (struct rdma_dev_addr * rda) +{ +return (union ib_gid *)rda->dst_dev_addr; +}
spacing nits
include/rdma/ib_verbs.h struct ib_device { · line 877
Quoted 10 lines
include/rdma/ib_verbs.h +3
-0+struct iw_cm_verbs ;struct ib_device {struct device *dma_device;@@ -846,6 +873,8 @@ struct ib_device {u32 flags; +struct iw_cm_verbs * iwcm; +
'*' placement nit
- Sean