Beispiel #1
0
/*
 * dapl_sp_free
 *
 * Free the passed in PSP structure.
 *
 * Input:
 * 	entry point pointer
 *
 * Output:
 * 	none
 *
 * Returns:
 * 	none
 *
 */
void
dapls_sp_free_sp(
	IN DAPL_SP *sp_ptr)
{
	dapl_os_assert(sp_ptr->header.magic == DAPL_MAGIC_PSP ||
	    sp_ptr->header.magic == DAPL_MAGIC_RSP);
	dapl_os_assert(dapl_llist_is_empty(&sp_ptr->cr_list_head));

	dapl_os_lock(&sp_ptr->header.lock);
	/* reset magic to prevent reuse */
	sp_ptr->header.magic = DAPL_MAGIC_INVALID;
	dapl_os_unlock(&sp_ptr->header.lock);
	dapl_os_free(sp_ptr, sizeof (DAPL_SP));
}
Beispiel #2
0
/*
 * dapl_cno_dealloc
 *
 * Free the passed in CNO structure.
 *
 * Input:
 * 	cno_ptr
 *
 * Output:
 * 	none
 *
 * Returns:
 * 	none
 *
 */
void
dapl_cno_dealloc(
    IN DAPL_CNO *cno_ptr)
{
	dapl_os_assert(cno_ptr->header.magic == DAPL_MAGIC_CNO);
	dapl_os_assert(cno_ptr->cno_ref_count == 0);

	/*
	 * deinitialize the header
	 */
	/* reset magic to prevent reuse */
	cno_ptr->header.magic = DAPL_MAGIC_INVALID;

	(void) dapl_os_wait_object_destroy(&cno_ptr->cno_wait_object);
	dapl_os_free(cno_ptr, sizeof (DAPL_CNO));
}
Beispiel #3
0
void *dapl_llist_peek_head(DAPL_LLIST_HEAD * head)
{
	DAPL_LLIST_ENTRY *first;

	dapl_os_assert(!dapl_llist_is_empty(head));
	first = *head;
	return (first->data);
}
Beispiel #4
0
/*
 * dapl_llist_remove_entry()
 *
 * Purpose: Remove the specified entry from a linked list
 */
void *dapl_llist_remove_entry(DAPL_LLIST_HEAD * head, DAPL_LLIST_ENTRY * entry)
{
	DAPL_LLIST_ENTRY *first;

	dapl_os_assert(!dapl_llist_is_empty(head));
	first = *head;

	/* if it's the first entry, pull it off */
	if (first == entry) {
		(*head) = first->flink;
		/* if it was the only entry, kill the list */
		if (first->flink == first) {
			(*head) = NULL;
		}
	}
#ifdef VERIFY_LINKED_LIST
	else {
		DAPL_LLIST_ENTRY *try_entry;

		try_entry = first->flink;
		for (;;) {
			if (try_entry == first) {
				/* not finding the element on the list is a BAD thing */
				dapl_os_assert(0);
				break;
			}
			if (try_entry == entry) {
				break;
			}
			try_entry = try_entry->flink;
		}
	}
#endif				/* VERIFY_LINKED_LIST */

	dapl_os_assert(entry->list_head == head);
	entry->list_head = NULL;

	entry->flink->blink = entry->blink;
	entry->blink->flink = entry->flink;
	entry->flink = NULL;
	entry->blink = NULL;

	return (entry->data);
}
Beispiel #5
0
void *dapl_llist_next_entry(IN DAPL_LLIST_HEAD * head,
			    IN DAPL_LLIST_ENTRY * cur_ent)
{
	DAPL_LLIST_ENTRY *next;

	dapl_os_assert(!dapl_llist_is_empty(head));
	if (cur_ent == NULL) {
		next = *head;
	} else {
		next = cur_ent->flink;
		if (next == *head) {
			return NULL;
		}
	}
	return (next->data);
}
Beispiel #6
0
/*
 * dapl_llist_remove_tail()
 *
 * Purpose: Remove the last entry of a linked list
 */
void *dapl_llist_remove_tail(DAPL_LLIST_HEAD * head)
{
	DAPL_LLIST_ENTRY *last;

	dapl_os_assert(!dapl_llist_is_empty(head));
	last = (*head)->blink;

	last->blink->flink = last->flink;
	last->flink->blink = last->blink;

	if (last->flink == last) {
		*head = NULL;
	}
	/* clean up the links for good measure */
	last->flink = NULL;
	last->blink = NULL;
	last->list_head = NULL;

	return (last->data);
}
Beispiel #7
0
/*
 * dapl_llist_remove_head()
 *
 * Purpose: Remove the first entry of a linked list
 */
