2 * Copyright (c) 2002-2007 Neterion, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * FileName : xge-queue.h
32 * Description: serialized event queue
34 * Created: 7 June 2004
40 #include <dev/nxge/include/xge-os-pal.h>
41 #include <dev/nxge/include/xge-defs.h>
42 #include <dev/nxge/include/xge-list.h>
43 #include <dev/nxge/include/xgehal-event.h>
47 #define XGE_QUEUE_BUF_SIZE 0x1000
48 #define XGE_DEFAULT_EVENT_MAX_DATA_SIZE 16
51 * enum xge_queue_status_e - Enumerates return codes of the xge_queue
53 * @XGE_QUEUE_IS_FULL: Queue is full, need to grow.
54 * @XGE_QUEUE_IS_EMPTY: Queue is empty.
55 * @XGE_QUEUE_OUT_OF_MEMORY: Out of memory.
56 * @XGE_QUEUE_NOT_ENOUGH_SPACE: Exceeded specified event size,
57 * see xge_queue_consume().
58 * @XGE_QUEUE_OK: Neither one of the codes listed above.
60 * Enumerates return codes of xge_queue_consume()
61 * and xge_queue_produce() APIs.
63 typedef enum xge_queue_status_e {
65 XGE_QUEUE_IS_FULL = 1,
66 XGE_QUEUE_IS_EMPTY = 2,
67 XGE_QUEUE_OUT_OF_MEMORY = 3,
68 XGE_QUEUE_NOT_ENOUGH_SPACE = 4
71 typedef void* xge_queue_h;
74 * struct xge_queue_item_t - Queue item.
75 * @item: List item. Note that the queue is "built" on top of
76 * the bi-directional linked list.
77 * @event_type: Event type. Includes (but is not restricted to)
78 * one of the xge_hal_event_e{} enumerated types.
79 * @data_size: Size of the enqueued user data. Note that xge_queue_t
80 * items are allowed to have variable sizes.
81 * @is_critical: For critical events, e.g. ECC.
82 * @context: Opaque (void*) "context", for instance event producer object.
84 * Item of the xge_queue_t{}. The queue is protected
85 * in terms of multi-threaded concurrent access.
86 * See also: xge_queue_t{}.
88 typedef struct xge_queue_item_t {
90 xge_hal_event_e event_type;
97 * function xge_queued_f - Item-enqueued callback.
98 * @data: Per-queue context independent of the event. E.g., device handle.
99 * @event_type: HAL or ULD-defined event type. Note that HAL own
100 * events are enumerated by xge_hal_event_e{}.
102 * Per-queue optional callback. If not NULL, called by HAL each
103 * time an event gets added to the queue.
105 typedef void (*xge_queued_f) (void *data, int event_type);
108 * struct xge_queue_t - Protected dynamic queue of variable-size items.
109 * @start_ptr: Points to the start of the queue.
110 * @end_ptr: Points to the end of the queue.
111 * @head_ptr: Points to the head of the queue. It gets changed during queue
112 * produce/consume operations.
113 * @tail_ptr: Points to the tail of the queue. It gets changed during queue
114 * produce/consume operations.
115 * @lock: Lock for queue operations(syncronization purpose).
116 * @pages_initial:Number of pages to be initially allocated at the time
118 * @pages_max: Max number of pages that can be allocated in the queue.
119 * @pages_current: Number of pages currently allocated
120 * @list_head: Points to the list of queue elements that are produced, but yet
122 * @signal_callback: (TODO)
123 * @pdev: PCI device handle
124 * @irqh: PCI device IRQ handle.
125 * @queued_func: Optional callback function to be called each time a new
126 * item is added to the queue.
127 * @queued_data: Arguments to the callback function.
128 * @has_critical_event: Non-zero, if the queue contains a critical event,
129 * see xge_hal_event_e{}.
130 * Protected dynamically growing queue. The queue is used to support multiple
131 * producer/consumer type scenarios. The queue is a strict FIFO: first come
133 * Queue users may "produce" (see xge_queue_produce()) and "consume"
134 * (see xge_queue_consume()) items (a.k.a. events) variable sizes.
135 * See also: xge_queue_item_t{}.
137 typedef struct xge_queue_t {
143 unsigned int pages_initial;
144 unsigned int pages_max;
145 unsigned int pages_current;
146 xge_list_t list_head;
149 xge_queued_f queued_func;
151 int has_critical_event;
154 /* ========================== PUBLIC API ================================= */
156 xge_queue_h xge_queue_create(pci_dev_h pdev, pci_irq_h irqh, int pages_initial,
157 int pages_max, xge_queued_f queued_func, void *queued_data);
159 void xge_queue_destroy(xge_queue_h queueh);
161 void* xge_queue_item_data(xge_queue_item_t *item);
164 xge_queue_produce(xge_queue_h queueh, int event_type, void *context,
165 int is_critical, const int data_size, void *data);
167 static inline xge_queue_status_e
168 xge_queue_produce_context(xge_queue_h queueh, int event_type, void *context) {
169 return xge_queue_produce(queueh, event_type, context, 0, 0, 0);
172 xge_queue_status_e xge_queue_consume(xge_queue_h queueh, int data_max_size,
173 xge_queue_item_t *item);
175 void xge_queue_flush(xge_queue_h queueh);
177 /* ========================== PRIVATE API ================================= */
179 xge_queue_status_e __io_queue_grow(xge_queue_h qh);
181 int __queue_get_reset_critical (xge_queue_h qh);
185 #endif /* XGE_QUEUE_H */