a23fd118e437af0a7877dd313db8fdaa3537c675yl/*
a23fd118e437af0a7877dd313db8fdaa3537c675yl * CDDL HEADER START
a23fd118e437af0a7877dd313db8fdaa3537c675yl *
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 *
a23fd118e437af0a7877dd313db8fdaa3537c675yl * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
a23fd118e437af0a7877dd313db8fdaa3537c675yl * or http://www.opensolaris.org/os/licensing.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * See the License for the specific language governing permissions
a23fd118e437af0a7877dd313db8fdaa3537c675yl * and limitations under the License.
a23fd118e437af0a7877dd313db8fdaa3537c675yl *
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 *
a23fd118e437af0a7877dd313db8fdaa3537c675yl * CDDL HEADER END
a23fd118e437af0a7877dd313db8fdaa3537c675yl *
8347601bcb0a439f6e50fc36b4039a73d08700e1yl * Copyright (c) 2002-2006 Neterion, Inc.
a23fd118e437af0a7877dd313db8fdaa3537c675yl */
a23fd118e437af0a7877dd313db8fdaa3537c675yl
a23fd118e437af0a7877dd313db8fdaa3537c675yl#ifndef XGE_QUEUE_H
a23fd118e437af0a7877dd313db8fdaa3537c675yl#define XGE_QUEUE_H
a23fd118e437af0a7877dd313db8fdaa3537c675yl
a23fd118e437af0a7877dd313db8fdaa3537c675yl#include "xge-os-pal.h"
a23fd118e437af0a7877dd313db8fdaa3537c675yl#include "xge-defs.h"
a23fd118e437af0a7877dd313db8fdaa3537c675yl#include "xge-list.h"
8347601bcb0a439f6e50fc36b4039a73d08700e1yl#include "xgehal-event.h"
8347601bcb0a439f6e50fc36b4039a73d08700e1yl
8347601bcb0a439f6e50fc36b4039a73d08700e1yl__EXTERN_BEGIN_DECLS
a23fd118e437af0a7877dd313db8fdaa3537c675yl
a23fd118e437af0a7877dd313db8fdaa3537c675yl#define XGE_QUEUE_BUF_SIZE 0x1000
a23fd118e437af0a7877dd313db8fdaa3537c675yl#define XGE_DEFAULT_EVENT_MAX_DATA_SIZE 16
a23fd118e437af0a7877dd313db8fdaa3537c675yl
a23fd118e437af0a7877dd313db8fdaa3537c675yl/**
a23fd118e437af0a7877dd313db8fdaa3537c675yl * enum xge_queue_status_e - Enumerates return codes of the xge_queue
a23fd118e437af0a7877dd313db8fdaa3537c675yl * manipulation APIs.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @XGE_QUEUE_IS_FULL: Queue is full, need to grow.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @XGE_QUEUE_IS_EMPTY: Queue is empty.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @XGE_QUEUE_OUT_OF_MEMORY: Out of memory.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @XGE_QUEUE_NOT_ENOUGH_SPACE: Exceeded specified event size,
a23fd118e437af0a7877dd313db8fdaa3537c675yl * see xge_queue_consume().
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @XGE_QUEUE_OK: Neither one of the codes listed above.
a23fd118e437af0a7877dd313db8fdaa3537c675yl *
a23fd118e437af0a7877dd313db8fdaa3537c675yl * Enumerates return codes of xge_queue_consume()
a23fd118e437af0a7877dd313db8fdaa3537c675yl * and xge_queue_produce() APIs.
a23fd118e437af0a7877dd313db8fdaa3537c675yl */
a23fd118e437af0a7877dd313db8fdaa3537c675yltypedef enum xge_queue_status_e {
a23fd118e437af0a7877dd313db8fdaa3537c675yl XGE_QUEUE_OK = 0,
a23fd118e437af0a7877dd313db8fdaa3537c675yl XGE_QUEUE_IS_FULL = 1,
a23fd118e437af0a7877dd313db8fdaa3537c675yl XGE_QUEUE_IS_EMPTY = 2,
a23fd118e437af0a7877dd313db8fdaa3537c675yl XGE_QUEUE_OUT_OF_MEMORY = 3,
a23fd118e437af0a7877dd313db8fdaa3537c675yl XGE_QUEUE_NOT_ENOUGH_SPACE = 4
a23fd118e437af0a7877dd313db8fdaa3537c675yl} xge_queue_status_e;
a23fd118e437af0a7877dd313db8fdaa3537c675yl
a23fd118e437af0a7877dd313db8fdaa3537c675yltypedef void* xge_queue_h;
a23fd118e437af0a7877dd313db8fdaa3537c675yl
a23fd118e437af0a7877dd313db8fdaa3537c675yl/**
a23fd118e437af0a7877dd313db8fdaa3537c675yl * struct xge_queue_item_t - Queue item.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @item: List item. Note that the queue is "built" on top of
a23fd118e437af0a7877dd313db8fdaa3537c675yl * the bi-directional linked list.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @event_type: Event type. Includes (but is not restricted to)
a23fd118e437af0a7877dd313db8fdaa3537c675yl * one of the xge_hal_event_e{} enumerated types.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @data_size: Size of the enqueued user data. Note that xge_queue_t
a23fd118e437af0a7877dd313db8fdaa3537c675yl * items are allowed to have variable sizes.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @is_critical: For critical events, e.g. ECC.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @context: Opaque (void*) "context", for instance event producer object.
a23fd118e437af0a7877dd313db8fdaa3537c675yl *
a23fd118e437af0a7877dd313db8fdaa3537c675yl * Item of the xge_queue_t{}. The queue is protected
a23fd118e437af0a7877dd313db8fdaa3537c675yl * in terms of multi-threaded concurrent access.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * See also: xge_queue_t{}.
a23fd118e437af0a7877dd313db8fdaa3537c675yl */
a23fd118e437af0a7877dd313db8fdaa3537c675yltypedef struct xge_queue_item_t {
8347601bcb0a439f6e50fc36b4039a73d08700e1yl xge_list_t item;
8347601bcb0a439f6e50fc36b4039a73d08700e1yl xge_hal_event_e event_type;
8347601bcb0a439f6e50fc36b4039a73d08700e1yl int data_size;
8347601bcb0a439f6e50fc36b4039a73d08700e1yl int is_critical;
8347601bcb0a439f6e50fc36b4039a73d08700e1yl void *context;
a23fd118e437af0a7877dd313db8fdaa3537c675yl} xge_queue_item_t;
a23fd118e437af0a7877dd313db8fdaa3537c675yl
a23fd118e437af0a7877dd313db8fdaa3537c675yl/**
a23fd118e437af0a7877dd313db8fdaa3537c675yl * function xge_queued_f - Item-enqueued callback.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @data: Per-queue context independent of the event. E.g., device handle.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @event_type: HAL or ULD-defined event type. Note that HAL own
a23fd118e437af0a7877dd313db8fdaa3537c675yl * events are enumerated by xge_hal_event_e{}.
a23fd118e437af0a7877dd313db8fdaa3537c675yl *
a23fd118e437af0a7877dd313db8fdaa3537c675yl * Per-queue optional callback. If not NULL, called by HAL each
a23fd118e437af0a7877dd313db8fdaa3537c675yl * time an event gets added to the queue.
a23fd118e437af0a7877dd313db8fdaa3537c675yl */
a23fd118e437af0a7877dd313db8fdaa3537c675yltypedef void (*xge_queued_f) (void *data, int event_type);
a23fd118e437af0a7877dd313db8fdaa3537c675yl
a23fd118e437af0a7877dd313db8fdaa3537c675yl/**
a23fd118e437af0a7877dd313db8fdaa3537c675yl * struct xge_queue_t - Protected dynamic queue of variable-size items.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @start_ptr: Points to the start of the queue.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @end_ptr: Points to the end of the queue.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @head_ptr: Points to the head of the queue. It gets changed during queue
a23fd118e437af0a7877dd313db8fdaa3537c675yl * produce/consume operations.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @tail_ptr: Points to the tail of the queue. It gets changed during queue
a23fd118e437af0a7877dd313db8fdaa3537c675yl * produce/consume operations.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @lock: Lock for queue operations(syncronization purpose).
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @pages_initial:Number of pages to be initially allocated at the time
a23fd118e437af0a7877dd313db8fdaa3537c675yl * of queue creation.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @pages_max: Max number of pages that can be allocated in the queue.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @pages_current: Number of pages currently allocated
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @list_head: Points to the list of queue elements that are produced, but yet
a23fd118e437af0a7877dd313db8fdaa3537c675yl * to be consumed.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @signal_callback: (TODO)
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @pdev: PCI device handle
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @irqh: PCI device IRQ handle.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @queued_func: Optional callback function to be called each time a new
a23fd118e437af0a7877dd313db8fdaa3537c675yl * item is added to the queue.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @queued_data: Arguments to the callback function.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * @has_critical_event: Non-zero, if the queue contains a critical event,
a23fd118e437af0a7877dd313db8fdaa3537c675yl * see xge_hal_event_e{}.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * Protected dynamically growing queue. The queue is used to support multiple
a23fd118e437af0a7877dd313db8fdaa3537c675yl * producer/consumer type scenarios. The queue is a strict FIFO: first come
a23fd118e437af0a7877dd313db8fdaa3537c675yl * first served.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * Queue users may "produce" (see xge_queue_produce()) and "consume"
a23fd118e437af0a7877dd313db8fdaa3537c675yl * (see xge_queue_consume()) items (a.k.a. events) variable sizes.
a23fd118e437af0a7877dd313db8fdaa3537c675yl * See also: xge_queue_item_t{}.
a23fd118e437af0a7877dd313db8fdaa3537c675yl */
a23fd118e437af0a7877dd313db8fdaa3537c675yltypedef struct xge_queue_t {
a23fd118e437af0a7877dd313db8fdaa3537c675yl void *start_ptr;
a23fd118e437af0a7877dd313db8fdaa3537c675yl void *end_ptr;
a23fd118e437af0a7877dd313db8fdaa3537c675yl void *head_ptr;
a23fd118e437af0a7877dd313db8fdaa3537c675yl void *tail_ptr;
a23fd118e437af0a7877dd313db8fdaa3537c675yl spinlock_t lock;
a23fd118e437af0a7877dd313db8fdaa3537c675yl unsigned int pages_initial;
a23fd118e437af0a7877dd313db8fdaa3537c675yl unsigned int pages_max;
a23fd118e437af0a7877dd313db8fdaa3537c675yl unsigned int pages_current;
a23fd118e437af0a7877dd313db8fdaa3537c675yl xge_list_t list_head;
a23fd118e437af0a7877dd313db8fdaa3537c675yl pci_dev_h pdev;
a23fd118e437af0a7877dd313db8fdaa3537c675yl pci_irq_h irqh;
a23fd118e437af0a7877dd313db8fdaa3537c675yl xge_queued_f queued_func;
a23fd118e437af0a7877dd313db8fdaa3537c675yl void *queued_data;
a23fd118e437af0a7877dd313db8fdaa3537c675yl int has_critical_event;
a23fd118e437af0a7877dd313db8fdaa3537c675yl} xge_queue_t;
a23fd118e437af0a7877dd313db8fdaa3537c675yl
a23fd118e437af0a7877dd313db8fdaa3537c675yl/* ========================== PUBLIC API ================================= */
a23fd118e437af0a7877dd313db8fdaa3537c675yl
a23fd118e437af0a7877dd313db8fdaa3537c675ylxge_queue_h xge_queue_create(pci_dev_h pdev, pci_irq_h irqh, int pages_initial,
a23fd118e437af0a7877dd313db8fdaa3537c675yl int pages_max, xge_queued_f queued_func, void *queued_data);
a23fd118e437af0a7877dd313db8fdaa3537c675yl
a23fd118e437af0a7877dd313db8fdaa3537c675ylvoid xge_queue_destroy(xge_queue_h queueh);
a23fd118e437af0a7877dd313db8fdaa3537c675yl
a23fd118e437af0a7877dd313db8fdaa3537c675ylvoid* xge_queue_item_data(xge_queue_item_t *item);
a23fd118e437af0a7877dd313db8fdaa3537c675yl
a23fd118e437af0a7877dd313db8fdaa3537c675ylxge_queue_status_e
a23fd118e437af0a7877dd313db8fdaa3537c675ylxge_queue_produce(xge_queue_h queueh, int event_type, void *context,
a23fd118e437af0a7877dd313db8fdaa3537c675yl int is_critical, const int data_size, void *data);
a23fd118e437af0a7877dd313db8fdaa3537c675yl
a23fd118e437af0a7877dd313db8fdaa3537c675ylstatic inline xge_queue_status_e
a23fd118e437af0a7877dd313db8fdaa3537c675ylxge_queue_produce_context(xge_queue_h queueh, int event_type, void *context) {
a23fd118e437af0a7877dd313db8fdaa3537c675yl return xge_queue_produce(queueh, event_type, context, 0, 0, 0);
a23fd118e437af0a7877dd313db8fdaa3537c675yl}
a23fd118e437af0a7877dd313db8fdaa3537c675yl
a23fd118e437af0a7877dd313db8fdaa3537c675ylxge_queue_status_e xge_queue_consume(xge_queue_h queueh, int data_max_size,
a23fd118e437af0a7877dd313db8fdaa3537c675yl xge_queue_item_t *item);
a23fd118e437af0a7877dd313db8fdaa3537c675yl
a23fd118e437af0a7877dd313db8fdaa3537c675ylvoid xge_queue_flush(xge_queue_h queueh);
a23fd118e437af0a7877dd313db8fdaa3537c675yl
a23fd118e437af0a7877dd313db8fdaa3537c675yl/* ========================== PRIVATE API ================================= */
a23fd118e437af0a7877dd313db8fdaa3537c675yl
a23fd118e437af0a7877dd313db8fdaa3537c675ylxge_queue_status_e __io_queue_grow(xge_queue_h qh);
a23fd118e437af0a7877dd313db8fdaa3537c675yl
a23fd118e437af0a7877dd313db8fdaa3537c675ylint __queue_get_reset_critical (xge_queue_h qh);
a23fd118e437af0a7877dd313db8fdaa3537c675yl
8347601bcb0a439f6e50fc36b4039a73d08700e1yl__EXTERN_END_DECLS
8347601bcb0a439f6e50fc36b4039a73d08700e1yl
a23fd118e437af0a7877dd313db8fdaa3537c675yl#endif /* XGE_QUEUE_H */