/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
* Copyright (c) 2002-2006 Neterion, Inc.
*/
#include "xge-queue.h"
/**
* xge_queue_item_data - Get item's data.
* @item: Queue item.
*
* Returns: item data(variable size). Note that xge_queue_t
* contains items comprized of a fixed xge_queue_item_t "header"
* and a variable size data. This function returns the variable
* user-defined portion of the queue item.
*/
{
return (char *)item + sizeof(xge_queue_item_t);
}
/*
* __queue_consume - (Lockless) dequeue an item from the specified queue.
*
* @queue: Event queue.
* See xge_queue_consume().
*/
static xge_queue_status_e
{
int real_size;
return XGE_QUEUE_IS_EMPTY;
return XGE_QUEUE_NOT_ENOUGH_SPACE;
"event_type: %d removing from the head: "
"event_type: %d removing from the tail: "
} else {
"event_type: %d removing from the list: "
}
/* reset buffer pointers just to be clean */
}
return XGE_QUEUE_OK;
}
/**
* xge_queue_produce - Enqueue an item (see xge_queue_item_t{})
* into the specified queue.
* @queueh: Queue handle.
* @event_type: Event type. One of the enumerated event types
* that both consumer and producer "understand".
* For an example, please refer to xge_hal_event_e.
* @context: Opaque (void*) "context", for instance event producer object.
* @is_critical: For critical event, e.g. ECC.
* @data_size: Size of the @data.
* @data: User data of variable @data_size that is _copied_ into
* the new queue item (see xge_queue_item_t{}). Upon return
* from the call the @data memory can be re-used or released.
*
* Enqueue a new item.
*
* Returns: XGE_QUEUE_OK - success.
* XGE_QUEUE_IS_FULL - Queue is full.
* XGE_QUEUE_OUT_OF_MEMORY - Memory allocation failed.
*
* See also: xge_queue_item_t{}, xge_queue_consume().
*/
{
unsigned long flags = 0;
while (__queue_consume(queue,
item) != XGE_QUEUE_IS_EMPTY)
; /* do nothing */
}
"event_type: %d adding to the tail: "
"event_type: %d adding to the head: "
} else {
return XGE_QUEUE_IS_FULL;
}
if (queue->has_critical_event) {
return XGE_QUEUE_IS_FULL;
}
/* grow */
if (status != XGE_QUEUE_OK) {
return status;
}
goto try_again;
}
if (is_critical)
/* no lock taken! */
return XGE_QUEUE_OK;
}
/**
* xge_queue_create - Create protected first-in-first-out queue.
* @pdev: PCI device handle.
* @irqh: PCI device IRQ handle.
* @pages_initial: Number of pages to be initially allocated at the
* time of queue creation.
* @pages_max: Max number of pages that can be allocated in the queue.
* @queued: Optional callback function to be called each time a new item is
* added to the queue.
* @queued_data: Argument to the callback function.
*
* Create protected (fifo) queue.
*
* Returns: Pointer to xge_queue_t structure,
* NULL - on failure.
*
* See also: xge_queue_item_t{}, xge_queue_destroy().
*/
{
return NULL;
return NULL;
}
return queue;
}
/**
* xge_queue_destroy - Destroy xge_queue_t object.
* @queueh: Queue handle.
*
* Destroy the specified xge_queue_t object.
*
* See also: xge_queue_item_t{}, xge_queue_create().
*/
{
}
}
/*
* __io_queue_grow - Dynamically increases the size of the queue.
* @queueh: Queue handle.
*
* This function is called in the case of no slot avaialble in the queue
* to accomodate the newly received event.
* Note that queue cannot grow beyond the max size specified for the
* queue.
*
* Returns XGE_QUEUE_OK: On success.
* XGE_QUEUE_OUT_OF_MEMORY : No memory is available.
*/
{
return XGE_QUEUE_OUT_OF_MEMORY;
/* adjust queue sizes */
(char *)oldbuf);
(char *)oldbuf);
/* adjust queue list */
(xge_list_t*)(void *)((char *)newbuf +
}
(xge_list_t*) (void *)((char *)newbuf +
}
}
queue->pages_current++;
return XGE_QUEUE_OK;
}
/**
* xge_queue_consume - Dequeue an item from the specified queue.
* @queueh: Queue handle.
* @data_max_size: Maximum expected size of the item.
* @item: Memory area into which the item is _copied_ upon return
* from the function.
*
* Dequeue an item from the queue. The caller is required to provide
* enough space for the item.
*
* Returns: XGE_QUEUE_OK - success.
* XGE_QUEUE_IS_EMPTY - Queue is empty.
* XGE_QUEUE_NOT_ENOUGH_SPACE - Requested item size(@data_max_size)
* is too small to accomodate an item from the queue.
*
* See also: xge_queue_item_t{}, xge_queue_produce().
*/
{
unsigned long flags = 0;
return status;
}
/**
* xge_queue_flush - Flush, or empty, the queue.
* @queueh: Queue handle.
*
* Flush the queue, i.e. make it empty by consuming all events
* without invoking the event processing logic (callbacks, etc.)
*/
{
/* flush queue by consuming all enqueued items */
while (xge_queue_consume(queueh,
item) != XGE_QUEUE_IS_EMPTY) {
/* do nothing */
}
(void) __queue_get_reset_critical (queueh);
}
/*
* __queue_get_reset_critical - Check for critical events in the queue,
* @qh: Queue handle.
*
* Check for critical event(s) in the queue, and reset the
* "has-critical-event" flag upon return.
* Returns: 1 - if the queue contains atleast one critical event.
* 0 - If there are no critical events in the queue.
*/
int c = queue->has_critical_event;
queue->has_critical_event = 0;
return c;
}