void *dapl_llist_remove_head(DAPL_LLIST_HEAD * head)
{
	DAPL_LLIST_ENTRY *first;

	dapl_os_assert(!dapl_llist_is_empty(head));
	first = *head;
	*head = first->flink;

	first->flink->blink = first->blink;
	first->blink->flink = first->flink;

	if (first->flink == first) {
		*head = NULL;
	}
	/* clean up the links for good measure */
	first->flink = NULL;
	first->blink = NULL;
	first->list_head = NULL;
	return (first->data);
}
Beispiel #8
0
/*
 * dapls_cr_callback
 *
 * The callback function registered with verbs for passive side of
 * connection requests. The interface is specified by cm_api.h
 *
 *
 * Input:
 * 	ib_cm_handle,		Handle to CM
 * 	ib_cm_event		Specific CM event
 *	instant_data		Private data with DAT ADDRESS header
 * 	context			SP pointer
 *
 * Output:
 * 	None
 *
 */
void dapls_cr_callback(IN dp_ib_cm_handle_t ib_cm_handle, IN const ib_cm_events_t ib_cm_event,
                       IN const void *private_data_ptr, IN const int private_data_size,
                       IN const void *context)
{
	DAPL_EP *ep_ptr;
	DAPL_EVD *evd_ptr;
	DAPL_SP *sp_ptr;
	DAPL_PRIVATE *prd_ptr;
	DAT_EVENT_NUMBER dat_event_num;
	DAT_RETURN dat_status;

	dapl_dbg_log(DAPL_DBG_TYPE_CM | DAPL_DBG_TYPE_CALLBACK,
		     "--> dapl_cr_callback! context: %p event: %x cm_handle %p\n",
		     context, ib_cm_event, (void *)ib_cm_handle);

	/*
	 * Passive side of the connection, context is a SP and
	 * we need to look up the EP.
	 */
	sp_ptr = (DAPL_SP *) context;
	/*
	 * The context pointer could have been cleaned up in a racing
	 * CM callback, check to see if we should just exit here
	 */
	if (sp_ptr->header.magic == DAPL_MAGIC_INVALID) {
		return;
	}
	dapl_os_assert(sp_ptr->header.magic == DAPL_MAGIC_PSP ||
		       sp_ptr->header.magic == DAPL_MAGIC_RSP);

	/* Obtain the event number from the provider layer */
	dat_event_num = dapls_ib_get_dat_event(ib_cm_event, DAT_FALSE);

	/*
	 * CONNECT_REQUEST events create an event on the PSP
	 * EVD, which will trigger connection processing. The
	 * sequence is:
	 *    CONNECT_REQUEST         Event to SP
	 *    CONNECTED               Event to EP
	 *    DISCONNECT              Event to EP
	 *
	 * Obtain the EP if required and set an event up on the correct
	 * EVD.
	 */
	if (dat_event_num == DAT_CONNECTION_REQUEST_EVENT) {
		ep_ptr = NULL;
		evd_ptr = sp_ptr->evd_handle;
	} else {
		/* see if there is an EP connected with this CM handle */
		ep_ptr = dapli_get_sp_ep(ib_cm_handle, sp_ptr, dat_event_num);

		/* if we lost a race with the CM just exit. */
		if (ep_ptr == NULL) {
			return;
		}

		evd_ptr = (DAPL_EVD *) ep_ptr->param.connect_evd_handle;
		/* if something has happened to our EVD, bail. */
		if (evd_ptr == NULL) {
			return;
		}
	}

	prd_ptr = (DAPL_PRIVATE *) private_data_ptr;

	dat_status = DAT_INTERNAL_ERROR;	/* init to ERR */

	switch (dat_event_num) {
	case DAT_CONNECTION_REQUEST_EVENT:
		{
			/*
			 * Requests arriving on a disabled SP are immediatly rejected
			 */

			dapl_os_lock(&sp_ptr->header.lock);
			if (sp_ptr->listening == DAT_FALSE) {
				dapl_os_unlock(&sp_ptr->header.lock);
				dapl_log(DAPL_DBG_TYPE_CM_WARN,
					 " cr_callback: CR event on non-listening SP\n");
				(void)dapls_ib_reject_connection(ib_cm_handle,
								 DAT_CONNECTION_EVENT_UNREACHABLE,
								 0, NULL);

				return;
			}

			if (sp_ptr->header.handle_type == DAT_HANDLE_TYPE_RSP) {
				/*
				 * RSP connections only allow a single connection. Close
				 * it down NOW so we reject any further connections.
				 */
				sp_ptr->listening = DAT_FALSE;
			}
			dapl_os_unlock(&sp_ptr->header.lock);

			/*
			 * Only occurs on the passive side of a connection
			 * dapli_connection_request will post the connection
			 * event if appropriate.
			 */
			dat_status = dapli_connection_request(ib_cm_handle,
							      sp_ptr, prd_ptr, private_data_size, evd_ptr);
			/* Set evd_ptr = NULL so we don't generate an event below */
			evd_ptr = NULL;

			break;
		}
	case DAT_CONNECTION_EVENT_ESTABLISHED:
		{
			/* This is just a notification the connection is now
			 * established, there isn't any private data to deal with.
			 *
			 * Update the EP state and cache a copy of the cm handle,
			 * then let the user know we are ready to go.
			 */
			dapl_os_lock(&ep_ptr->header.lock);
			if (ep_ptr->header.magic != DAPL_MAGIC_EP ||
			    ep_ptr->param.ep_state !=
			    DAT_EP_STATE_COMPLETION_PENDING) {
				/* If someone pulled the plug on the EP or connection,
				 * just exit
				 */
				dapl_os_unlock(&ep_ptr->header.lock);
				dat_status = DAT_SUCCESS;
				/* Set evd_ptr = NULL so we don't generate an event below */
				evd_ptr = NULL;

				break;
			}

			ep_ptr->param.ep_state = DAT_EP_STATE_CONNECTED;
			dapl_os_unlock(&ep_ptr->header.lock);

			break;
		}
	case DAT_CONNECTION_EVENT_DISCONNECTED:
		{
			/*
			 * EP is now fully disconnected; initiate any post processing
			 * to reset the underlying QP and get the EP ready for
			 * another connection
			 */
			dapl_os_lock(&ep_ptr->header.lock);
			if (ep_ptr->param.ep_state == DAT_EP_STATE_DISCONNECTED) {
				/* The disconnect has already occurred, we are now
				 * cleaned up and ready to exit
				 */
				dapl_os_unlock(&ep_ptr->header.lock);
				return;
			}
			ep_ptr->param.ep_state = DAT_EP_STATE_DISCONNECTED;
			dapls_ib_disconnect_clean(ep_ptr, DAT_FALSE,
						  ib_cm_event);
			dapl_os_unlock(&ep_ptr->header.lock);

			break;
		}
	case DAT_CONNECTION_EVENT_NON_PEER_REJECTED:
	case DAT_CONNECTION_EVENT_PEER_REJECTED:
	case DAT_CONNECTION_EVENT_UNREACHABLE:
		{
			/*
			 * After posting an accept the requesting node has
			 * stopped talking.
			 */
			dapl_os_lock(&ep_ptr->header.lock);
			ep_ptr->param.ep_state = DAT_EP_STATE_DISCONNECTED;
			dapls_ib_disconnect_clean(ep_ptr, DAT_FALSE,
						  ib_cm_event);
			dapl_os_unlock(&ep_ptr->header.lock);

			break;
		}
	case DAT_CONNECTION_EVENT_BROKEN:
		{
			dapl_os_lock(&ep_ptr->header.lock);
			ep_ptr->param.ep_state = DAT_EP_STATE_DISCONNECTED;
			dapls_ib_disconnect_clean(ep_ptr, DAT_FALSE,
						  ib_cm_event);
			dapl_os_unlock(&ep_ptr->header.lock);

			break;
		}
	default:
		{
			evd_ptr = NULL;
			dapl_os_assert(0);	/* shouldn't happen */
			break;
		}
	}

	if (evd_ptr != NULL) {
		dat_status = dapls_evd_post_connection_event(evd_ptr,
							     dat_event_num,
							     (DAT_HANDLE)
							     ep_ptr, 0, NULL);
	}

	if (dat_status != DAT_SUCCESS) {
		/* The event post failed; take appropriate action.  */
		(void)dapls_ib_reject_connection(ib_cm_handle,
						 DAT_CONNECTION_EVENT_BROKEN,
						 0, NULL);

		return;
	}
}
Beispiel #9
0
/*
 * dapli_connection_request
 *
 * Process a connection request on the Passive side of a connection.
 * Create a CR record and link it on to the SP so we can update it
 * and free it later. Create an EP if specified by the PSP flags.
 *
 * Input:
 * 	ib_cm_handle,
 * 	sp_ptr
 * 	event_ptr
 *	prd_ptr
 *
 * Output:
 * 	None
 *
 * Returns
 *	DAT_INSUFFICIENT_RESOURCES
 *	DAT_SUCCESS
 *
 */
