1a23fd118Syl /*
2a23fd118Syl * CDDL HEADER START
3a23fd118Syl *
4a23fd118Syl * The contents of this file are subject to the terms of the
5a23fd118Syl * Common Development and Distribution License (the "License").
6a23fd118Syl * You may not use this file except in compliance with the License.
7a23fd118Syl *
8a23fd118Syl * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9a23fd118Syl * or http://www.opensolaris.org/os/licensing.
10a23fd118Syl * See the License for the specific language governing permissions
11a23fd118Syl * and limitations under the License.
12a23fd118Syl *
13a23fd118Syl * When distributing Covered Code, include this CDDL HEADER in each
14a23fd118Syl * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15a23fd118Syl * If applicable, add the following below this CDDL HEADER, with the
16a23fd118Syl * fields enclosed by brackets "[]" replaced with your own identifying
17a23fd118Syl * information: Portions Copyright [yyyy] [name of copyright owner]
18a23fd118Syl *
19a23fd118Syl * CDDL HEADER END
20a23fd118Syl *
21*8347601bSyl * Copyright (c) 2002-2006 Neterion, Inc.
22a23fd118Syl */
23a23fd118Syl
24a23fd118Syl #ifndef XGE_QUEUE_H
25a23fd118Syl #define XGE_QUEUE_H
26a23fd118Syl
27a23fd118Syl #include "xge-os-pal.h"
28a23fd118Syl #include "xge-defs.h"
29a23fd118Syl #include "xge-list.h"
30*8347601bSyl #include "xgehal-event.h"
31*8347601bSyl
32*8347601bSyl __EXTERN_BEGIN_DECLS
33a23fd118Syl
34a23fd118Syl #define XGE_QUEUE_BUF_SIZE 0x1000
35a23fd118Syl #define XGE_DEFAULT_EVENT_MAX_DATA_SIZE 16
36a23fd118Syl
37a23fd118Syl /**
38a23fd118Syl * enum xge_queue_status_e - Enumerates return codes of the xge_queue
39a23fd118Syl * manipulation APIs.
40a23fd118Syl * @XGE_QUEUE_IS_FULL: Queue is full, need to grow.
41a23fd118Syl * @XGE_QUEUE_IS_EMPTY: Queue is empty.
42a23fd118Syl * @XGE_QUEUE_OUT_OF_MEMORY: Out of memory.
43a23fd118Syl * @XGE_QUEUE_NOT_ENOUGH_SPACE: Exceeded specified event size,
44a23fd118Syl * see xge_queue_consume().
45a23fd118Syl * @XGE_QUEUE_OK: Neither one of the codes listed above.
46a23fd118Syl *
47a23fd118Syl * Enumerates return codes of xge_queue_consume()
48a23fd118Syl * and xge_queue_produce() APIs.
49a23fd118Syl */
50a23fd118Syl typedef enum xge_queue_status_e {
51a23fd118Syl XGE_QUEUE_OK = 0,
52a23fd118Syl XGE_QUEUE_IS_FULL = 1,
53a23fd118Syl XGE_QUEUE_IS_EMPTY = 2,
54a23fd118Syl XGE_QUEUE_OUT_OF_MEMORY = 3,
55a23fd118Syl XGE_QUEUE_NOT_ENOUGH_SPACE = 4
56a23fd118Syl } xge_queue_status_e;
57a23fd118Syl
58a23fd118Syl typedef void* xge_queue_h;
59a23fd118Syl
60a23fd118Syl /**
61a23fd118Syl * struct xge_queue_item_t - Queue item.
62a23fd118Syl * @item: List item. Note that the queue is "built" on top of
63a23fd118Syl * the bi-directional linked list.
64a23fd118Syl * @event_type: Event type. Includes (but is not restricted to)
65a23fd118Syl * one of the xge_hal_event_e{} enumerated types.
66a23fd118Syl * @data_size: Size of the enqueued user data. Note that xge_queue_t
67a23fd118Syl * items are allowed to have variable sizes.
68a23fd118Syl * @is_critical: For critical events, e.g. ECC.
69a23fd118Syl * @context: Opaque (void*) "context", for instance event producer object.
70a23fd118Syl *
71a23fd118Syl * Item of the xge_queue_t{}. The queue is protected
72a23fd118Syl * in terms of multi-threaded concurrent access.
73a23fd118Syl * See also: xge_queue_t{}.
74a23fd118Syl */
75a23fd118Syl typedef struct xge_queue_item_t {
76*8347601bSyl xge_list_t item;
77*8347601bSyl xge_hal_event_e event_type;
78*8347601bSyl int data_size;
79*8347601bSyl int is_critical;
80*8347601bSyl void *context;
81a23fd118Syl } xge_queue_item_t;
82a23fd118Syl
83a23fd118Syl /**
84a23fd118Syl * function xge_queued_f - Item-enqueued callback.
85a23fd118Syl * @data: Per-queue context independent of the event. E.g., device handle.
86a23fd118Syl * @event_type: HAL or ULD-defined event type. Note that HAL own
87a23fd118Syl * events are enumerated by xge_hal_event_e{}.
88a23fd118Syl *
89a23fd118Syl * Per-queue optional callback. If not NULL, called by HAL each
90a23fd118Syl * time an event gets added to the queue.
91a23fd118Syl */
92a23fd118Syl typedef void (*xge_queued_f) (void *data, int event_type);
93a23fd118Syl
94a23fd118Syl /**
95a23fd118Syl * struct xge_queue_t - Protected dynamic queue of variable-size items.
96a23fd118Syl * @start_ptr: Points to the start of the queue.
97a23fd118Syl * @end_ptr: Points to the end of the queue.
98a23fd118Syl * @head_ptr: Points to the head of the queue. It gets changed during queue
99a23fd118Syl * produce/consume operations.
100a23fd118Syl * @tail_ptr: Points to the tail of the queue. It gets changed during queue
101a23fd118Syl * produce/consume operations.
102a23fd118Syl * @lock: Lock for queue operations(syncronization purpose).
103a23fd118Syl * @pages_initial:Number of pages to be initially allocated at the time
104a23fd118Syl * of queue creation.
105a23fd118Syl * @pages_max: Max number of pages that can be allocated in the queue.
106a23fd118Syl * @pages_current: Number of pages currently allocated
107a23fd118Syl * @list_head: Points to the list of queue elements that are produced, but yet
108a23fd118Syl * to be consumed.
109a23fd118Syl * @signal_callback: (TODO)
110a23fd118Syl * @pdev: PCI device handle
111a23fd118Syl * @irqh: PCI device IRQ handle.
112a23fd118Syl * @queued_func: Optional callback function to be called each time a new
113a23fd118Syl * item is added to the queue.
114a23fd118Syl * @queued_data: Arguments to the callback function.
115a23fd118Syl * @has_critical_event: Non-zero, if the queue contains a critical event,
116a23fd118Syl * see xge_hal_event_e{}.
117a23fd118Syl * Protected dynamically growing queue. The queue is used to support multiple
118a23fd118Syl * producer/consumer type scenarios. The queue is a strict FIFO: first come
119a23fd118Syl * first served.
120a23fd118Syl * Queue users may "produce" (see xge_queue_produce()) and "consume"
121a23fd118Syl * (see xge_queue_consume()) items (a.k.a. events) variable sizes.
122a23fd118Syl * See also: xge_queue_item_t{}.
123a23fd118Syl */
124a23fd118Syl typedef struct xge_queue_t {
125a23fd118Syl void *start_ptr;
126a23fd118Syl void *end_ptr;
127a23fd118Syl void *head_ptr;
128a23fd118Syl void *tail_ptr;
129a23fd118Syl spinlock_t lock;
130a23fd118Syl unsigned int pages_initial;
131a23fd118Syl unsigned int pages_max;
132a23fd118Syl unsigned int pages_current;
133a23fd118Syl xge_list_t list_head;
134a23fd118Syl pci_dev_h pdev;
135a23fd118Syl pci_irq_h irqh;
136a23fd118Syl xge_queued_f queued_func;
137a23fd118Syl void *queued_data;
138a23fd118Syl int has_critical_event;
139a23fd118Syl } xge_queue_t;
140a23fd118Syl
141a23fd118Syl /* ========================== PUBLIC API ================================= */
142a23fd118Syl
143a23fd118Syl xge_queue_h xge_queue_create(pci_dev_h pdev, pci_irq_h irqh, int pages_initial,
144a23fd118Syl int pages_max, xge_queued_f queued_func, void *queued_data);
145a23fd118Syl
146a23fd118Syl void xge_queue_destroy(xge_queue_h queueh);
147a23fd118Syl
148a23fd118Syl void* xge_queue_item_data(xge_queue_item_t *item);
149a23fd118Syl
150a23fd118Syl xge_queue_status_e
151a23fd118Syl xge_queue_produce(xge_queue_h queueh, int event_type, void *context,
152a23fd118Syl int is_critical, const int data_size, void *data);
153a23fd118Syl
154a23fd118Syl static inline xge_queue_status_e
xge_queue_produce_context(xge_queue_h queueh,int event_type,void * context)155a23fd118Syl xge_queue_produce_context(xge_queue_h queueh, int event_type, void *context) {
156a23fd118Syl return xge_queue_produce(queueh, event_type, context, 0, 0, 0);
157a23fd118Syl }
158a23fd118Syl
159a23fd118Syl xge_queue_status_e xge_queue_consume(xge_queue_h queueh, int data_max_size,
160a23fd118Syl xge_queue_item_t *item);
161a23fd118Syl
162a23fd118Syl void xge_queue_flush(xge_queue_h queueh);
163a23fd118Syl
164a23fd118Syl /* ========================== PRIVATE API ================================= */
165a23fd118Syl
166a23fd118Syl xge_queue_status_e __io_queue_grow(xge_queue_h qh);
167a23fd118Syl
168a23fd118Syl int __queue_get_reset_critical (xge_queue_h qh);
169a23fd118Syl
170*8347601bSyl __EXTERN_END_DECLS
171*8347601bSyl
172a23fd118Syl #endif /* XGE_QUEUE_H */
173