xref: /illumos-gate/usr/src/uts/common/sys/squeue.h (revision 196b393b)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5da14cebeSEric Cheng  * Common Development and Distribution License (the "License").
6da14cebeSEric Cheng  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
229ee3959aSAnders Persson  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
23233fee3fSPatrick Mooney  * Copyright 2017 Joyent, Inc.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_SQUEUE_H
277c478bd9Sstevel@tonic-gate #define	_SYS_SQUEUE_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
307c478bd9Sstevel@tonic-gate extern "C" {
317c478bd9Sstevel@tonic-gate #endif
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate #include <sys/processor.h>
357c478bd9Sstevel@tonic-gate #include <sys/stream.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate struct squeue_s;
387c478bd9Sstevel@tonic-gate typedef struct squeue_s squeue_t;
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #define	SET_SQUEUE(mp, proc, arg) {				\
417c478bd9Sstevel@tonic-gate 	ASSERT((mp)->b_prev == NULL);				\
427c478bd9Sstevel@tonic-gate 	ASSERT((mp)->b_next == NULL);				\
437c478bd9Sstevel@tonic-gate 	(mp)->b_queue = (queue_t *)(proc);			\
447c478bd9Sstevel@tonic-gate 	(mp)->b_prev = (mblk_t *)(arg);				\
457c478bd9Sstevel@tonic-gate }
467c478bd9Sstevel@tonic-gate 
47da14cebeSEric Cheng #define	SQ_FILL		0x0001
48da14cebeSEric Cheng #define	SQ_NODRAIN	0x0002
49da14cebeSEric Cheng #define	SQ_PROCESS	0x0004
50da14cebeSEric Cheng 
51bd670b35SErik Nordmark #define	SQUEUE_ENTER(sqp, head, tail, cnt, ira, flag, tag) {	\
52bd670b35SErik Nordmark 	sqp->sq_enter(sqp, head, tail, cnt, ira, flag, tag);	\
53da14cebeSEric Cheng }
54da14cebeSEric Cheng 
55bd670b35SErik Nordmark #define	SQUEUE_ENTER_ONE(sqp, mp, proc, arg, ira, flag, tag) {	\
56da14cebeSEric Cheng 	ASSERT(mp->b_next == NULL);				\
57da14cebeSEric Cheng 	ASSERT(mp->b_prev == NULL);				\
58da14cebeSEric Cheng 	SET_SQUEUE(mp, proc, arg);				\
59bd670b35SErik Nordmark 	SQUEUE_ENTER(sqp, mp, mp, 1, ira, flag, tag);		\
60da14cebeSEric Cheng }
61da14cebeSEric Cheng 
62da14cebeSEric Cheng /*
63da14cebeSEric Cheng  * May be called only by a thread executing in the squeue. The thread must
64da14cebeSEric Cheng  * not continue to execute any code needing squeue protection after calling
65da14cebeSEric Cheng  * this macro. Please see the comments in squeue.c for more details.
66da14cebeSEric Cheng  */
67da14cebeSEric Cheng #define	SQUEUE_SWITCH(connp, new_sqp)				\
68da14cebeSEric Cheng 	(connp)->conn_sqp = new_sqp;
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate /*
717c478bd9Sstevel@tonic-gate  * Facility-special private data in squeues.
727c478bd9Sstevel@tonic-gate  */
737c478bd9Sstevel@tonic-gate typedef enum {
747c478bd9Sstevel@tonic-gate 	SQPRIVATE_TCP,
757c478bd9Sstevel@tonic-gate 	SQPRIVATE_MAX
767c478bd9Sstevel@tonic-gate } sqprivate_t;
777c478bd9Sstevel@tonic-gate 
78bd670b35SErik Nordmark struct ip_recv_attr_s;
797c478bd9Sstevel@tonic-gate extern void squeue_init(void);
80233fee3fSPatrick Mooney extern squeue_t *squeue_create(pri_t);
817c478bd9Sstevel@tonic-gate extern void squeue_bind(squeue_t *, processorid_t);
827c478bd9Sstevel@tonic-gate extern void squeue_unbind(squeue_t *);
83da14cebeSEric Cheng extern void squeue_enter(squeue_t *, mblk_t *, mblk_t *,
84bd670b35SErik Nordmark     uint32_t, struct ip_recv_attr_s *, int, uint8_t);
857c478bd9Sstevel@tonic-gate extern uintptr_t *squeue_getprivate(squeue_t *, sqprivate_t);
867c478bd9Sstevel@tonic-gate 
87f3124163SAnders Persson struct conn_s;
889ee3959aSAnders Persson extern int squeue_synch_enter(struct conn_s *, mblk_t *);
89*196b393bSPatrick Mooney extern void squeue_synch_exit(struct conn_s *, int);
900f1702c5SYu Xiangning 
917c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
927c478bd9Sstevel@tonic-gate }
937c478bd9Sstevel@tonic-gate #endif
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate #endif	/* _SYS_SQUEUE_H */
96