DAT_RETURN
dapli_connection_request(IN dp_ib_cm_handle_t ib_cm_handle,
			 IN DAPL_SP * sp_ptr,
			 IN DAPL_PRIVATE * prd_ptr, IN int private_data_size,
			 IN DAPL_EVD * evd_ptr)
{
	DAT_RETURN dat_status;

	DAPL_CR *cr_ptr;
	DAPL_EP *ep_ptr;
	DAPL_IA *ia_ptr;
	DAT_SP_HANDLE sp_handle;

	cr_ptr = dapls_cr_alloc(sp_ptr->header.owner_ia);
	if (cr_ptr == NULL) {
		/* Invoking function will call dapls_ib_cm_reject() */
		return DAT_INSUFFICIENT_RESOURCES;
	}

	/*
	 * Set up the CR
	 */
	cr_ptr->sp_ptr = sp_ptr;	/* maintain sp_ptr in case of reject */
	cr_ptr->param.remote_port_qual = 0;
	cr_ptr->ib_cm_handle = ib_cm_handle;
#ifdef IBHOSTS_NAMING
	/*
	 * Special case: pull the remote HCA address from the private data
	 * prefix. This is a spec violation as it introduces a protocol, but
	 * some implementations may find it necessary for a time.
	 */
	cr_ptr->remote_ia_address = prd_ptr->hca_address;
#endif				/* IBHOSTS_NAMING */
	cr_ptr->param.remote_ia_address_ptr =
	    (DAT_IA_ADDRESS_PTR) & cr_ptr->remote_ia_address;
	/*
	 * Copy the remote address and private data out of the private_data
	 * payload and put them in a local structure
	 */

	/* Private data size will be determined by the provider layer */
	cr_ptr->param.private_data = cr_ptr->private_data;
	cr_ptr->param.private_data_size = private_data_size;
	if (cr_ptr->param.private_data_size > 0) {
		dapl_os_memcpy(cr_ptr->private_data,
			       prd_ptr->private_data,
			       DAPL_MIN(cr_ptr->param.private_data_size,
					DAPL_MAX_PRIVATE_DATA_SIZE));
	}

	/* EP will be NULL unless RSP service point */
	ep_ptr = (DAPL_EP *) sp_ptr->ep_handle;

	if (sp_ptr->psp_flags == DAT_PSP_PROVIDER_FLAG) {
		/*
		 * Never true for RSP connections
		 *
		 * Create an EP for the user. If we can't allocate an
		 * EP we are out of resources and need to tell the
		 * requestor that we cant help them.
		 */
		ia_ptr = sp_ptr->header.owner_ia;
		ep_ptr = dapl_ep_alloc(ia_ptr, NULL);
		if (ep_ptr == NULL) {
			dapls_cr_free(cr_ptr);
			/* Invoking function will call dapls_ib_cm_reject() */
			return DAT_INSUFFICIENT_RESOURCES;
		}
		ep_ptr->param.ia_handle = ia_ptr;
		ep_ptr->param.local_ia_address_ptr =
		    (DAT_IA_ADDRESS_PTR) & ia_ptr->hca_ptr->hca_address;

		/* Link the EP onto the IA */
		dapl_ia_link_ep(ia_ptr, ep_ptr);
	}

	cr_ptr->param.local_ep_handle = ep_ptr;

	if (ep_ptr != NULL) {
		/* Assign valid EP fields: RSP and PSP_PROVIDER_FLAG only */
		if (sp_ptr->psp_flags == DAT_PSP_PROVIDER_FLAG) {
			ep_ptr->param.ep_state =
			    DAT_EP_STATE_TENTATIVE_CONNECTION_PENDING;
		} else {
			/* RSP */
			dapl_os_assert(sp_ptr->header.handle_type ==
				       DAT_HANDLE_TYPE_RSP);
			ep_ptr->param.ep_state =
			    DAT_EP_STATE_PASSIVE_CONNECTION_PENDING;
		}
		dapl_ep_link_cm(ep_ptr, ib_cm_handle);
	}

	/* link the CR onto the SP so we can pick it up later */
	dapl_sp_link_cr(sp_ptr, cr_ptr);

	/* Post the event.  */
	/* assign sp_ptr to union to avoid typecast errors from some compilers */
	sp_handle.psp_handle = (DAT_PSP_HANDLE) sp_ptr;

	dat_status = dapls_evd_post_cr_arrival_event(evd_ptr,
						     DAT_CONNECTION_REQUEST_EVENT,
						     sp_handle,
						     (DAT_IA_ADDRESS_PTR)
						     & sp_ptr->header.owner_ia->
						     hca_ptr->hca_address,
						     sp_ptr->conn_qual,
						     (DAT_CR_HANDLE) cr_ptr);

	if (dat_status != DAT_SUCCESS) {
		(void)dapls_ib_reject_connection(ib_cm_handle,
						 DAT_CONNECTION_EVENT_BROKEN,
						 0, NULL);

		/* Take the CR off the list, we can't use it */
		dapl_os_lock(&sp_ptr->header.lock);
		dapl_sp_remove_cr(sp_ptr, cr_ptr);
		dapl_os_unlock(&sp_ptr->header.lock);
		dapls_cr_free(cr_ptr);
		return DAT_INSUFFICIENT_RESOURCES;
	}

	return DAT_SUCCESS;
}
Beispiel #10
0
DAT_RETURN dapl_evd_resize(
	IN	DAT_EVD_HANDLE	   evd_handle,
	IN	DAT_COUNT	   req_evd_qlen)
{
	int			i;
	DAPL_EVD		*evd_ptr;
	DAT_EVENT		*event_ptr;
	DAT_EVENT		*eventp;
	DAT_EVENT		*event;
	DAT_EVENT		*new_event;
	DAPL_RING_BUFFER	free_event_queue;
	DAPL_RING_BUFFER	pending_event_queue;
	DAT_RETURN		dat_status;
	DAT_COUNT		max_evd_qlen;
	DAT_COUNT		evd_qlen;

	evd_ptr = (DAPL_EVD *)evd_handle;
	dat_status = DAT_SUCCESS;

	if (DAPL_BAD_HANDLE(evd_handle, DAPL_MAGIC_EVD)) {
		return (DAT_ERROR(DAT_INVALID_HANDLE, 0));
	}

	if (req_evd_qlen < evd_ptr->qlen) {
		return (DAT_ERROR(DAT_INVALID_STATE, 0));
	}

	if (req_evd_qlen == evd_ptr->qlen) {
		return (DAT_SUCCESS);
	}

	max_evd_qlen = evd_ptr->header.owner_ia->hca_ptr->ia_attr.max_evd_qlen;
	if (req_evd_qlen > max_evd_qlen) {
		return (DAT_ERROR(DAT_INVALID_STATE, 0));
	}

	evd_qlen = DAPL_MIN_RESZ_QLEN;
	while (req_evd_qlen > evd_qlen) {
		evd_qlen <<= 1;
		if (evd_qlen > max_evd_qlen)
			evd_qlen = max_evd_qlen;
	}

	/* Allocate EVENTs */
	event_ptr = (DAT_EVENT *) dapl_os_alloc(evd_qlen * sizeof (DAT_EVENT));
	if (!event_ptr) {
		return (DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
		    DAT_RESOURCE_MEMORY));
	}

	/* allocate free event queue */
	dat_status = dapls_rbuf_alloc(&free_event_queue, evd_qlen);
	if (dat_status != DAT_SUCCESS) {
		goto bail;
	}

	/* allocate pending event queue */
	dat_status = dapls_rbuf_alloc(&pending_event_queue, evd_qlen);
	if (dat_status != DAT_SUCCESS) {
		goto bail;
	}

	/* need to resize the cq only for DTO/BIND evds */
	if (0 != (evd_ptr->evd_flags & ~ (DAT_EVD_SOFTWARE_FLAG |
	    DAT_EVD_CONNECTION_FLAG | DAT_EVD_CR_FLAG))) {
		dat_status = dapls_ib_cq_resize(evd_ptr, evd_qlen);
		if (dat_status != DAT_SUCCESS)
			goto bail;
	}

	/* add events to free event queue */
	for (i = 0, eventp = event_ptr; i < evd_qlen; i++) {
		(void) dapls_rbuf_add(&free_event_queue, (void *)eventp);
		eventp++;
	}
	/*
	 * copy pending events from evd to the new pending event queue
	 */
	while (event = (DAT_EVENT *)
	    dapls_rbuf_remove(&evd_ptr->pending_event_queue)) {
		new_event = (DAT_EVENT *) dapls_rbuf_remove(&free_event_queue);
		dapl_os_assert(new_event);
		(void) dapl_os_memcpy(new_event, event, sizeof (DAT_EVENT));
		dat_status = dapls_rbuf_add(&pending_event_queue, new_event);
		dapl_os_assert(dat_status == DAT_SUCCESS);
		dat_status = dapls_rbuf_add(&evd_ptr->free_event_queue, event);
		dapl_os_assert(dat_status == DAT_SUCCESS);
	}

	dapls_rbuf_destroy(&evd_ptr->free_event_queue);
	dapls_rbuf_destroy(&evd_ptr->pending_event_queue);
	if (evd_ptr->events) {
		dapl_os_free(evd_ptr->events,
		    evd_ptr->qlen * sizeof (DAT_EVENT));
	}
	evd_ptr->events = event_ptr;
	evd_ptr->free_event_queue = free_event_queue;
	evd_ptr->pending_event_queue = pending_event_queue;
	evd_ptr->qlen = evd_qlen;

	return (DAT_SUCCESS);
