xge-queue.h revision 3115:4198a5aabed4
1139825Simp/*
2103619Sgrehan * CDDL HEADER START
3103619Sgrehan *
4103619Sgrehan * The contents of this file are subject to the terms of the
5103619Sgrehan * Common Development and Distribution License (the "License").
6103619Sgrehan * You may not use this file except in compliance with the License.
7103619Sgrehan *
8103619Sgrehan * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9103619Sgrehan * or http://www.opensolaris.org/os/licensing.
10103619Sgrehan * See the License for the specific language governing permissions
11103619Sgrehan * and limitations under the License.
12103619Sgrehan *
13103619Sgrehan * When distributing Covered Code, include this CDDL HEADER in each
14103619Sgrehan * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15103619Sgrehan * If applicable, add the following below this CDDL HEADER, with the
16103619Sgrehan * fields enclosed by brackets "[]" replaced with your own identifying
17103619Sgrehan * information: Portions Copyright [yyyy] [name of copyright owner]
18103619Sgrehan *
19103619Sgrehan * CDDL HEADER END
20103619Sgrehan *
21103619Sgrehan * Copyright (c) 2002-2006 Neterion, Inc.
22103619Sgrehan */
23103619Sgrehan
24103619Sgrehan#ifndef XGE_QUEUE_H
25103619Sgrehan#define XGE_QUEUE_H
26103619Sgrehan
27103619Sgrehan#include "xge-os-pal.h"
28103619Sgrehan#include "xge-defs.h"
29103619Sgrehan#include "xge-list.h"
30103619Sgrehan#include "xgehal-event.h"
31103619Sgrehan
32103619Sgrehan__EXTERN_BEGIN_DECLS
33103619Sgrehan
34103619Sgrehan#define XGE_QUEUE_BUF_SIZE		0x1000
35103619Sgrehan#define XGE_DEFAULT_EVENT_MAX_DATA_SIZE	16
36103619Sgrehan
37103619Sgrehan/**
38131102Sgrehan * enum xge_queue_status_e - Enumerates return codes of the xge_queue
39103619Sgrehan * manipulation APIs.
40103619Sgrehan * @XGE_QUEUE_IS_FULL: Queue is full, need to grow.
41103619Sgrehan * @XGE_QUEUE_IS_EMPTY: Queue is empty.
42103619Sgrehan * @XGE_QUEUE_OUT_OF_MEMORY: Out of memory.
43103619Sgrehan * @XGE_QUEUE_NOT_ENOUGH_SPACE: Exceeded specified event size,
44209298Snwhitehorn * see xge_queue_consume().
45209298Snwhitehorn * @XGE_QUEUE_OK: Neither one of the codes listed above.
46209298Snwhitehorn *
47103619Sgrehan * Enumerates return codes of xge_queue_consume()
48103619Sgrehan * and xge_queue_produce() APIs.
49209298Snwhitehorn */
50103619Sgrehantypedef enum xge_queue_status_e {
51133589Smarius	XGE_QUEUE_OK			= 0,
52153050Smarius	XGE_QUEUE_IS_FULL		= 1,
53103619Sgrehan	XGE_QUEUE_IS_EMPTY		= 2,
54103619Sgrehan	XGE_QUEUE_OUT_OF_MEMORY	        = 3,
55103619Sgrehan	XGE_QUEUE_NOT_ENOUGH_SPACE	= 4
56103619Sgrehan} xge_queue_status_e;
57103619Sgrehan
58103619Sgrehantypedef void* xge_queue_h;
59103619Sgrehan
60131400Sgrehan/**
61131400Sgrehan * struct xge_queue_item_t - Queue item.
62131400Sgrehan * @item: List item. Note that the queue is "built" on top of
63131400Sgrehan *        the bi-directional linked list.
64131400Sgrehan * @event_type: Event type. Includes (but is not restricted to)
65131400Sgrehan * one of the xge_hal_event_e{} enumerated types.
66131400Sgrehan * @data_size: Size of the enqueued user data. Note that xge_queue_t
67131400Sgrehan * items are allowed to have variable sizes.
68221519Snwhitehorn * @is_critical: For critical events, e.g. ECC.
69221519Snwhitehorn * @context: Opaque (void*) "context", for instance event producer object.
70221519Snwhitehorn *
71221519Snwhitehorn * Item of the xge_queue_t{}. The queue is protected
72131400Sgrehan * in terms of multi-threaded concurrent access.
73131400Sgrehan * See also: xge_queue_t{}.
74103619Sgrehan */
75103619Sgrehantypedef struct xge_queue_item_t {
76103619Sgrehan	xge_list_t			item;
77103619Sgrehan	xge_hal_event_e		event_type;
78103619Sgrehan	int					data_size;
79103619Sgrehan	int					is_critical;
80103619Sgrehan	void				*context;
81103619Sgrehan} xge_queue_item_t;
82103619Sgrehan
83103619Sgrehan/**
84103619Sgrehan * function xge_queued_f - Item-enqueued callback.
85103619Sgrehan * @data: Per-queue context independent of the event. E.g., device handle.
86103619Sgrehan * @event_type: HAL or ULD-defined event type. Note that HAL own
87103619Sgrehan *        events are enumerated by xge_hal_event_e{}.
88103619Sgrehan *
89153050Smarius * Per-queue optional callback. If not NULL, called by HAL each
90103619Sgrehan * time an event gets added to the queue.
91103619Sgrehan */
92103619Sgrehantypedef void (*xge_queued_f) (void *data, int event_type);
93103619Sgrehan
94103619Sgrehan/**
95103619Sgrehan * struct xge_queue_t - Protected dynamic queue of variable-size items.
96103619Sgrehan * @start_ptr: Points to the start of the queue.
97103619Sgrehan * @end_ptr: Points to the end of the queue.
98103619Sgrehan * @head_ptr: Points to the head of the queue. It gets changed during queue
99103619Sgrehan *            produce/consume operations.
100103619Sgrehan * @tail_ptr: Points to the tail of the queue. It gets changed during queue
101103619Sgrehan *            produce/consume operations.
102103619Sgrehan * @lock: Lock for queue operations(syncronization purpose).
103103619Sgrehan * @pages_initial:Number of pages to be initially allocated at the time
104103619Sgrehan *		  of queue creation.
105103619Sgrehan * @pages_max: Max number of pages that can be allocated in the queue.
106103619Sgrehan * @pages_current: Number of pages currently allocated
107103619Sgrehan * @list_head: Points to the list of queue elements that are produced, but yet
108103619Sgrehan *             to be consumed.
109103619Sgrehan * @signal_callback: (TODO)
110103619Sgrehan * @pdev: PCI device handle
111103619Sgrehan * @irqh: PCI device IRQ handle.
112103619Sgrehan * @queued_func: Optional callback function to be called each time a new
113103619Sgrehan * item is added to the queue.
114103619Sgrehan * @queued_data: Arguments to the callback function.
115186128Snwhitehorn * @has_critical_event: Non-zero, if the queue contains a critical event,
116186128Snwhitehorn * see xge_hal_event_e{}.
117133589Smarius * Protected dynamically growing queue. The queue is used to support multiple
118153050Smarius * producer/consumer type scenarios. The queue is a strict FIFO: first come
119153050Smarius * first served.
120153050Smarius * Queue users may "produce" (see xge_queue_produce()) and "consume"
121153050Smarius * (see xge_queue_consume()) items (a.k.a. events) variable sizes.
122153050Smarius * See also: xge_queue_item_t{}.
123153050Smarius */
124133589Smariustypedef struct xge_queue_t {
125103619Sgrehan	void				*start_ptr;
126103619Sgrehan	void				*end_ptr;
127103619Sgrehan	void				*head_ptr;
128103619Sgrehan	void				*tail_ptr;
129103619Sgrehan	spinlock_t			lock;
130103619Sgrehan	unsigned int			pages_initial;
131103619Sgrehan	unsigned int			pages_max;
132103619Sgrehan	unsigned int			pages_current;
133103619Sgrehan	xge_list_t			list_head;
134103619Sgrehan	pci_dev_h                       pdev;
135103619Sgrehan	pci_irq_h                       irqh;
136103619Sgrehan	xge_queued_f			queued_func;
137103619Sgrehan	void				*queued_data;
138103619Sgrehan	int				has_critical_event;
139103619Sgrehan} xge_queue_t;
140103619Sgrehan
141103619Sgrehan/* ========================== PUBLIC API ================================= */
142103619Sgrehan
143103619Sgrehanxge_queue_h xge_queue_create(pci_dev_h pdev, pci_irq_h irqh, int pages_initial,
144103619Sgrehan		int pages_max, xge_queued_f queued_func, void *queued_data);
145112428Sgrehan
146112428Sgrehanvoid xge_queue_destroy(xge_queue_h queueh);
147103619Sgrehan
148112428Sgrehanvoid* xge_queue_item_data(xge_queue_item_t *item);
149183882Snwhitehorn
150183882Snwhitehornxge_queue_status_e
151112428Sgrehanxge_queue_produce(xge_queue_h queueh, int event_type, void *context,
152103619Sgrehan		int is_critical, const int data_size, void *data);
153103619Sgrehan
154103619Sgrehanstatic inline xge_queue_status_e
155103619Sgrehanxge_queue_produce_context(xge_queue_h queueh, int event_type, void *context) {
156103619Sgrehan	return xge_queue_produce(queueh, event_type, context, 0, 0, 0);
157103619Sgrehan}
158108991Sbenno
159108991Sbennoxge_queue_status_e xge_queue_consume(xge_queue_h queueh, int data_max_size,
160186805Snwhitehorn		xge_queue_item_t *item);
161108991Sbenno
162108991Sbennovoid xge_queue_flush(xge_queue_h queueh);
163108991Sbenno
164108991Sbenno/* ========================== PRIVATE API ================================= */
165103619Sgrehan
166103619Sgrehanxge_queue_status_e __io_queue_grow(xge_queue_h qh);
167108991Sbenno
168108991Sbennoint __queue_get_reset_critical (xge_queue_h qh);
169108991Sbenno
170108991Sbenno__EXTERN_END_DECLS
171186805Snwhitehorn
172186805Snwhitehorn#endif /* XGE_QUEUE_H */
173186805Snwhitehorn