FreeBSD/sys/dev/ntb/if_ntb/if_ntb.c
/**
 * ntb_transport_create_queue - Create a new NTB transport layer queue
 * @rx_handler: receive callback function
 * @tx_handler: transmit callback function
 * @event_handler: event callback function
 *
 * Create a new NTB transport layer queue and provide the queue with a callback
 * routine for both transmit and receive.  The receive callback routine will be
 * used to pass up data when the transport has received it on the queue.   The
 * transmit callback routine will be called when the transport has completed the
 * transmission of the data on the queue and the data is ready to be freed.
 *
 * RETURNS: pointer to newly created ntb_queue, NULL on error.
 */
Create a new NTB transport layer queue
@rx_handler: receive callback function
@tx_handler: transmit callback function
@event_handler: event callback function

Create a new NTB transport layer queue and provide the queue with a callback
routine for both transmit and receive.  The receive callback routine will be
used to pass up data when the transport has received it on the queue.   The
transmit callback routine will be called when the transport has completed the
transmission of the data on the queue and the data is ready to be freed.

pointer to newly created ntb_queue, NULL on error.
Create a new NTB transport layer queue @rx_handler : receive callback function @tx_handler : transmit callback function @event_handler : event callback function Create a new NTB transport layer queue and provide the queue with a callback routine for both transmit and receive . The receive callback routine will be used to pass up data when the transport has received it on the queue . The transmit callback routine will be called when the transport has completed the transmission of the data on the queue and the data is ready to be freed . pointer to newly created ntb_queue NULL on error .
static struct ntb_transport_qp *
ntb_transport_create_queue(void *data, struct ntb_softc *ntb,
    const struct ntb_queue_handlers *handlers)
{
	struct ntb_queue_entry *entry;
	struct ntb_transport_qp *qp;
	struct ntb_transport_ctx *nt;
	unsigned int free_queue;
	int i;
	nt = ntb_get_ctx(ntb, NULL);
	KASSERT(nt != NULL, ("bogus"));
	free_queue = ffs_bit(&nt->qp_bitmap);
	if (free_queue == 0)
		return (NULL);
	free_queue--;
	qp = &nt->qp_vec[free_queue];
	clear_bit(qp->qp_num, &nt->qp_bitmap_free);
	qp->cb_data = data;
	qp->rx_handler = handlers->rx_handler;
	qp->tx_handler = handlers->tx_handler;
	qp->event_handler = handlers->event_handler;
	for (i = 0; i < NTB_QP_DEF_NUM_ENTRIES; i++) {
		entry = malloc(sizeof(*entry), M_NTB_IF, M_WAITOK | M_ZERO);
		entry->cb_data = nt->ifp;
		entry->buf = NULL;
		entry->len = transport_mtu;
		ntb_list_add(&qp->ntb_rx_q_lock, entry, &qp->rx_pend_q);
	}
	for (i = 0; i < NTB_QP_DEF_NUM_ENTRIES; i++) {
		entry = malloc(sizeof(*entry), M_NTB_IF, M_WAITOK | M_ZERO);
		ntb_list_add(&qp->ntb_tx_free_q_lock, entry, &qp->tx_free_q);
	}
	ntb_db_clear(ntb, 1ull << qp->qp_num);
	ntb_db_clear_mask(ntb, 1ull << qp->qp_num);
	return (qp);
}
static struct ntb_transport_qp * ntb_transport_create_queue ( void * data , struct ntb_softc * ntb , const struct ntb_queue_handlers * handlers ) { struct ntb_queue_entry * entry ; struct ntb_transport_qp * qp ; struct ntb_transport_ctx * nt ; unsigned int free_queue ; int i ; nt = ntb_get_ctx ( ntb , NULL ) ; KASSERT ( nt != NULL , ( " " ) ) ; free_queue = ffs_bit ( & nt -> qp_bitmap ) ; if ( free_queue == 0 ) return ( NULL ) ; free_queue -- ; qp = & nt -> qp_vec [ free_queue ] ; clear_bit ( qp -> qp_num , & nt -> qp_bitmap_free ) ; qp -> cb_data = data ; qp -> rx_handler = handlers -> rx_handler ; qp -> tx_handler = handlers -> tx_handler ; qp -> event_handler = handlers -> event_handler ; for ( i = 0 ; i < NTB_QP_DEF_NUM_ENTRIES ; i ++ ) { entry = malloc ( sizeof ( * entry ) , M_NTB_IF , M_WAITOK | M_ZERO ) ; entry -> cb_data = nt -> ifp ; entry -> buf = NULL ; entry -> len = transport_mtu ; ntb_list_add ( & qp -> ntb_rx_q_lock , entry , & qp -> rx_pend_q ) ; } for ( i = 0 ; i < NTB_QP_DEF_NUM_ENTRIES ; i ++ ) { entry = malloc ( sizeof ( * entry ) , M_NTB_IF , M_WAITOK | M_ZERO ) ; ntb_list_add ( & qp -> ntb_tx_free_q_lock , entry , & qp -> tx_free_q ) ; } ntb_db_clear ( ntb , 1ull << qp -> qp_num ) ; ntb_db_clear_mask ( ntb , 1ull << qp -> qp_num ) ; return ( qp ) ; }
ntb_transport_create_queue - Create a new NTB transport layer queue
 @rx_handler: receive callback function
 @tx_handler: transmit callback function
 @event_handler: event callback function
ntb_transport_create_queue - Create a new NTB transport layer queue @rx_handler : receive callback function @tx_handler : transmit callback function @event_handler : event callback function
/* decrement free_queue to make it zero based */