bail:
	/*
	 * If we are here means event_ptr was allocd but something else
	 * failed
	 */
	dapl_os_free(event_ptr, evd_qlen * sizeof (DAT_EVENT));
	dapls_rbuf_destroy(&free_event_queue);
	dapls_rbuf_destroy(&pending_event_queue);

	return (dat_status);
}
void
dapl_evd_connection_callback(
    IN    ib_cm_handle_t	ib_cm_handle,
    IN    const ib_cm_events_t  ib_cm_event,
    IN	  const void 		*private_data_ptr,
    IN    const void		*context)
{
	DAPL_EP		*ep_ptr;
	DAPL_EVD	*evd_ptr;
	DAPL_PRIVATE	*prd_ptr;
	DAT_EVENT_NUMBER event_type;

	dapl_dbg_log(
	    DAPL_DBG_TYPE_CM | DAPL_DBG_TYPE_CALLBACK,
	    "--> dapl_evd_connection_callback: ctxt: %p event: %x"
	    " cm_handle %p\n",
	    context,
	    ib_cm_event,
	    ib_cm_handle);

	/*
	 * Determine the type of handle passed back to us in the context
	 * and sort out key parameters.
	 */
	dapl_os_assert(((DAPL_HEADER *)context)->magic == DAPL_MAGIC_EP ||
	    ((DAPL_HEADER *)context)->magic == DAPL_MAGIC_EP_EXIT);
	/*
	 * Active side of the connection, context is an EP and
	 * PSP is irrelevant.
	 */
	ep_ptr  = (DAPL_EP *)context;
	evd_ptr = (DAPL_EVD *)ep_ptr->param.connect_evd_handle;

	prd_ptr = (DAPL_PRIVATE *)private_data_ptr;

	switch (ib_cm_event) {
	case IB_CME_CONNECTED:
	{
		/*
		 * If we don't have an EP at this point we are very screwed
		 * up
		 */
		DAT_RETURN dat_status;

		if (ep_ptr->param.ep_state == DAT_EP_STATE_DISCONNECT_PENDING) {
			/*
			 * If someone pulled the plug on the connection, just
			 * exit
			 */
			break;
		}
		dapls_ib_connected(ep_ptr);
		ep_ptr->param.ep_state	= DAT_EP_STATE_CONNECTED;
		ep_ptr->cm_handle	= ib_cm_handle;
		/* copy in the private data */
		(void) dapl_os_memcpy(ep_ptr->private_data,
		    prd_ptr->private_data,
		    IB_MAX_REQ_PDATA_SIZE);

		dat_status = dapls_evd_post_connection_event(
		    evd_ptr,
		    DAT_CONNECTION_EVENT_ESTABLISHED,
		    (DAT_HANDLE) ep_ptr,
		    IB_MAX_REQ_PDATA_SIZE,
		    ep_ptr->private_data);

		if (dat_status != DAT_SUCCESS) {
			(void) dapls_ib_disconnect(ep_ptr,
			    DAT_CLOSE_ABRUPT_FLAG);
			ep_ptr->param.ep_state =
			    DAT_EP_STATE_DISCONNECT_PENDING;
		}

		/*
		 * If we received any premature DTO completions and
		 * post them to the recv evd now.
		 * there is a race here - if events arrive after we change
		 * the ep state to connected and before we process premature
		 * events
		 */
		dapls_evd_post_premature_events(ep_ptr);

		break;
	}
	case IB_CME_DISCONNECTED:
	case IB_CME_DISCONNECTED_ON_LINK_DOWN:
	{
		/*
		 * EP is now fully disconnected; initiate any post processing
		 * to reset the underlying QP and get the EP ready for
		 * another connection
		 */
		if (ep_ptr->param.ep_state  == DAT_EP_STATE_DISCONNECTED) {
			/* DTO error caused this */
			event_type = DAT_CONNECTION_EVENT_BROKEN;
		} else {
			ep_ptr->param.ep_state  = DAT_EP_STATE_DISCONNECTED;
			dapls_ib_disconnect_clean(ep_ptr, DAT_TRUE,
			    ib_cm_event);
			event_type = DAT_CONNECTION_EVENT_DISCONNECTED;
		}

		/* If the EP has been freed, the evd_ptr will be NULL */
		if (evd_ptr != NULL) {
			(void) dapls_evd_post_connection_event(
			    evd_ptr, event_type, (DAT_HANDLE) ep_ptr, 0, 0);
		}

		/*
		 * If the user has done an ep_free of the EP, we have been
		 * waiting for the disconnect event; just clean it up now.
		 */
		if (ep_ptr->header.magic == DAPL_MAGIC_EP_EXIT) {
			(void) dapl_ep_free(ep_ptr);
		}
		break;
	}
	case IB_CME_DESTINATION_REJECT_PRIVATE_DATA:
	{
		ep_ptr->param.ep_state  = DAT_EP_STATE_DISCONNECTED;
		dapls_ib_disconnect_clean(ep_ptr, DAT_TRUE, ib_cm_event);
		(void) dapls_evd_post_connection_event(
		    evd_ptr,
		    DAT_CONNECTION_EVENT_PEER_REJECTED,
		    (DAT_HANDLE) ep_ptr,
		    0,
		    0);
		break;
	}
	case IB_CME_DESTINATION_UNREACHABLE:
	{
		ep_ptr->param.ep_state  = DAT_EP_STATE_DISCONNECTED;
		dapls_ib_disconnect_clean(ep_ptr, DAT_TRUE, ib_cm_event);
		(void) dapls_evd_post_connection_event(
		    evd_ptr,
		    DAT_CONNECTION_EVENT_UNREACHABLE,
		    (DAT_HANDLE) ep_ptr,
		    0,
		    0);
		break;
	}
	case IB_CME_DESTINATION_REJECT:
	case IB_CME_TOO_MANY_CONNECTION_REQUESTS:
	case IB_CME_LOCAL_FAILURE:
	{
		ep_ptr->param.ep_state  = DAT_EP_STATE_DISCONNECTED;
		dapls_ib_disconnect_clean(ep_ptr, DAT_TRUE, ib_cm_event);
		(void) dapls_evd_post_connection_event(
		    evd_ptr,
		    DAT_CONNECTION_EVENT_NON_PEER_REJECTED,
		    (DAT_HANDLE) ep_ptr,
		    0,
		    0);
		break;
	}
	case IB_CME_TIMED_OUT:
	{
		ep_ptr->param.ep_state  = DAT_EP_STATE_DISCONNECTED;
		dapls_ib_disconnect_clean(ep_ptr, DAT_TRUE, ib_cm_event);
		(void) dapls_evd_post_connection_event(
		    evd_ptr,
		    DAT_CONNECTION_EVENT_TIMED_OUT,
		    (DAT_HANDLE) ep_ptr,
		    0,
		    0);
		break;
	}
	case IB_CME_CONNECTION_REQUEST_PENDING:
	case IB_CME_CONNECTION_REQUEST_PENDING_PRIVATE_DATA:
	default:
	{
		dapl_os_assert(0);		/* shouldn't happen */
		break;
	}
	}

	dapl_dbg_log(DAPL_DBG_TYPE_CM | DAPL_DBG_TYPE_CALLBACK,
	    "dapl_evd_connection_callback () returns\n");

}
Beispiel #12
0
/*
 * dapl_cno_wait
 *
 * DAPL Requirements Version xxx, 6.3.2.3
 *
 * Wait for a consumer notification event
 *
 * Input:
 *	cno_handle
 *	timeout
 *	evd_handle
 *
 * Output:
 *	evd_handle
 *
 * Returns:
 *	DAT_SUCCESS
 *	DAT_INVALID_HANDLE
 *	DAT_QUEUE_EMPTY
 *	DAT_INVALID_PARAMETER
 */
