xref: /onnv-gate/usr/src/uts/common/io/xge/hal/include/xge-queue.h (revision 3115:4198a5aabed4)
11256Syl150051 /*
21256Syl150051  * CDDL HEADER START
31256Syl150051  *
41256Syl150051  * The contents of this file are subject to the terms of the
51256Syl150051  * Common Development and Distribution License (the "License").
61256Syl150051  * You may not use this file except in compliance with the License.
71256Syl150051  *
81256Syl150051  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91256Syl150051  * or http://www.opensolaris.org/os/licensing.
101256Syl150051  * See the License for the specific language governing permissions
111256Syl150051  * and limitations under the License.
121256Syl150051  *
131256Syl150051  * When distributing Covered Code, include this CDDL HEADER in each
141256Syl150051  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151256Syl150051  * If applicable, add the following below this CDDL HEADER, with the
161256Syl150051  * fields enclosed by brackets "[]" replaced with your own identifying
171256Syl150051  * information: Portions Copyright [yyyy] [name of copyright owner]
181256Syl150051  *
191256Syl150051  * CDDL HEADER END
201256Syl150051  *
21*3115Syl150051  * Copyright (c) 2002-2006 Neterion, Inc.
221256Syl150051  */
231256Syl150051 
241256Syl150051 #ifndef XGE_QUEUE_H
251256Syl150051 #define XGE_QUEUE_H
261256Syl150051 
271256Syl150051 #include "xge-os-pal.h"
281256Syl150051 #include "xge-defs.h"
291256Syl150051 #include "xge-list.h"
30*3115Syl150051 #include "xgehal-event.h"
31*3115Syl150051 
32*3115Syl150051 __EXTERN_BEGIN_DECLS
331256Syl150051 
341256Syl150051 #define XGE_QUEUE_BUF_SIZE		0x1000
351256Syl150051 #define XGE_DEFAULT_EVENT_MAX_DATA_SIZE	16
361256Syl150051 
371256Syl150051 /**
381256Syl150051  * enum xge_queue_status_e - Enumerates return codes of the xge_queue
391256Syl150051  * manipulation APIs.
401256Syl150051  * @XGE_QUEUE_IS_FULL: Queue is full, need to grow.
411256Syl150051  * @XGE_QUEUE_IS_EMPTY: Queue is empty.
421256Syl150051  * @XGE_QUEUE_OUT_OF_MEMORY: Out of memory.
431256Syl150051  * @XGE_QUEUE_NOT_ENOUGH_SPACE: Exceeded specified event size,
441256Syl150051  * see xge_queue_consume().
451256Syl150051  * @XGE_QUEUE_OK: Neither one of the codes listed above.
461256Syl150051  *
471256Syl150051  * Enumerates return codes of xge_queue_consume()
481256Syl150051  * and xge_queue_produce() APIs.
491256Syl150051  */
501256Syl150051 typedef enum xge_queue_status_e {
511256Syl150051 	XGE_QUEUE_OK			= 0,
521256Syl150051 	XGE_QUEUE_IS_FULL		= 1,
531256Syl150051 	XGE_QUEUE_IS_EMPTY		= 2,
541256Syl150051 	XGE_QUEUE_OUT_OF_MEMORY	        = 3,
551256Syl150051 	XGE_QUEUE_NOT_ENOUGH_SPACE	= 4
561256Syl150051 } xge_queue_status_e;
571256Syl150051 
581256Syl150051 typedef void* xge_queue_h;
591256Syl150051 
601256Syl150051 /**
611256Syl150051  * struct xge_queue_item_t - Queue item.
621256Syl150051  * @item: List item. Note that the queue is "built" on top of
631256Syl150051  *        the bi-directional linked list.
641256Syl150051  * @event_type: Event type. Includes (but is not restricted to)
651256Syl150051  * one of the xge_hal_event_e{} enumerated types.
661256Syl150051  * @data_size: Size of the enqueued user data. Note that xge_queue_t
671256Syl150051  * items are allowed to have variable sizes.
681256Syl150051  * @is_critical: For critical events, e.g. ECC.
691256Syl150051  * @context: Opaque (void*) "context", for instance event producer object.
701256Syl150051  *
711256Syl150051  * Item of the xge_queue_t{}. The queue is protected
721256Syl150051  * in terms of multi-threaded concurrent access.
731256Syl150051  * See also: xge_queue_t{}.
741256Syl150051  */
751256Syl150051 typedef struct xge_queue_item_t {
76*3115Syl150051 	xge_list_t			item;
77*3115Syl150051 	xge_hal_event_e		event_type;
78*3115Syl150051 	int					data_size;
79*3115Syl150051 	int					is_critical;
80*3115Syl150051 	void				*context;
811256Syl150051 } xge_queue_item_t;
821256Syl150051 
831256Syl150051 /**
841256Syl150051  * function xge_queued_f - Item-enqueued callback.
851256Syl150051  * @data: Per-queue context independent of the event. E.g., device handle.
861256Syl150051  * @event_type: HAL or ULD-defined event type. Note that HAL own
871256Syl150051  *        events are enumerated by xge_hal_event_e{}.
881256Syl150051  *
891256Syl150051  * Per-queue optional callback. If not NULL, called by HAL each
901256Syl150051  * time an event gets added to the queue.
911256Syl150051  */
921256Syl150051 typedef void (*xge_queued_f) (void *data, int event_type);
931256Syl150051 
941256Syl150051 /**
951256Syl150051  * struct xge_queue_t - Protected dynamic queue of variable-size items.
961256Syl150051  * @start_ptr: Points to the start of the queue.
971256Syl150051  * @end_ptr: Points to the end of the queue.
981256Syl150051  * @head_ptr: Points to the head of the queue. It gets changed during queue
991256Syl150051  *            produce/consume operations.
1001256Syl150051  * @tail_ptr: Points to the tail of the queue. It gets changed during queue
1011256Syl150051  *            produce/consume operations.
1021256Syl150051  * @lock: Lock for queue operations(syncronization purpose).
1031256Syl150051  * @pages_initial:Number of pages to be initially allocated at the time
1041256Syl150051  *		  of queue creation.
1051256Syl150051  * @pages_max: Max number of pages that can be allocated in the queue.
1061256Syl150051  * @pages_current: Number of pages currently allocated
1071256Syl150051  * @list_head: Points to the list of queue elements that are produced, but yet
1081256Syl150051  *             to be consumed.
1091256Syl150051  * @signal_callback: (TODO)
1101256Syl150051  * @pdev: PCI device handle
1111256Syl150051  * @irqh: PCI device IRQ handle.
1121256Syl150051  * @queued_func: Optional callback function to be called each time a new
1131256Syl150051  * item is added to the queue.
1141256Syl150051  * @queued_data: Arguments to the callback function.
1151256Syl150051  * @has_critical_event: Non-zero, if the queue contains a critical event,
1161256Syl150051  * see xge_hal_event_e{}.
1171256Syl150051  * Protected dynamically growing queue. The queue is used to support multiple
1181256Syl150051  * producer/consumer type scenarios. The queue is a strict FIFO: first come
1191256Syl150051  * first served.
1201256Syl150051  * Queue users may "produce" (see xge_queue_produce()) and "consume"
1211256Syl150051  * (see xge_queue_consume()) items (a.k.a. events) variable sizes.
1221256Syl150051  * See also: xge_queue_item_t{}.
1231256Syl150051  */
1241256Syl150051 typedef struct xge_queue_t {
1251256Syl150051 	void				*start_ptr;
1261256Syl150051 	void				*end_ptr;
1271256Syl150051 	void				*head_ptr;
1281256Syl150051 	void				*tail_ptr;
1291256Syl150051 	spinlock_t			lock;
1301256Syl150051 	unsigned int			pages_initial;
1311256Syl150051 	unsigned int			pages_max;
1321256Syl150051 	unsigned int			pages_current;
1331256Syl150051 	xge_list_t			list_head;
1341256Syl150051 	pci_dev_h                       pdev;
1351256Syl150051 	pci_irq_h                       irqh;
1361256Syl150051 	xge_queued_f			queued_func;
1371256Syl150051 	void				*queued_data;
1381256Syl150051 	int				has_critical_event;
1391256Syl150051 } xge_queue_t;
1401256Syl150051 
1411256Syl150051 /* ========================== PUBLIC API ================================= */
1421256Syl150051 
1431256Syl150051 xge_queue_h xge_queue_create(pci_dev_h pdev, pci_irq_h irqh, int pages_initial,
1441256Syl150051 		int pages_max, xge_queued_f queued_func, void *queued_data);
1451256Syl150051 
1461256Syl150051 void xge_queue_destroy(xge_queue_h queueh);
1471256Syl150051 
1481256Syl150051 void* xge_queue_item_data(xge_queue_item_t *item);
1491256Syl150051 
1501256Syl150051 xge_queue_status_e
1511256Syl150051 xge_queue_produce(xge_queue_h queueh, int event_type, void *context,
1521256Syl150051 		int is_critical, const int data_size, void *data);
1531256Syl150051 
1541256Syl150051 static inline xge_queue_status_e
xge_queue_produce_context(xge_queue_h queueh,int event_type,void * context)1551256Syl150051 xge_queue_produce_context(xge_queue_h queueh, int event_type, void *context) {
1561256Syl150051 	return xge_queue_produce(queueh, event_type, context, 0, 0, 0);
1571256Syl150051 }
1581256Syl150051 
1591256Syl150051 xge_queue_status_e xge_queue_consume(xge_queue_h queueh, int data_max_size,
1601256Syl150051 		xge_queue_item_t *item);
1611256Syl150051 
1621256Syl150051 void xge_queue_flush(xge_queue_h queueh);
1631256Syl150051 
1641256Syl150051 /* ========================== PRIVATE API ================================= */
1651256Syl150051 
1661256Syl150051 xge_queue_status_e __io_queue_grow(xge_queue_h qh);
1671256Syl150051 
1681256Syl150051 int __queue_get_reset_critical (xge_queue_h qh);
1691256Syl150051 
170*3115Syl150051 __EXTERN_END_DECLS
171*3115Syl150051 
1721256Syl150051 #endif /* XGE_QUEUE_H */
173