FreeBSD/sys/dev/nxge/xgehal/xgehal-channel.c
/**
 * xge_hal_channel_close - Close communication channel.
 * @channelh: The channel handle.
 * @reopen: See  xge_hal_channel_reopen_e{}.
 *
 * Will close previously opened channel and deallocate associated resources.
 * Channel must be opened otherwise assert will be generated.
 * Note that free_channels list is not protected. i.e. caller must provide
 * safe context.
 */
Close communication channel.
@channelh: The channel handle.

Will close previously opened channel and deallocate associated resources.
Channel must be opened otherwise assert will be generated.
Note that free_channels list is not protected.
Close communication channel . @channelh : The channel handle . Will close previously opened channel and deallocate associated resources . Channel must be opened otherwise assert will be generated . Note that free_channels list is not protected .
void xge_hal_channel_close(xge_hal_channel_h channelh,
	                       xge_hal_channel_reopen_e reopen)
{
	xge_hal_channel_t *channel = (xge_hal_channel_t *)channelh;
	xge_hal_device_t *hldev;
	xge_list_t *item;
	xge_assert(channel);
	xge_assert(channel->type < XGE_HAL_CHANNEL_TYPE_MAX);
	hldev = (xge_hal_device_t *)channel->devh;
	channel->is_open = 0;
	channel->magic = XGE_HAL_DEAD;
	xge_list_for_each(item, &hldev->free_channels) {
	    xge_hal_channel_t *tmp;
	    tmp = xge_container_of(item, xge_hal_channel_t, item);
	    xge_assert(!tmp->is_open);
	    if (channel == tmp) {
	        return;
	    }
	}
	xge_hal_channel_abort(channel, reopen);
	xge_assert((channel->type == XGE_HAL_CHANNEL_TYPE_FIFO) ||
	       (channel->type == XGE_HAL_CHANNEL_TYPE_RING));
	if (reopen == XGE_HAL_CHANNEL_OC_NORMAL) {
	    switch(channel->type) {
	        case XGE_HAL_CHANNEL_TYPE_FIFO:
	            __hal_fifo_close(channelh);
	            break;
	        case XGE_HAL_CHANNEL_TYPE_RING:
	            __hal_ring_close(channelh);
	            break;
	        case XGE_HAL_CHANNEL_TYPE_SEND_QUEUE:
	        case XGE_HAL_CHANNEL_TYPE_RECEIVE_QUEUE:
	        case XGE_HAL_CHANNEL_TYPE_COMPLETION_QUEUE:
	        case XGE_HAL_CHANNEL_TYPE_UP_MESSAGE_QUEUE:
	        case XGE_HAL_CHANNEL_TYPE_DOWN_MESSAGE_QUEUE:
	            xge_assert(channel->type == XGE_HAL_CHANNEL_TYPE_FIFO ||
	                   channel->type == XGE_HAL_CHANNEL_TYPE_RING);
	            break;
	        default:
	            break;
	    }
	}
	else
	        xge_assert(reopen == XGE_HAL_CHANNEL_RESET_ONLY);
	xge_list_remove(&channel->item);
	xge_list_insert(&channel->item, &hldev->free_channels);
	if (xge_list_is_empty(&hldev->fifo_channels) &&
	    xge_list_is_empty(&hldev->ring_channels)) {
	    hldev->reset_needed_after_close = 1;
	}
}
void xge_hal_channel_close ( xge_hal_channel_h channelh , xge_hal_channel_reopen_e reopen ) { xge_hal_channel_t * channel = ( xge_hal_channel_t * ) channelh ; xge_hal_device_t * hldev ; xge_list_t * item ; xge_assert ( channel ) ; xge_assert ( channel -> type < XGE_HAL_CHANNEL_TYPE_MAX ) ; hldev = ( xge_hal_device_t * ) channel -> devh ; channel -> is_open = 0 ; channel -> magic = XGE_HAL_DEAD ; xge_list_for_each ( item , & hldev -> free_channels ) { xge_hal_channel_t * tmp ; tmp = xge_container_of ( item , xge_hal_channel_t , item ) ; xge_assert ( ! tmp -> is_open ) ; if ( channel == tmp ) { return ; } } xge_hal_channel_abort ( channel , reopen ) ; xge_assert ( ( channel -> type == XGE_HAL_CHANNEL_TYPE_FIFO ) || ( channel -> type == XGE_HAL_CHANNEL_TYPE_RING ) ) ; if ( reopen == XGE_HAL_CHANNEL_OC_NORMAL ) { switch ( channel -> type ) { case XGE_HAL_CHANNEL_TYPE_FIFO : __hal_fifo_close ( channelh ) ; break ; case XGE_HAL_CHANNEL_TYPE_RING : __hal_ring_close ( channelh ) ; break ; case XGE_HAL_CHANNEL_TYPE_SEND_QUEUE : case XGE_HAL_CHANNEL_TYPE_RECEIVE_QUEUE : case XGE_HAL_CHANNEL_TYPE_COMPLETION_QUEUE : case XGE_HAL_CHANNEL_TYPE_UP_MESSAGE_QUEUE : case XGE_HAL_CHANNEL_TYPE_DOWN_MESSAGE_QUEUE : xge_assert ( channel -> type == XGE_HAL_CHANNEL_TYPE_FIFO || channel -> type == XGE_HAL_CHANNEL_TYPE_RING ) ; break ; default : break ; } } else xge_assert ( reopen == XGE_HAL_CHANNEL_RESET_ONLY ) ; xge_list_remove ( & channel -> item ) ; xge_list_insert ( & channel -> item , & hldev -> free_channels ) ; if ( xge_list_is_empty ( & hldev -> fifo_channels ) && xge_list_is_empty ( & hldev -> ring_channels ) ) { hldev -> reset_needed_after_close = 1 ; } }
xge_hal_channel_close - Close communication channel.
xge_hal_channel_close - Close communication channel .
/* sanity check: make sure channel is not in free list */ /* de-allocate */ /* move channel back to free state list */ /* clear msix_idx in case of following HW reset */