DAT_RETURN DAT_API dapl_cno_wait(IN DAT_CNO_HANDLE cno_handle,	/* cno_handle */
				 IN DAT_TIMEOUT timeout,	/* agent */
				 OUT DAT_EVD_HANDLE * evd_handle)
{				/* ia_handle */
	DAPL_CNO *cno_ptr;
	DAT_RETURN dat_status;

	if (DAPL_BAD_HANDLE(cno_handle, DAPL_MAGIC_CNO)) {
		dat_status = DAT_INVALID_HANDLE | DAT_INVALID_HANDLE_CNO;
		goto bail;
	}

	dat_status = DAT_SUCCESS;

	cno_ptr = (DAPL_CNO *) cno_handle;

	if (cno_ptr->cno_state == DAPL_CNO_STATE_DEAD) {
		dat_status =
		    DAT_ERROR(DAT_INVALID_STATE, DAT_INVALID_STATE_CNO_DEAD);
		goto bail;
	}

	dapl_os_lock(&cno_ptr->header.lock);
	if (cno_ptr->cno_state == DAPL_CNO_STATE_TRIGGERED) {
		cno_ptr->cno_state = DAPL_CNO_STATE_UNTRIGGERED;
		*evd_handle = cno_ptr->cno_evd_triggered;
		cno_ptr->cno_evd_triggered = NULL;
		dapl_os_unlock(&cno_ptr->header.lock);
		goto bail;
	}

	while (cno_ptr->cno_state == DAPL_CNO_STATE_UNTRIGGERED
	       && DAT_GET_TYPE(dat_status) != DAT_TIMEOUT_EXPIRED) {
		cno_ptr->cno_waiters++;
		dapl_os_unlock(&cno_ptr->header.lock);
		dat_status = dapl_os_wait_object_wait(&cno_ptr->cno_wait_object,
						      timeout);
		dapl_os_lock(&cno_ptr->header.lock);
		cno_ptr->cno_waiters--;
	}

	if (cno_ptr->cno_state == DAPL_CNO_STATE_DEAD) {
		dat_status =
		    DAT_ERROR(DAT_INVALID_STATE, DAT_INVALID_STATE_CNO_DEAD);
	} else if (dat_status == DAT_SUCCESS) {
		/*
		 * After the first triggering, this will be a valid handle.
		 * If we're racing with wakeups of other CNO waiters,
		 * that's ok.
		 */
		dapl_os_assert(cno_ptr->cno_state == DAPL_CNO_STATE_TRIGGERED);
		cno_ptr->cno_state = DAPL_CNO_STATE_UNTRIGGERED;
		*evd_handle = cno_ptr->cno_evd_triggered;
		cno_ptr->cno_evd_triggered = NULL;
	} else if (DAT_GET_TYPE(dat_status) == DAT_TIMEOUT_EXPIRED) {
		cno_ptr->cno_state = DAPL_CNO_STATE_UNTRIGGERED;
		*evd_handle = NULL;
		dat_status = DAT_QUEUE_EMPTY;
	} else {
		/*
		 * The only other reason we could have made it out of
		 * the loop is an interrupted system call.
		 */
		dapl_os_assert(DAT_GET_TYPE(dat_status) ==
			       DAT_INTERRUPTED_CALL);
	}
	dapl_os_unlock(&cno_ptr->header.lock);

      bail:
	return dat_status;
}