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