xref: /onnv-gate/usr/src/uts/common/sys/strsubr.h (revision 6769:c1faa4d16a30)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52712Snn35248  * Common Development and Distribution License (the "License").
62712Snn35248  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
220Sstevel@tonic-gate /*	  All Rights Reserved  	*/
230Sstevel@tonic-gate 
240Sstevel@tonic-gate 
250Sstevel@tonic-gate /*
266380Sjk115741  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
270Sstevel@tonic-gate  * Use is subject to license terms.
280Sstevel@tonic-gate  */
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #ifndef _SYS_STRSUBR_H
310Sstevel@tonic-gate #define	_SYS_STRSUBR_H
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.17 */
340Sstevel@tonic-gate 
350Sstevel@tonic-gate /*
360Sstevel@tonic-gate  * WARNING:
370Sstevel@tonic-gate  * Everything in this file is private, belonging to the
380Sstevel@tonic-gate  * STREAMS subsystem.  The only guarantee made about the
390Sstevel@tonic-gate  * contents of this file is that if you include it, your
400Sstevel@tonic-gate  * code will not port to the next release.
410Sstevel@tonic-gate  */
420Sstevel@tonic-gate #include <sys/stream.h>
430Sstevel@tonic-gate #include <sys/stropts.h>
440Sstevel@tonic-gate #include <sys/kstat.h>
450Sstevel@tonic-gate #include <sys/uio.h>
460Sstevel@tonic-gate #include <sys/proc.h>
473448Sdh155122 #include <sys/netstack.h>
483448Sdh155122 #include <sys/modhash.h>
496707Sbrutus #include <sys/sodirect.h>
500Sstevel@tonic-gate 
510Sstevel@tonic-gate #ifdef	__cplusplus
520Sstevel@tonic-gate extern "C" {
530Sstevel@tonic-gate #endif
540Sstevel@tonic-gate 
550Sstevel@tonic-gate /*
560Sstevel@tonic-gate  * In general, the STREAMS locks are disjoint; they are only held
570Sstevel@tonic-gate  * locally, and not simultaneously by a thread.  However, module
580Sstevel@tonic-gate  * code, including at the stream head, requires some locks to be
590Sstevel@tonic-gate  * acquired in order for its safety.
600Sstevel@tonic-gate  *	1. Stream level claim.  This prevents the value of q_next
610Sstevel@tonic-gate  *		from changing while module code is executing.
620Sstevel@tonic-gate  *	2. Queue level claim.  This prevents the value of q_ptr
630Sstevel@tonic-gate  *		from changing while put or service code is executing.
640Sstevel@tonic-gate  *		In addition, it provides for queue single-threading
650Sstevel@tonic-gate  *		for QPAIR and PERQ MT-safe modules.
660Sstevel@tonic-gate  *	3. Stream head lock.  May be held by the stream head module
670Sstevel@tonic-gate  *		to implement a read/write/open/close monitor.
680Sstevel@tonic-gate  *	   Note: that the only types of twisted stream supported are
690Sstevel@tonic-gate  *	   the pipe and transports which have read and write service
700Sstevel@tonic-gate  *	   procedures on both sides of the twist.
710Sstevel@tonic-gate  *	4. Queue lock.  May be acquired by utility routines on
720Sstevel@tonic-gate  *		behalf of a module.
730Sstevel@tonic-gate  */
740Sstevel@tonic-gate 
750Sstevel@tonic-gate /*
760Sstevel@tonic-gate  * In general, sd_lock protects the consistency of the stdata
770Sstevel@tonic-gate  * structure.  Additionally, it is used with sd_monitor
780Sstevel@tonic-gate  * to implement an open/close monitor.  In particular, it protects
790Sstevel@tonic-gate  * the following fields:
800Sstevel@tonic-gate  *	sd_iocblk
810Sstevel@tonic-gate  *	sd_flag
820Sstevel@tonic-gate  *	sd_copyflag
830Sstevel@tonic-gate  *	sd_iocid
840Sstevel@tonic-gate  *	sd_iocwait
850Sstevel@tonic-gate  *	sd_sidp
860Sstevel@tonic-gate  *	sd_pgidp
870Sstevel@tonic-gate  *	sd_wroff
88898Skais  *	sd_tail
890Sstevel@tonic-gate  *	sd_rerror
900Sstevel@tonic-gate  *	sd_werror
910Sstevel@tonic-gate  *	sd_pushcnt
920Sstevel@tonic-gate  *	sd_sigflags
930Sstevel@tonic-gate  *	sd_siglist
940Sstevel@tonic-gate  *	sd_pollist
950Sstevel@tonic-gate  *	sd_mark
960Sstevel@tonic-gate  *	sd_closetime
970Sstevel@tonic-gate  *	sd_wakeq
980Sstevel@tonic-gate  *	sd_maxblk
996707Sbrutus  *	sd_sodirect
1000Sstevel@tonic-gate  *
1010Sstevel@tonic-gate  * The following fields are modified only by the allocator, which
1020Sstevel@tonic-gate  * has exclusive access to them at that time:
1030Sstevel@tonic-gate  *	sd_wrq
1040Sstevel@tonic-gate  *	sd_strtab
1050Sstevel@tonic-gate  *
1060Sstevel@tonic-gate  * The following field is protected by the overlying file system
1070Sstevel@tonic-gate  * code, guaranteeing single-threading of opens:
1080Sstevel@tonic-gate  *	sd_vnode
1090Sstevel@tonic-gate  *
1100Sstevel@tonic-gate  * Stream-level locks should be acquired before any queue-level locks
1110Sstevel@tonic-gate  *	are acquired.
1120Sstevel@tonic-gate  *
1130Sstevel@tonic-gate  * The stream head write queue lock(sd_wrq) is used to protect the
1140Sstevel@tonic-gate  * fields qn_maxpsz and qn_minpsz because freezestr() which is
1150Sstevel@tonic-gate  * necessary for strqset() only gets the queue lock.
1160Sstevel@tonic-gate  */
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate /*
1190Sstevel@tonic-gate  * Function types for the parameterized stream head.
1200Sstevel@tonic-gate  * The msgfunc_t takes the parameters:
1210Sstevel@tonic-gate  * 	msgfunc(vnode_t *vp, mblk_t *mp, strwakeup_t *wakeups,
1220Sstevel@tonic-gate  *		strsigset_t *firstmsgsigs, strsigset_t *allmsgsigs,
1230Sstevel@tonic-gate  *		strpollset_t *pollwakeups);
1240Sstevel@tonic-gate  * It returns an optional message to be processed by the stream head.
1250Sstevel@tonic-gate  *
1260Sstevel@tonic-gate  * The parameters for errfunc_t are:
1270Sstevel@tonic-gate  *	errfunc(vnode *vp, int ispeek, int *clearerr);
1280Sstevel@tonic-gate  * It returns an errno and zero if there was no pending error.
1290Sstevel@tonic-gate  */
1300Sstevel@tonic-gate typedef uint_t	strwakeup_t;
1310Sstevel@tonic-gate typedef uint_t	strsigset_t;
1320Sstevel@tonic-gate typedef short	strpollset_t;
1330Sstevel@tonic-gate typedef uintptr_t callbparams_id_t;
1340Sstevel@tonic-gate typedef	mblk_t	*(*msgfunc_t)(vnode_t *, mblk_t *, strwakeup_t *,
1350Sstevel@tonic-gate 			strsigset_t *, strsigset_t *, strpollset_t *);
1360Sstevel@tonic-gate typedef int 	(*errfunc_t)(vnode_t *, int, int *);
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate /*
1390Sstevel@tonic-gate  * Per stream sd_lock in putnext may be replaced by per cpu stream_putlocks
1400Sstevel@tonic-gate  * each living in a separate cache line. putnext/canputnext grabs only one of
1410Sstevel@tonic-gate  * stream_putlocks while strlock() (called on behalf of insertq()/removeq())
1420Sstevel@tonic-gate  * acquires all stream_putlocks. Normally stream_putlocks are only employed
1430Sstevel@tonic-gate  * for highly contended streams that have SQ_CIPUT queues in the critical path
1440Sstevel@tonic-gate  * (e.g. NFS/UDP stream).
1450Sstevel@tonic-gate  *
1460Sstevel@tonic-gate  * stream_putlocks are dynamically assigned to stdata structure through
1470Sstevel@tonic-gate  * sd_ciputctrl pointer possibly when a stream is already in use. Since
1480Sstevel@tonic-gate  * strlock() uses stream_putlocks only under sd_lock acquiring sd_lock when
1490Sstevel@tonic-gate  * assigning stream_putlocks to the stream ensures synchronization with
1500Sstevel@tonic-gate  * strlock().
1510Sstevel@tonic-gate  *
1520Sstevel@tonic-gate  * For lock ordering purposes stream_putlocks are treated as the extension of
1530Sstevel@tonic-gate  * sd_lock and are always grabbed right after grabbing sd_lock and released
1540Sstevel@tonic-gate  * right before releasing sd_lock except putnext/canputnext where only one of
1550Sstevel@tonic-gate  * stream_putlocks locks is used and where it is the first lock to grab.
1560Sstevel@tonic-gate  */
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate typedef struct ciputctrl_str {
1590Sstevel@tonic-gate 	union _ciput_un {
1600Sstevel@tonic-gate 		uchar_t	pad[64];
1610Sstevel@tonic-gate 		struct _ciput_str {
1620Sstevel@tonic-gate 			kmutex_t	ciput_lck;
1630Sstevel@tonic-gate 			ushort_t	ciput_cnt;
1640Sstevel@tonic-gate 		} ciput_str;
1650Sstevel@tonic-gate 	} ciput_un;
1660Sstevel@tonic-gate } ciputctrl_t;
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate #define	ciputctrl_lock	ciput_un.ciput_str.ciput_lck
1690Sstevel@tonic-gate #define	ciputctrl_count	ciput_un.ciput_str.ciput_cnt
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate /*
1720Sstevel@tonic-gate  * Header for a stream: interface to rest of system.
1733027Smeem  *
1743027Smeem  * NOTE: While this is a consolidation-private structure, some unbundled and
1753027Smeem  *       third-party products inappropriately make use of some of the fields.
1763027Smeem  *       As such, please take care to not gratuitously change any offsets of
1773027Smeem  *       existing members.
1780Sstevel@tonic-gate  */
1790Sstevel@tonic-gate typedef struct stdata {
1800Sstevel@tonic-gate 	struct queue	*sd_wrq;	/* write queue */
1810Sstevel@tonic-gate 	struct msgb	*sd_iocblk;	/* return block for ioctl */
1820Sstevel@tonic-gate 	struct vnode	*sd_vnode;	/* pointer to associated vnode */
1830Sstevel@tonic-gate 	struct streamtab *sd_strtab;	/* pointer to streamtab for stream */
1840Sstevel@tonic-gate 	uint_t		sd_flag;	/* state/flags */
1850Sstevel@tonic-gate 	uint_t		sd_iocid;	/* ioctl id */
1860Sstevel@tonic-gate 	struct pid	*sd_sidp;	/* controlling session info */
1870Sstevel@tonic-gate 	struct pid	*sd_pgidp;	/* controlling process group info */
1883027Smeem 	ushort_t	sd_tail;	/* reserved space in written mblks */
1890Sstevel@tonic-gate 	ushort_t	sd_wroff;	/* write offset */
1900Sstevel@tonic-gate 	int		sd_rerror;	/* error to return on read ops */
1910Sstevel@tonic-gate 	int		sd_werror;	/* error to return on write ops */
1920Sstevel@tonic-gate 	int		sd_pushcnt;	/* number of pushes done on stream */
1930Sstevel@tonic-gate 	int		sd_sigflags;	/* logical OR of all siglist events */
1940Sstevel@tonic-gate 	struct strsig	*sd_siglist;	/* pid linked list to rcv SIGPOLL sig */
1950Sstevel@tonic-gate 	struct pollhead sd_pollist;	/* list of all pollers to wake up */
1960Sstevel@tonic-gate 	struct msgb	*sd_mark;	/* "marked" message on read queue */
1970Sstevel@tonic-gate 	clock_t		sd_closetime;	/* time to wait to drain q in close */
1980Sstevel@tonic-gate 	kmutex_t	sd_lock;	/* protect head consistency */
1990Sstevel@tonic-gate 	kcondvar_t	sd_monitor;	/* open/close/push/pop monitor */
2000Sstevel@tonic-gate 	kcondvar_t	sd_iocmonitor;	/* ioctl single-threading */
201166Sxy158873 	kcondvar_t	sd_refmonitor;	/* sd_refcnt monitor */
2020Sstevel@tonic-gate 	ssize_t		sd_qn_minpsz;	/* These two fields are a performance */
2030Sstevel@tonic-gate 	ssize_t		sd_qn_maxpsz;	/* enhancements, cache the values in */
2040Sstevel@tonic-gate 					/* the stream head so we don't have */
2050Sstevel@tonic-gate 					/* to ask the module below the stream */
2060Sstevel@tonic-gate 					/* head to get this information. */
2070Sstevel@tonic-gate 	struct stdata	*sd_mate;	/* pointer to twisted stream mate */
2080Sstevel@tonic-gate 	kthread_id_t	sd_freezer;	/* thread that froze stream */
2090Sstevel@tonic-gate 	kmutex_t	sd_reflock;	/* Protects sd_refcnt */
2100Sstevel@tonic-gate 	int		sd_refcnt;	/* number of claimstr */
2110Sstevel@tonic-gate 	uint_t		sd_wakeq;	/* strwakeq()'s copy of sd_flag */
2120Sstevel@tonic-gate 	struct queue	*sd_struiordq;	/* sync barrier struio() read queue */
2130Sstevel@tonic-gate 	struct queue	*sd_struiowrq;	/* sync barrier struio() write queue */
2140Sstevel@tonic-gate 	char		sd_struiodnak;	/* defer NAK of M_IOCTL by rput() */
2150Sstevel@tonic-gate 	struct msgb	*sd_struionak;	/* pointer M_IOCTL mblk(s) to NAK */
2160Sstevel@tonic-gate 	caddr_t		sd_t_audit_data; /* For audit purposes only */
2170Sstevel@tonic-gate 	ssize_t		sd_maxblk;	/* maximum message block size */
2180Sstevel@tonic-gate 	uint_t		sd_rput_opt;	/* options/flags for strrput */
2190Sstevel@tonic-gate 	uint_t		sd_wput_opt;	/* options/flags for write/putmsg */
2200Sstevel@tonic-gate 	uint_t		sd_read_opt;	/* options/flags for strread */
2210Sstevel@tonic-gate 	msgfunc_t	sd_rprotofunc;	/* rput M_*PROTO routine */
222898Skais 	msgfunc_t	sd_rputdatafunc; /* read M_DATA routine */
2230Sstevel@tonic-gate 	msgfunc_t	sd_rmiscfunc;	/* rput routine (non-data/proto) */
224898Skais 	msgfunc_t	sd_wputdatafunc; /* wput M_DATA routine */
2250Sstevel@tonic-gate 	errfunc_t	sd_rderrfunc;	/* read side error callback */
2260Sstevel@tonic-gate 	errfunc_t	sd_wrerrfunc;	/* write side error callback */
2270Sstevel@tonic-gate 	/*
2280Sstevel@tonic-gate 	 * support for low contention concurrent putnext.
2290Sstevel@tonic-gate 	 */
2300Sstevel@tonic-gate 	ciputctrl_t	*sd_ciputctrl;
2310Sstevel@tonic-gate 	uint_t		sd_nciputctrl;
2320Sstevel@tonic-gate 
2330Sstevel@tonic-gate 	int		sd_anchor;	/* position of anchor in stream */
2340Sstevel@tonic-gate 	/*
2350Sstevel@tonic-gate 	 * Service scheduling at the stream head.
2360Sstevel@tonic-gate 	 */
2370Sstevel@tonic-gate 	kmutex_t	sd_qlock;
2380Sstevel@tonic-gate 	struct queue	*sd_qhead;	/* Head of queues to be serviced. */
2390Sstevel@tonic-gate 	struct queue	*sd_qtail;	/* Tail of queues to be serviced. */
2400Sstevel@tonic-gate 	void		*sd_servid;	/* Service ID for bckgrnd schedule */
2410Sstevel@tonic-gate 	ushort_t	sd_svcflags;	/* Servicing flags */
2420Sstevel@tonic-gate 	short		sd_nqueues;	/* Number of queues in the list */
2430Sstevel@tonic-gate 	kcondvar_t	sd_qcv;		/* Waiters for qhead to become empty */
2440Sstevel@tonic-gate 	kcondvar_t	sd_zcopy_wait;
2450Sstevel@tonic-gate 	uint_t		sd_copyflag;	/* copy-related flags */
2463448Sdh155122 	zoneid_t	sd_anchorzone;	/* Allow removal from same zone only */
2476583Smeem 	struct msgb	*sd_cmdblk;	/* reply from _I_CMD */
2486707Sbrutus 	/*
2496707Sbrutus 	 * Support for socket direct.
2506707Sbrutus 	 */
2516707Sbrutus 	sodirect_t	*sd_sodirect;	/* pointer to shared sodirect_t */
2520Sstevel@tonic-gate } stdata_t;
2530Sstevel@tonic-gate 
2540Sstevel@tonic-gate /*
2550Sstevel@tonic-gate  * stdata servicing flags.
2560Sstevel@tonic-gate  */
2570Sstevel@tonic-gate #define	STRS_WILLSERVICE	0x01
2580Sstevel@tonic-gate #define	STRS_SCHEDULED		0x02
2590Sstevel@tonic-gate 
2600Sstevel@tonic-gate #define	STREAM_NEEDSERVICE(stp)	((stp)->sd_qhead != NULL)
2610Sstevel@tonic-gate 
2620Sstevel@tonic-gate /*
2630Sstevel@tonic-gate  * stdata flag field defines
2640Sstevel@tonic-gate  */
2650Sstevel@tonic-gate #define	IOCWAIT		0x00000001	/* Someone is doing an ioctl */
2660Sstevel@tonic-gate #define	RSLEEP		0x00000002	/* Someone wants to read/recv msg */
2670Sstevel@tonic-gate #define	WSLEEP		0x00000004	/* Someone wants to write */
2680Sstevel@tonic-gate #define	STRPRI		0x00000008	/* An M_PCPROTO is at stream head */
2690Sstevel@tonic-gate #define	STRHUP		0x00000010	/* Device has vanished */
2700Sstevel@tonic-gate #define	STWOPEN		0x00000020	/* waiting for 1st open */
2710Sstevel@tonic-gate #define	STPLEX		0x00000040	/* stream is being multiplexed */
2720Sstevel@tonic-gate #define	STRISTTY	0x00000080	/* stream is a terminal */
2730Sstevel@tonic-gate #define	STRGETINPROG	0x00000100	/* (k)strgetmsg is running */
2740Sstevel@tonic-gate #define	IOCWAITNE	0x00000200	/* STR_NOERROR ioctl running */
2750Sstevel@tonic-gate #define	STRDERR		0x00000400	/* fatal read error from M_ERROR */
2760Sstevel@tonic-gate #define	STWRERR		0x00000800	/* fatal write error from M_ERROR */
2770Sstevel@tonic-gate #define	STRDERRNONPERSIST 0x00001000	/* nonpersistent read errors */
2780Sstevel@tonic-gate #define	STWRERRNONPERSIST 0x00002000	/* nonpersistent write errors */
2790Sstevel@tonic-gate #define	STRCLOSE	0x00004000	/* wait for a close to complete */
2800Sstevel@tonic-gate #define	SNDMREAD	0x00008000	/* used for read notification */
2810Sstevel@tonic-gate #define	OLDNDELAY	0x00010000	/* use old TTY semantics for */
2820Sstevel@tonic-gate 					/* NDELAY reads and writes */
2830Sstevel@tonic-gate 	/*		0x00020000	   unused */
2840Sstevel@tonic-gate 	/*		0x00040000	   unused */
2850Sstevel@tonic-gate #define	STRTOSTOP	0x00080000	/* block background writes */
2866583Smeem #define	STRCMDWAIT	0x00100000 	/* someone is doing an _I_CMD */
2870Sstevel@tonic-gate 	/*		0x00200000	   unused */
2880Sstevel@tonic-gate #define	STRMOUNT	0x00400000	/* stream is mounted */
2890Sstevel@tonic-gate #define	STRNOTATMARK	0x00800000	/* Not at mark (when empty read q) */
2900Sstevel@tonic-gate #define	STRDELIM	0x01000000	/* generate delimited messages */
2910Sstevel@tonic-gate #define	STRATMARK	0x02000000	/* At mark (due to MSGMARKNEXT) */
2920Sstevel@tonic-gate #define	STZCNOTIFY	0x04000000	/* wait for zerocopy mblk to be acked */
2930Sstevel@tonic-gate #define	STRPLUMB	0x08000000	/* push/pop pending */
2940Sstevel@tonic-gate #define	STREOF		0x10000000	/* End-of-file indication */
2950Sstevel@tonic-gate #define	STREOPENFAIL	0x20000000	/* indicates if re-open has failed */
2960Sstevel@tonic-gate #define	STRMATE		0x40000000	/* this stream is a mate */
2970Sstevel@tonic-gate #define	STRHASLINKS	0x80000000	/* I_LINKs under this stream */
2980Sstevel@tonic-gate 
2990Sstevel@tonic-gate /*
3000Sstevel@tonic-gate  * Copy-related flags (sd_copyflag), set by SO_COPYOPT.
3010Sstevel@tonic-gate  */
3020Sstevel@tonic-gate #define	STZCVMSAFE	0x00000001	/* safe to borrow file (segmapped) */
3030Sstevel@tonic-gate 					/* pages instead of bcopy */
3040Sstevel@tonic-gate #define	STZCVMUNSAFE	0x00000002	/* unsafe to borrow file pages */
3050Sstevel@tonic-gate #define	STRCOPYCACHED	0x00000004	/* copy should NOT bypass cache */
3060Sstevel@tonic-gate 
3070Sstevel@tonic-gate /*
3080Sstevel@tonic-gate  * Options and flags for strrput (sd_rput_opt)
3090Sstevel@tonic-gate  */
3100Sstevel@tonic-gate #define	SR_POLLIN	0x00000001	/* pollwakeup needed for band0 data */
3110Sstevel@tonic-gate #define	SR_SIGALLDATA	0x00000002	/* Send SIGPOLL for all M_DATA */
3120Sstevel@tonic-gate #define	SR_CONSOL_DATA	0x00000004	/* Consolidate M_DATA onto q_last */
3130Sstevel@tonic-gate #define	SR_IGN_ZEROLEN	0x00000008	/* Ignore zero-length M_DATA */
3140Sstevel@tonic-gate 
3150Sstevel@tonic-gate /*
3160Sstevel@tonic-gate  * Options and flags for strwrite/strputmsg (sd_wput_opt)
3170Sstevel@tonic-gate  */
3180Sstevel@tonic-gate #define	SW_SIGPIPE	0x00000001	/* Send SIGPIPE for write error */
3190Sstevel@tonic-gate #define	SW_RECHECK_ERR	0x00000002	/* Recheck errors in strwrite loop */
3200Sstevel@tonic-gate #define	SW_SNDZERO	0x00000004	/* send 0-length msg down pipe/FIFO */
3210Sstevel@tonic-gate 
3220Sstevel@tonic-gate /*
3230Sstevel@tonic-gate  * Options and flags for strread (sd_read_opt)
3240Sstevel@tonic-gate  */
3250Sstevel@tonic-gate #define	RD_MSGDIS	0x00000001	/* read msg discard */
3260Sstevel@tonic-gate #define	RD_MSGNODIS	0x00000002	/* read msg no discard */
3270Sstevel@tonic-gate #define	RD_PROTDAT	0x00000004	/* read M_[PC]PROTO contents as data */
3280Sstevel@tonic-gate #define	RD_PROTDIS	0x00000008	/* discard M_[PC]PROTO blocks and */
3290Sstevel@tonic-gate 					/* retain data blocks */
3300Sstevel@tonic-gate /*
3310Sstevel@tonic-gate  * Flags parameter for strsetrputhooks() and strsetwputhooks().
3320Sstevel@tonic-gate  * These flags define the interface for setting the above internal
3330Sstevel@tonic-gate  * flags in sd_rput_opt and sd_wput_opt.
3340Sstevel@tonic-gate  */
3350Sstevel@tonic-gate #define	SH_CONSOL_DATA	0x00000001	/* Consolidate M_DATA onto q_last */
3360Sstevel@tonic-gate #define	SH_SIGALLDATA	0x00000002	/* Send SIGPOLL for all M_DATA */
3370Sstevel@tonic-gate #define	SH_IGN_ZEROLEN	0x00000004	/* Drop zero-length M_DATA */
3380Sstevel@tonic-gate 
3390Sstevel@tonic-gate #define	SH_SIGPIPE	0x00000100	/* Send SIGPIPE for write error */
3400Sstevel@tonic-gate #define	SH_RECHECK_ERR	0x00000200	/* Recheck errors in strwrite loop */
3410Sstevel@tonic-gate 
3420Sstevel@tonic-gate /*
3430Sstevel@tonic-gate  * Each queue points to a sync queue (the inner perimeter) which keeps
3440Sstevel@tonic-gate  * track of the number of threads that are inside a given queue (sq_count)
3450Sstevel@tonic-gate  * and also is used to implement the asynchronous putnext
3460Sstevel@tonic-gate  * (by queuing messages if the queue can not be entered.)
3470Sstevel@tonic-gate  *
3480Sstevel@tonic-gate  * Messages are queued on sq_head/sq_tail including deferred qwriter(INNER)
3490Sstevel@tonic-gate  * messages. The sq_head/sq_tail list is a singly-linked list with
3500Sstevel@tonic-gate  * b_queue recording the queue and b_prev recording the function to
3510Sstevel@tonic-gate  * be called (either the put procedure or a qwriter callback function.)
3520Sstevel@tonic-gate  *
3530Sstevel@tonic-gate  * The sq_count counter tracks the number of threads that are
3540Sstevel@tonic-gate  * executing inside the perimeter or (in the case of outer perimeters)
3550Sstevel@tonic-gate  * have some work queued for them relating to the perimeter. The sq_rmqcount
3560Sstevel@tonic-gate  * counter tracks the subset which are in removeq() (usually invoked from
3570Sstevel@tonic-gate  * qprocsoff(9F)).
3580Sstevel@tonic-gate  *
3590Sstevel@tonic-gate  * In addition a module writer can declare that the module has an outer
3600Sstevel@tonic-gate  * perimeter (by setting D_MTOUTPERIM) in which case all inner perimeter
3610Sstevel@tonic-gate  * syncq's for the module point (through sq_outer) to an outer perimeter
3620Sstevel@tonic-gate  * syncq. The outer perimeter consists of the doubly linked list (sq_onext and
3630Sstevel@tonic-gate  * sq_oprev) linking all the inner perimeter syncq's with out outer perimeter
3640Sstevel@tonic-gate  * syncq. This is used to implement qwriter(OUTER) (an asynchronous way of
3650Sstevel@tonic-gate  * getting exclusive access at the outer perimeter) and outer_enter/exit
3660Sstevel@tonic-gate  * which are used by the framework to acquire exclusive access to the outer
3670Sstevel@tonic-gate  * perimeter during open and close of modules that have set D_MTOUTPERIM.
3680Sstevel@tonic-gate  *
3690Sstevel@tonic-gate  * In the inner perimeter case sq_save is available for use by machine
3700Sstevel@tonic-gate  * dependent code. sq_head/sq_tail are used to queue deferred messages on
3710Sstevel@tonic-gate  * the inner perimeter syncqs and to queue become_writer requests on the
3720Sstevel@tonic-gate  * outer perimeter syncqs.
3730Sstevel@tonic-gate  *
3740Sstevel@tonic-gate  * Note: machine dependent optimized versions of putnext may depend
3750Sstevel@tonic-gate  * on the order of sq_flags and sq_count (so that they can e.g.
3760Sstevel@tonic-gate  * read these two fields in a single load instruction.)
3770Sstevel@tonic-gate  *
3780Sstevel@tonic-gate  * Per perimeter SQLOCK/sq_count in putnext/put may be replaced by per cpu
3790Sstevel@tonic-gate  * sq_putlocks/sq_putcounts each living in a separate cache line. Obviously
3800Sstevel@tonic-gate  * sq_putlock[x] protects sq_putcount[x]. putnext/put routine will grab only 1
3810Sstevel@tonic-gate  * of sq_putlocks and update only 1 of sq_putcounts. strlock() and many
3820Sstevel@tonic-gate  * other routines in strsubr.c and ddi.c will grab all sq_putlocks (as well as
3830Sstevel@tonic-gate  * SQLOCK) and figure out the count value as the sum of sq_count and all of
3840Sstevel@tonic-gate  * sq_putcounts. The idea is to make critical fast path -- putnext -- much
3850Sstevel@tonic-gate  * faster at the expense of much less often used slower path like
3860Sstevel@tonic-gate  * strlock(). One known case where entersq/strlock is executed pretty often is
3870Sstevel@tonic-gate  * SpecWeb but since IP is SQ_CIOC and socket TCP/IP stream is nextless
3880Sstevel@tonic-gate  * there's no need to grab multiple sq_putlocks and look at sq_putcounts. See
3890Sstevel@tonic-gate  * strsubr.c for more comments.
3900Sstevel@tonic-gate  *
3910Sstevel@tonic-gate  * Note regular SQLOCK and sq_count are still used in many routines
3920Sstevel@tonic-gate  * (e.g. entersq(), rwnext()) in the same way as before sq_putlocks were
3930Sstevel@tonic-gate  * introduced.
3940Sstevel@tonic-gate  *
3950Sstevel@tonic-gate  * To understand when all sq_putlocks need to be held and all sq_putcounts
3960Sstevel@tonic-gate  * need to be added up one needs to look closely at putnext code. Basically if
3970Sstevel@tonic-gate  * a routine like e.g. wait_syncq() needs to be sure that perimeter is empty
3980Sstevel@tonic-gate  * all sq_putlocks/sq_putcounts need to be held/added up. On the other hand
3990Sstevel@tonic-gate  * there's no need to hold all sq_putlocks and count all sq_putcounts in
4000Sstevel@tonic-gate  * routines like leavesq()/dropsq() and etc. since the are usually exit
4010Sstevel@tonic-gate  * counterparts of entersq/outer_enter() and etc. which have already either
4020Sstevel@tonic-gate  * prevented put entry poins from executing or did not care about put
4030Sstevel@tonic-gate  * entrypoints. entersq() doesn't need to care about sq_putlocks/sq_putcounts
4040Sstevel@tonic-gate  * if the entry point has a shared access since put has the highest degree of
4050Sstevel@tonic-gate  * concurrency and such entersq() does not intend to block out put
4060Sstevel@tonic-gate  * entrypoints.
4070Sstevel@tonic-gate  *
4080Sstevel@tonic-gate  * Before sq_putcounts were introduced the standard way to wait for perimeter
4090Sstevel@tonic-gate  * to become empty was:
4100Sstevel@tonic-gate  *
4110Sstevel@tonic-gate  *	mutex_enter(SQLOCK(sq));
4120Sstevel@tonic-gate  *	while (sq->sq_count > 0) {
4130Sstevel@tonic-gate  *		sq->sq_flags |= SQ_WANTWAKEUP;
4140Sstevel@tonic-gate  *		cv_wait(&sq->sq_wait, SQLOCK(sq));
4150Sstevel@tonic-gate  *	}
4160Sstevel@tonic-gate  *	mutex_exit(SQLOCK(sq));
4170Sstevel@tonic-gate  *
4180Sstevel@tonic-gate  * The new way is:
4190Sstevel@tonic-gate  *
4200Sstevel@tonic-gate  * 	mutex_enter(SQLOCK(sq));
4210Sstevel@tonic-gate  *	count = sq->sq_count;
4220Sstevel@tonic-gate  *	SQ_PUTLOCKS_ENTER(sq);
4230Sstevel@tonic-gate  *	SUM_SQ_PUTCOUNTS(sq, count);
4240Sstevel@tonic-gate  *	while (count != 0) {
4250Sstevel@tonic-gate  *		sq->sq_flags |= SQ_WANTWAKEUP;
4260Sstevel@tonic-gate  *		SQ_PUTLOCKS_EXIT(sq);
4270Sstevel@tonic-gate  *		cv_wait(&sq->sq_wait, SQLOCK(sq));
4280Sstevel@tonic-gate  *		count = sq->sq_count;
4290Sstevel@tonic-gate  *		SQ_PUTLOCKS_ENTER(sq);
4300Sstevel@tonic-gate  *		SUM_SQ_PUTCOUNTS(sq, count);
4310Sstevel@tonic-gate  *	}
4320Sstevel@tonic-gate  *	SQ_PUTLOCKS_EXIT(sq);
4330Sstevel@tonic-gate  *	mutex_exit(SQLOCK(sq));
4340Sstevel@tonic-gate  *
4350Sstevel@tonic-gate  * Note that SQ_WANTWAKEUP is set before dropping SQ_PUTLOCKS. This makes sure
4360Sstevel@tonic-gate  * putnext won't skip a wakeup.
4370Sstevel@tonic-gate  *
4380Sstevel@tonic-gate  * sq_putlocks are treated as the extension of SQLOCK for lock ordering
4390Sstevel@tonic-gate  * purposes and are always grabbed right after grabbing SQLOCK and released
4400Sstevel@tonic-gate  * right before releasing SQLOCK. This also allows dynamic creation of
4410Sstevel@tonic-gate  * sq_putlocks while holding SQLOCK (by making sq_ciputctrl non null even when
4420Sstevel@tonic-gate  * the stream is already in use). Only in putnext one of sq_putlocks
4430Sstevel@tonic-gate  * is grabbed instead of SQLOCK. putnext return path remembers what counter it
4440Sstevel@tonic-gate  * incremented and decrements the right counter on its way out.
4450Sstevel@tonic-gate  */
4460Sstevel@tonic-gate 
4470Sstevel@tonic-gate struct syncq {
4480Sstevel@tonic-gate 	kmutex_t	sq_lock;	/* atomic access to syncq */
4490Sstevel@tonic-gate 	uint16_t	sq_count;	/* # threads inside */
4500Sstevel@tonic-gate 	uint16_t	sq_flags;	/* state and some type info */
4510Sstevel@tonic-gate 	/*
4520Sstevel@tonic-gate 	 * Distributed syncq scheduling
4530Sstevel@tonic-gate 	 *  The list of queue's is handled by sq_head and
4540Sstevel@tonic-gate 	 *  sq_tail fields.
4550Sstevel@tonic-gate 	 *
4560Sstevel@tonic-gate 	 *  The list of events is handled by the sq_evhead and sq_evtail
4570Sstevel@tonic-gate 	 *  fields.
4580Sstevel@tonic-gate 	 */
4590Sstevel@tonic-gate 	queue_t		*sq_head;	/* queue of deferred messages */
4600Sstevel@tonic-gate 	queue_t		*sq_tail;	/* queue of deferred messages */
4610Sstevel@tonic-gate 	mblk_t		*sq_evhead;	/* Event message on the syncq */
4620Sstevel@tonic-gate 	mblk_t		*sq_evtail;
4630Sstevel@tonic-gate 	uint_t		sq_nqueues;	/* # of queues on this sq */
4640Sstevel@tonic-gate 	/*
4650Sstevel@tonic-gate 	 * Concurrency and condition variables
4660Sstevel@tonic-gate 	 */
4670Sstevel@tonic-gate 	uint16_t	sq_type;	/* type (concurrency) of syncq */
4680Sstevel@tonic-gate 	uint16_t	sq_rmqcount;	/* # threads inside removeq() */
4690Sstevel@tonic-gate 	kcondvar_t 	sq_wait;	/* block on this sync queue */
4700Sstevel@tonic-gate 	kcondvar_t 	sq_exitwait;	/* waiting for thread to leave the */
4710Sstevel@tonic-gate 					/* inner perimeter */
4720Sstevel@tonic-gate 	/*
4730Sstevel@tonic-gate 	 * Handling synchronous callbacks such as qtimeout and qbufcall
4740Sstevel@tonic-gate 	 */
4750Sstevel@tonic-gate 	ushort_t	sq_callbflags;	/* flags for callback synchronization */
4760Sstevel@tonic-gate 	callbparams_id_t sq_cancelid;	/* id of callback being cancelled */
4770Sstevel@tonic-gate 	struct callbparams *sq_callbpend;	/* Pending callbacks */
4780Sstevel@tonic-gate 
4790Sstevel@tonic-gate 	/*
4800Sstevel@tonic-gate 	 * Links forming an outer perimeter from one outer syncq and
4810Sstevel@tonic-gate 	 * a set of inner sync queues.
4820Sstevel@tonic-gate 	 */
4830Sstevel@tonic-gate 	struct syncq	*sq_outer;	/* Pointer to outer perimeter */
4840Sstevel@tonic-gate 	struct syncq	*sq_onext;	/* Linked list of syncq's making */
4850Sstevel@tonic-gate 	struct syncq	*sq_oprev;	/* up the outer perimeter. */
4860Sstevel@tonic-gate 	/*
4870Sstevel@tonic-gate 	 * support for low contention concurrent putnext.
4880Sstevel@tonic-gate 	 */
4890Sstevel@tonic-gate 	ciputctrl_t	*sq_ciputctrl;
4900Sstevel@tonic-gate 	uint_t		sq_nciputctrl;
4910Sstevel@tonic-gate 	/*
4920Sstevel@tonic-gate 	 * Counter for the number of threads wanting to become exclusive.
4930Sstevel@tonic-gate 	 */
4940Sstevel@tonic-gate 	uint_t		sq_needexcl;
4950Sstevel@tonic-gate 	/*
4960Sstevel@tonic-gate 	 * These two fields are used for scheduling a syncq for
4970Sstevel@tonic-gate 	 * background processing. The sq_svcflag is protected by
4980Sstevel@tonic-gate 	 * SQLOCK lock.
4990Sstevel@tonic-gate 	 */
5000Sstevel@tonic-gate 	struct syncq	*sq_next;	/* for syncq scheduling */
5010Sstevel@tonic-gate 	void *		sq_servid;
5020Sstevel@tonic-gate 	uint_t		sq_servcount;	/* # pending background threads */
5030Sstevel@tonic-gate 	uint_t		sq_svcflags;	/* Scheduling flags	*/
5040Sstevel@tonic-gate 	clock_t		sq_tstamp;	/* Time when was enabled */
5050Sstevel@tonic-gate 	/*
5060Sstevel@tonic-gate 	 * Maximum priority of the queues on this syncq.
5070Sstevel@tonic-gate 	 */
5080Sstevel@tonic-gate 	pri_t		sq_pri;
5090Sstevel@tonic-gate };
5100Sstevel@tonic-gate typedef struct syncq syncq_t;
5110Sstevel@tonic-gate 
5120Sstevel@tonic-gate /*
5130Sstevel@tonic-gate  * sync queue scheduling flags (for sq_svcflags).
5140Sstevel@tonic-gate  */
5150Sstevel@tonic-gate #define	SQ_SERVICE	0x1		/* being serviced */
5160Sstevel@tonic-gate #define	SQ_BGTHREAD	0x2		/* awaiting service by bg thread */
5170Sstevel@tonic-gate #define	SQ_DISABLED	0x4		/* don't put syncq in service list */
5180Sstevel@tonic-gate 
5190Sstevel@tonic-gate /*
5200Sstevel@tonic-gate  * FASTPUT bit in sd_count/putcount.
5210Sstevel@tonic-gate  */
5220Sstevel@tonic-gate #define	SQ_FASTPUT	0x8000
5230Sstevel@tonic-gate #define	SQ_FASTMASK	0x7FFF
5240Sstevel@tonic-gate 
5250Sstevel@tonic-gate /*
5260Sstevel@tonic-gate  * sync queue state flags
5270Sstevel@tonic-gate  */
5280Sstevel@tonic-gate #define	SQ_EXCL		0x0001		/* exclusive access to inner */
5290Sstevel@tonic-gate 					/*	perimeter */
5300Sstevel@tonic-gate #define	SQ_BLOCKED	0x0002		/* qprocsoff */
5310Sstevel@tonic-gate #define	SQ_FROZEN	0x0004		/* freezestr */
5320Sstevel@tonic-gate #define	SQ_WRITER	0x0008		/* qwriter(OUTER) pending or running */
5330Sstevel@tonic-gate #define	SQ_MESSAGES	0x0010		/* messages on syncq */
5340Sstevel@tonic-gate #define	SQ_WANTWAKEUP	0x0020		/* do cv_broadcast on sq_wait */
5350Sstevel@tonic-gate #define	SQ_WANTEXWAKEUP	0x0040		/* do cv_broadcast on sq_exitwait */
5360Sstevel@tonic-gate #define	SQ_EVENTS	0x0080		/* Events pending */
5370Sstevel@tonic-gate #define	SQ_QUEUED	(SQ_MESSAGES | SQ_EVENTS)
5380Sstevel@tonic-gate #define	SQ_FLAGMASK	0x00FF
5390Sstevel@tonic-gate 
5400Sstevel@tonic-gate /*
5410Sstevel@tonic-gate  * Test a queue to see if inner perimeter is exclusive.
5420Sstevel@tonic-gate  */
5430Sstevel@tonic-gate #define	PERIM_EXCL(q)	((q)->q_syncq->sq_flags & SQ_EXCL)
5440Sstevel@tonic-gate 
5450Sstevel@tonic-gate /*
5460Sstevel@tonic-gate  * If any of these flags are set it is not possible for a thread to
5470Sstevel@tonic-gate  * enter a put or service procedure. Instead it must either block
5480Sstevel@tonic-gate  * or put the message on the syncq.
5490Sstevel@tonic-gate  */
5500Sstevel@tonic-gate #define	SQ_GOAWAY	(SQ_EXCL|SQ_BLOCKED|SQ_FROZEN|SQ_WRITER|\
5510Sstevel@tonic-gate 			SQ_QUEUED)
5520Sstevel@tonic-gate /*
5530Sstevel@tonic-gate  * If any of these flags are set it not possible to drain the syncq
5540Sstevel@tonic-gate  */
5550Sstevel@tonic-gate #define	SQ_STAYAWAY	(SQ_BLOCKED|SQ_FROZEN|SQ_WRITER)
5560Sstevel@tonic-gate 
5570Sstevel@tonic-gate /*
5580Sstevel@tonic-gate  * Flags to trigger syncq tail processing.
5590Sstevel@tonic-gate  */
5600Sstevel@tonic-gate #define	SQ_TAIL		(SQ_QUEUED|SQ_WANTWAKEUP|SQ_WANTEXWAKEUP)
5610Sstevel@tonic-gate 
5620Sstevel@tonic-gate /*
5630Sstevel@tonic-gate  * Syncq types (stored in sq_type)
5640Sstevel@tonic-gate  * The SQ_TYPES_IN_FLAGS (ciput) are also stored in sq_flags
5650Sstevel@tonic-gate  * for performance reasons. Thus these type values have to be in the low
5660Sstevel@tonic-gate  * 16 bits and not conflict with the sq_flags values above.
5670Sstevel@tonic-gate  *
5680Sstevel@tonic-gate  * Notes:
5690Sstevel@tonic-gate  *  - putnext() and put() assume that the put procedures have the highest
5700Sstevel@tonic-gate  *    degree of concurrency. Thus if any of the SQ_CI* are set then SQ_CIPUT
5710Sstevel@tonic-gate  *    has to be set. This restriction can be lifted by adding code to putnext
5720Sstevel@tonic-gate  *    and put that check that sq_count == 0 like entersq does.
5730Sstevel@tonic-gate  *  - putnext() and put() does currently not handle !SQ_COPUT
5740Sstevel@tonic-gate  *  - In order to implement !SQ_COCB outer_enter has to be fixed so that
5750Sstevel@tonic-gate  *    the callback can be cancelled while cv_waiting in outer_enter.
5760Sstevel@tonic-gate  *  - If SQ_CISVC needs to be implemented, qprocsoff() needs to wait
5770Sstevel@tonic-gate  *    for the currently running services to stop (wait for QINSERVICE
5780Sstevel@tonic-gate  *    to go off). disable_svc called from qprcosoff disables only
5790Sstevel@tonic-gate  *    services that will be run in future.
5800Sstevel@tonic-gate  *
5810Sstevel@tonic-gate  * All the SQ_CO flags are set when there is no outer perimeter.
5820Sstevel@tonic-gate  */
5830Sstevel@tonic-gate #define	SQ_CIPUT	0x0100		/* Concurrent inner put proc */
5840Sstevel@tonic-gate #define	SQ_CISVC	0x0200		/* Concurrent inner svc proc */
5850Sstevel@tonic-gate #define	SQ_CIOC		0x0400		/* Concurrent inner open/close */
5860Sstevel@tonic-gate #define	SQ_CICB		0x0800		/* Concurrent inner callback */
5870Sstevel@tonic-gate #define	SQ_COPUT	0x1000		/* Concurrent outer put proc */
5880Sstevel@tonic-gate #define	SQ_COSVC	0x2000		/* Concurrent outer svc proc */
5890Sstevel@tonic-gate #define	SQ_COOC		0x4000		/* Concurrent outer open/close */
5900Sstevel@tonic-gate #define	SQ_COCB		0x8000		/* Concurrent outer callback */
5910Sstevel@tonic-gate 
5920Sstevel@tonic-gate /* Types also kept in sq_flags for performance */
5930Sstevel@tonic-gate #define	SQ_TYPES_IN_FLAGS	(SQ_CIPUT)
5940Sstevel@tonic-gate 
5950Sstevel@tonic-gate #define	SQ_CI		(SQ_CIPUT|SQ_CISVC|SQ_CIOC|SQ_CICB)
5960Sstevel@tonic-gate #define	SQ_CO		(SQ_COPUT|SQ_COSVC|SQ_COOC|SQ_COCB)
5970Sstevel@tonic-gate #define	SQ_TYPEMASK	(SQ_CI|SQ_CO)
5980Sstevel@tonic-gate 
5990Sstevel@tonic-gate /*
6000Sstevel@tonic-gate  * Flag combinations passed to entersq and leavesq to specify the type
6010Sstevel@tonic-gate  * of entry point.
6020Sstevel@tonic-gate  */
6030Sstevel@tonic-gate #define	SQ_PUT		(SQ_CIPUT|SQ_COPUT)
6040Sstevel@tonic-gate #define	SQ_SVC		(SQ_CISVC|SQ_COSVC)
6050Sstevel@tonic-gate #define	SQ_OPENCLOSE	(SQ_CIOC|SQ_COOC)
6060Sstevel@tonic-gate #define	SQ_CALLBACK	(SQ_CICB|SQ_COCB)
6070Sstevel@tonic-gate 
6080Sstevel@tonic-gate /*
6090Sstevel@tonic-gate  * Other syncq types which are not copied into flags.
6100Sstevel@tonic-gate  */
6110Sstevel@tonic-gate #define	SQ_PERMOD	0x01		/* Syncq is PERMOD */
6120Sstevel@tonic-gate 
6130Sstevel@tonic-gate /*
6140Sstevel@tonic-gate  * Asynchronous callback qun*** flag.
6150Sstevel@tonic-gate  * The mechanism these flags are used in is one where callbacks enter
6160Sstevel@tonic-gate  * the perimeter thanks to framework support. To use this mechanism
6170Sstevel@tonic-gate  * the q* and qun* flavors of the callback routines must be used.
6180Sstevel@tonic-gate  * e.g. qtimeout and quntimeout. The synchronization provided by the flags
6190Sstevel@tonic-gate  * avoids deadlocks between blocking qun* routines and the perimeter
6200Sstevel@tonic-gate  * lock.
6210Sstevel@tonic-gate  */
6220Sstevel@tonic-gate #define	SQ_CALLB_BYPASSED	0x01		/* bypassed callback fn */
6230Sstevel@tonic-gate 
6240Sstevel@tonic-gate /*
6250Sstevel@tonic-gate  * Cancel callback mask.
6260Sstevel@tonic-gate  * The mask expands as the number of cancelable callback types grows
6270Sstevel@tonic-gate  * Note - separate callback flag because different callbacks have
6280Sstevel@tonic-gate  * overlapping id space.
6290Sstevel@tonic-gate  */
6300Sstevel@tonic-gate #define	SQ_CALLB_CANCEL_MASK	(SQ_CANCEL_TOUT|SQ_CANCEL_BUFCALL)
6310Sstevel@tonic-gate 
6320Sstevel@tonic-gate #define	SQ_CANCEL_TOUT		0x02		/* cancel timeout request */
6330Sstevel@tonic-gate #define	SQ_CANCEL_BUFCALL	0x04		/* cancel bufcall request */
6340Sstevel@tonic-gate 
6350Sstevel@tonic-gate typedef struct callbparams {
6360Sstevel@tonic-gate 	syncq_t		*cbp_sq;
6370Sstevel@tonic-gate 	void		(*cbp_func)(void *);
6380Sstevel@tonic-gate 	void		*cbp_arg;
6390Sstevel@tonic-gate 	callbparams_id_t cbp_id;
6400Sstevel@tonic-gate 	uint_t		cbp_flags;
6410Sstevel@tonic-gate 	struct callbparams *cbp_next;
6420Sstevel@tonic-gate 	size_t		cbp_size;
6430Sstevel@tonic-gate } callbparams_t;
6440Sstevel@tonic-gate 
6450Sstevel@tonic-gate typedef struct strbufcall {
6460Sstevel@tonic-gate 	void		(*bc_func)(void *);
6470Sstevel@tonic-gate 	void		*bc_arg;
6480Sstevel@tonic-gate 	size_t		bc_size;
6490Sstevel@tonic-gate 	bufcall_id_t	bc_id;
6500Sstevel@tonic-gate 	struct strbufcall *bc_next;
6510Sstevel@tonic-gate 	kthread_id_t	bc_executor;
6520Sstevel@tonic-gate } strbufcall_t;
6530Sstevel@tonic-gate 
6540Sstevel@tonic-gate /*
6550Sstevel@tonic-gate  * Structure of list of processes to be sent SIGPOLL/SIGURG signal
6560Sstevel@tonic-gate  * on request.  The valid S_* events are defined in stropts.h.
6570Sstevel@tonic-gate  */
6580Sstevel@tonic-gate typedef struct strsig {
6590Sstevel@tonic-gate 	struct pid	*ss_pidp;	/* pid/pgrp pointer */
6600Sstevel@tonic-gate 	pid_t		ss_pid;		/* positive pid, negative pgrp */
6610Sstevel@tonic-gate 	int		ss_events;	/* S_* events */
6620Sstevel@tonic-gate 	struct strsig	*ss_next;
6630Sstevel@tonic-gate } strsig_t;
6640Sstevel@tonic-gate 
6650Sstevel@tonic-gate /*
6660Sstevel@tonic-gate  * bufcall list
6670Sstevel@tonic-gate  */
6680Sstevel@tonic-gate struct bclist {
6690Sstevel@tonic-gate 	strbufcall_t	*bc_head;
6700Sstevel@tonic-gate 	strbufcall_t	*bc_tail;
6710Sstevel@tonic-gate };
6720Sstevel@tonic-gate 
6730Sstevel@tonic-gate /*
6740Sstevel@tonic-gate  * Structure used to track mux links and unlinks.
6750Sstevel@tonic-gate  */
6760Sstevel@tonic-gate struct mux_node {
6770Sstevel@tonic-gate 	major_t		 mn_imaj;	/* internal major device number */
6780Sstevel@tonic-gate 	uint16_t	 mn_indegree;	/* number of incoming edges */
6790Sstevel@tonic-gate 	struct mux_node *mn_originp;	/* where we came from during search */
6800Sstevel@tonic-gate 	struct mux_edge *mn_startp;	/* where search left off in mn_outp */
6810Sstevel@tonic-gate 	struct mux_edge *mn_outp;	/* list of outgoing edges */
6820Sstevel@tonic-gate 	uint_t		 mn_flags;	/* see below */
6830Sstevel@tonic-gate };
6840Sstevel@tonic-gate 
6850Sstevel@tonic-gate /*
6860Sstevel@tonic-gate  * Flags for mux_nodes.
6870Sstevel@tonic-gate  */
6880Sstevel@tonic-gate #define	VISITED	1
6890Sstevel@tonic-gate 
6900Sstevel@tonic-gate /*
6910Sstevel@tonic-gate  * Edge structure - a list of these is hung off the
6920Sstevel@tonic-gate  * mux_node to represent the outgoing edges.
6930Sstevel@tonic-gate  */
6940Sstevel@tonic-gate struct mux_edge {
6950Sstevel@tonic-gate 	struct mux_node	*me_nodep;	/* edge leads to this node */
6960Sstevel@tonic-gate 	struct mux_edge	*me_nextp;	/* next edge */
6970Sstevel@tonic-gate 	int		 me_muxid;	/* id of link */
6983448Sdh155122 	dev_t		 me_dev;	/* dev_t - used for kernel PUNLINK */
6990Sstevel@tonic-gate };
7000Sstevel@tonic-gate 
7010Sstevel@tonic-gate /*
7020Sstevel@tonic-gate  * Queue info
7030Sstevel@tonic-gate  *
7040Sstevel@tonic-gate  * The syncq is included here to reduce memory fragmentation
7050Sstevel@tonic-gate  * for kernel memory allocators that only allocate in sizes that are
7060Sstevel@tonic-gate  * powers of two. If the kernel memory allocator changes this should
7070Sstevel@tonic-gate  * be revisited.
7080Sstevel@tonic-gate  */
7090Sstevel@tonic-gate typedef struct queinfo {
7100Sstevel@tonic-gate 	struct queue	qu_rqueue;	/* read queue - must be first */
7110Sstevel@tonic-gate 	struct queue	qu_wqueue;	/* write queue - must be second */
7120Sstevel@tonic-gate 	struct syncq	qu_syncq;	/* syncq - must be third */
7130Sstevel@tonic-gate } queinfo_t;
7140Sstevel@tonic-gate 
7150Sstevel@tonic-gate /*
7160Sstevel@tonic-gate  * Multiplexed streams info
7170Sstevel@tonic-gate  */
7180Sstevel@tonic-gate typedef struct linkinfo {
7190Sstevel@tonic-gate 	struct linkblk	li_lblk;	/* must be first */
7200Sstevel@tonic-gate 	struct file	*li_fpdown;	/* file pointer for lower stream */
7210Sstevel@tonic-gate 	struct linkinfo	*li_next;	/* next in list */
7220Sstevel@tonic-gate 	struct linkinfo *li_prev;	/* previous in list */
7230Sstevel@tonic-gate } linkinfo_t;
7240Sstevel@tonic-gate 
7250Sstevel@tonic-gate /*
7260Sstevel@tonic-gate  * List of syncq's used by freeezestr/unfreezestr
7270Sstevel@tonic-gate  */
7280Sstevel@tonic-gate typedef struct syncql {
7290Sstevel@tonic-gate 	struct syncql	*sql_next;
7300Sstevel@tonic-gate 	syncq_t		*sql_sq;
7310Sstevel@tonic-gate } syncql_t;
7320Sstevel@tonic-gate 
7330Sstevel@tonic-gate typedef struct sqlist {
7340Sstevel@tonic-gate 	syncql_t	*sqlist_head;
7350Sstevel@tonic-gate 	size_t		sqlist_size;		/* structure size in bytes */
7360Sstevel@tonic-gate 	size_t		sqlist_index;		/* next free entry in array */
7370Sstevel@tonic-gate 	syncql_t	sqlist_array[4];	/* 4 or more entries */
7380Sstevel@tonic-gate } sqlist_t;
7390Sstevel@tonic-gate 
7400Sstevel@tonic-gate typedef struct perdm {
7410Sstevel@tonic-gate 	struct perdm		*dm_next;
7420Sstevel@tonic-gate 	syncq_t			*dm_sq;
7430Sstevel@tonic-gate 	struct streamtab	*dm_str;
7440Sstevel@tonic-gate 	uint_t			dm_ref;
7450Sstevel@tonic-gate } perdm_t;
7460Sstevel@tonic-gate 
7470Sstevel@tonic-gate #define	NEED_DM(dmp, qflag) \
7480Sstevel@tonic-gate 	(dmp == NULL && (qflag & (QPERMOD | QMTOUTPERIM)))
7490Sstevel@tonic-gate 
7500Sstevel@tonic-gate /*
7510Sstevel@tonic-gate  * fmodsw_impl_t is used within the kernel. fmodsw is used by
7520Sstevel@tonic-gate  * the modules/drivers. The information is copied from fmodsw
7530Sstevel@tonic-gate  * defined in the module/driver into the fmodsw_impl_t structure
7540Sstevel@tonic-gate  * during the module/driver initialization.
7550Sstevel@tonic-gate  */
7560Sstevel@tonic-gate typedef struct fmodsw_impl	fmodsw_impl_t;
7570Sstevel@tonic-gate 
7580Sstevel@tonic-gate struct fmodsw_impl {
7590Sstevel@tonic-gate 	fmodsw_impl_t		*f_next;
7600Sstevel@tonic-gate 	char			f_name[FMNAMESZ + 1];
7610Sstevel@tonic-gate 	struct streamtab	*f_str;
7620Sstevel@tonic-gate 	uint32_t		f_qflag;
7630Sstevel@tonic-gate 	uint32_t		f_sqtype;
7640Sstevel@tonic-gate 	perdm_t			*f_dmp;
7650Sstevel@tonic-gate 	uint32_t		f_ref;
7660Sstevel@tonic-gate 	uint32_t		f_hits;
7670Sstevel@tonic-gate };
7680Sstevel@tonic-gate 
7690Sstevel@tonic-gate typedef enum {
7700Sstevel@tonic-gate 	FMODSW_HOLD =	0x00000001,
7710Sstevel@tonic-gate 	FMODSW_LOAD =	0x00000002
7720Sstevel@tonic-gate } fmodsw_flags_t;
7730Sstevel@tonic-gate 
7740Sstevel@tonic-gate typedef struct cdevsw_impl {
7750Sstevel@tonic-gate 	struct streamtab	*d_str;
7760Sstevel@tonic-gate 	uint32_t		d_qflag;
7770Sstevel@tonic-gate 	uint32_t		d_sqtype;
7780Sstevel@tonic-gate 	perdm_t			*d_dmp;
7790Sstevel@tonic-gate } cdevsw_impl_t;
7800Sstevel@tonic-gate 
7810Sstevel@tonic-gate /*
782560Smeem  * Enumeration of the types of access that can be requested for a
783560Smeem  * controlling terminal under job control.
784560Smeem  */
785560Smeem enum jcaccess {
786560Smeem 	JCREAD,			/* read data on a ctty */
787560Smeem 	JCWRITE,		/* write data to a ctty */
788560Smeem 	JCSETP,			/* set ctty parameters */
789560Smeem 	JCGETP			/* get ctty parameters */
790560Smeem };
791560Smeem 
7923448Sdh155122 struct str_stack {
7933448Sdh155122 	netstack_t	*ss_netstack;	/* Common netstack */
7943448Sdh155122 
7953448Sdh155122 	kmutex_t	ss_sad_lock;	/* autopush lock */
7963448Sdh155122 	mod_hash_t	*ss_sad_hash;
7973448Sdh155122 	size_t		ss_sad_hash_nchains;
7983448Sdh155122 	struct saddev	*ss_saddev;	/* sad device array */
7993448Sdh155122 	int		ss_sadcnt;	/* number of sad devices */
8003448Sdh155122 
8013448Sdh155122 	int		ss_devcnt;	/* number of mux_nodes */
8023448Sdh155122 	struct mux_node	*ss_mux_nodes;	/* mux info for cycle checking */
8033448Sdh155122 };
8043448Sdh155122 typedef struct str_stack str_stack_t;
8053448Sdh155122 
806560Smeem /*
8070Sstevel@tonic-gate  * Finding related queues
8080Sstevel@tonic-gate  */
8090Sstevel@tonic-gate #define	STREAM(q)	((q)->q_stream)
8100Sstevel@tonic-gate #define	SQ(rq)		((syncq_t *)((rq) + 2))
8110Sstevel@tonic-gate 
8120Sstevel@tonic-gate /*
8130Sstevel@tonic-gate  * Locking macros
8140Sstevel@tonic-gate  */
8150Sstevel@tonic-gate #define	QLOCK(q)	(&(q)->q_lock)
8160Sstevel@tonic-gate #define	SQLOCK(sq)	(&(sq)->sq_lock)
8170Sstevel@tonic-gate 
8180Sstevel@tonic-gate #define	STREAM_PUTLOCKS_ENTER(stp) {					       \
8190Sstevel@tonic-gate 		ASSERT(MUTEX_HELD(&(stp)->sd_lock));			       \
8200Sstevel@tonic-gate 		if ((stp)->sd_ciputctrl != NULL) {			       \
8210Sstevel@tonic-gate 			int i;						       \
8220Sstevel@tonic-gate 			int nlocks = (stp)->sd_nciputctrl;		       \
8230Sstevel@tonic-gate 			ciputctrl_t *cip = (stp)->sd_ciputctrl;		       \
8240Sstevel@tonic-gate 			for (i = 0; i <= nlocks; i++) {			       \
8250Sstevel@tonic-gate 				mutex_enter(&cip[i].ciputctrl_lock);	       \
8260Sstevel@tonic-gate 			}						       \
8270Sstevel@tonic-gate 		}							       \
8280Sstevel@tonic-gate 	}
8290Sstevel@tonic-gate 
8300Sstevel@tonic-gate #define	STREAM_PUTLOCKS_EXIT(stp) {					       \
8310Sstevel@tonic-gate 		ASSERT(MUTEX_HELD(&(stp)->sd_lock));			       \
8320Sstevel@tonic-gate 		if ((stp)->sd_ciputctrl != NULL) {			       \
8330Sstevel@tonic-gate 			int i;						       \
8340Sstevel@tonic-gate 			int nlocks = (stp)->sd_nciputctrl;		       \
8350Sstevel@tonic-gate 			ciputctrl_t *cip = (stp)->sd_ciputctrl;		       \
8360Sstevel@tonic-gate 			for (i = 0; i <= nlocks; i++) {			       \
8370Sstevel@tonic-gate 				mutex_exit(&cip[i].ciputctrl_lock);	       \
8380Sstevel@tonic-gate 			}						       \
8390Sstevel@tonic-gate 		}							       \
8400Sstevel@tonic-gate 	}
8410Sstevel@tonic-gate 
8420Sstevel@tonic-gate #define	SQ_PUTLOCKS_ENTER(sq) {						       \
8430Sstevel@tonic-gate 		ASSERT(MUTEX_HELD(SQLOCK(sq)));				       \
8440Sstevel@tonic-gate 		if ((sq)->sq_ciputctrl != NULL) {			       \
8450Sstevel@tonic-gate 			int i;						       \
8460Sstevel@tonic-gate 			int nlocks = (sq)->sq_nciputctrl;		       \
8470Sstevel@tonic-gate 			ciputctrl_t *cip = (sq)->sq_ciputctrl;		       \
8480Sstevel@tonic-gate 			ASSERT((sq)->sq_type & SQ_CIPUT);		       \
8490Sstevel@tonic-gate 			for (i = 0; i <= nlocks; i++) {			       \
8500Sstevel@tonic-gate 				mutex_enter(&cip[i].ciputctrl_lock);	       \
8510Sstevel@tonic-gate 			}						       \
8520Sstevel@tonic-gate 		}							       \
8530Sstevel@tonic-gate 	}
8540Sstevel@tonic-gate 
8550Sstevel@tonic-gate #define	SQ_PUTLOCKS_EXIT(sq) {						       \
8560Sstevel@tonic-gate 		ASSERT(MUTEX_HELD(SQLOCK(sq)));				       \
8570Sstevel@tonic-gate 		if ((sq)->sq_ciputctrl != NULL) {			       \
8580Sstevel@tonic-gate 			int i;						       \
8590Sstevel@tonic-gate 			int nlocks = (sq)->sq_nciputctrl;		       \
8600Sstevel@tonic-gate 			ciputctrl_t *cip = (sq)->sq_ciputctrl;		       \
8610Sstevel@tonic-gate 			ASSERT((sq)->sq_type & SQ_CIPUT);		       \
8620Sstevel@tonic-gate 			for (i = 0; i <= nlocks; i++) {			       \
8630Sstevel@tonic-gate 				mutex_exit(&cip[i].ciputctrl_lock);	       \
8640Sstevel@tonic-gate 			}						       \
8650Sstevel@tonic-gate 		}							       \
8660Sstevel@tonic-gate 	}
8670Sstevel@tonic-gate 
8680Sstevel@tonic-gate #define	SQ_PUTCOUNT_SETFAST(sq) {					\
8690Sstevel@tonic-gate 		ASSERT(MUTEX_HELD(SQLOCK(sq)));				\
8700Sstevel@tonic-gate 		if ((sq)->sq_ciputctrl != NULL) {			\
8710Sstevel@tonic-gate 			int i;						\
8720Sstevel@tonic-gate 			int nlocks = (sq)->sq_nciputctrl;		\
8730Sstevel@tonic-gate 			ciputctrl_t *cip = (sq)->sq_ciputctrl;		\
8740Sstevel@tonic-gate 			ASSERT((sq)->sq_type & SQ_CIPUT);		\
8750Sstevel@tonic-gate 			for (i = 0; i <= nlocks; i++) {			\
8760Sstevel@tonic-gate 				mutex_enter(&cip[i].ciputctrl_lock);	\
8770Sstevel@tonic-gate 				cip[i].ciputctrl_count |= SQ_FASTPUT;	\
8780Sstevel@tonic-gate 				mutex_exit(&cip[i].ciputctrl_lock);	\
8790Sstevel@tonic-gate 			}						\
8800Sstevel@tonic-gate 		}							\
8810Sstevel@tonic-gate 	}
8820Sstevel@tonic-gate 
8830Sstevel@tonic-gate #define	SQ_PUTCOUNT_CLRFAST(sq) {					\
8840Sstevel@tonic-gate 		ASSERT(MUTEX_HELD(SQLOCK(sq)));				\
8850Sstevel@tonic-gate 		if ((sq)->sq_ciputctrl != NULL) {			\
8860Sstevel@tonic-gate 			int i;						\
8870Sstevel@tonic-gate 			int nlocks = (sq)->sq_nciputctrl;		\
8880Sstevel@tonic-gate 			ciputctrl_t *cip = (sq)->sq_ciputctrl;		\
8890Sstevel@tonic-gate 			ASSERT((sq)->sq_type & SQ_CIPUT);		\
8900Sstevel@tonic-gate 			for (i = 0; i <= nlocks; i++) {			\
8910Sstevel@tonic-gate 				mutex_enter(&cip[i].ciputctrl_lock);	\
8920Sstevel@tonic-gate 				cip[i].ciputctrl_count &= ~SQ_FASTPUT;	\
8930Sstevel@tonic-gate 				mutex_exit(&cip[i].ciputctrl_lock);	\
8940Sstevel@tonic-gate 			}						\
8950Sstevel@tonic-gate 		}							\
8960Sstevel@tonic-gate 	}
8970Sstevel@tonic-gate 
8980Sstevel@tonic-gate 
8990Sstevel@tonic-gate #ifdef	DEBUG
9000Sstevel@tonic-gate 
9010Sstevel@tonic-gate #define	SQ_PUTLOCKS_HELD(sq) {						       \
9020Sstevel@tonic-gate 		ASSERT(MUTEX_HELD(SQLOCK(sq)));				       \
9030Sstevel@tonic-gate 		if ((sq)->sq_ciputctrl != NULL) {			       \
9040Sstevel@tonic-gate 			int i;						       \
9050Sstevel@tonic-gate 			int nlocks = (sq)->sq_nciputctrl;		       \
9060Sstevel@tonic-gate 			ciputctrl_t *cip = (sq)->sq_ciputctrl;		       \
9070Sstevel@tonic-gate 			ASSERT((sq)->sq_type & SQ_CIPUT);		       \
9080Sstevel@tonic-gate 			for (i = 0; i <= nlocks; i++) {			       \
9090Sstevel@tonic-gate 				ASSERT(MUTEX_HELD(&cip[i].ciputctrl_lock));    \
9100Sstevel@tonic-gate 			}						       \
9110Sstevel@tonic-gate 		}							       \
9120Sstevel@tonic-gate 	}
9130Sstevel@tonic-gate 
9140Sstevel@tonic-gate #define	SUMCHECK_SQ_PUTCOUNTS(sq, countcheck) {				       \
9150Sstevel@tonic-gate 		if ((sq)->sq_ciputctrl != NULL) {			       \
9160Sstevel@tonic-gate 			int i;						       \
9170Sstevel@tonic-gate 			uint_t count = 0;				       \
9180Sstevel@tonic-gate 			int ncounts = (sq)->sq_nciputctrl;		       \
9190Sstevel@tonic-gate 			ASSERT((sq)->sq_type & SQ_CIPUT);		       \
9200Sstevel@tonic-gate 			for (i = 0; i <= ncounts; i++) {		       \
9210Sstevel@tonic-gate 				count +=				       \
9220Sstevel@tonic-gate 				    (((sq)->sq_ciputctrl[i].ciputctrl_count) & \
9230Sstevel@tonic-gate 				    SQ_FASTMASK);			       \
9240Sstevel@tonic-gate 			}						       \
9250Sstevel@tonic-gate 			ASSERT(count == (countcheck));			       \
9260Sstevel@tonic-gate 		}							       \
9270Sstevel@tonic-gate 	}
9280Sstevel@tonic-gate 
9290Sstevel@tonic-gate #define	SUMCHECK_CIPUTCTRL_COUNTS(ciput, nciput, countcheck) {		       \
9300Sstevel@tonic-gate 		int i;							       \
9310Sstevel@tonic-gate 		uint_t count = 0;					       \
9320Sstevel@tonic-gate 		ASSERT((ciput) != NULL);				       \
9330Sstevel@tonic-gate 		for (i = 0; i <= (nciput); i++) {			       \
9340Sstevel@tonic-gate 			count += (((ciput)[i].ciputctrl_count) &	       \
9350Sstevel@tonic-gate 			    SQ_FASTMASK);				       \
9360Sstevel@tonic-gate 		}							       \
9370Sstevel@tonic-gate 		ASSERT(count == (countcheck));				       \
9380Sstevel@tonic-gate 	}
9390Sstevel@tonic-gate 
9400Sstevel@tonic-gate #else	/* DEBUG */
9410Sstevel@tonic-gate 
9420Sstevel@tonic-gate #define	SQ_PUTLOCKS_HELD(sq)
9430Sstevel@tonic-gate #define	SUMCHECK_SQ_PUTCOUNTS(sq, countcheck)
9440Sstevel@tonic-gate #define	SUMCHECK_CIPUTCTRL_COUNTS(sq, nciput, countcheck)
9450Sstevel@tonic-gate 
9460Sstevel@tonic-gate #endif	/* DEBUG */
9470Sstevel@tonic-gate 
9480Sstevel@tonic-gate #define	SUM_SQ_PUTCOUNTS(sq, count) {					       \
9490Sstevel@tonic-gate 		if ((sq)->sq_ciputctrl != NULL) {			       \
9500Sstevel@tonic-gate 			int i;						       \
9510Sstevel@tonic-gate 			int ncounts = (sq)->sq_nciputctrl;		       \
9520Sstevel@tonic-gate 			ciputctrl_t *cip = (sq)->sq_ciputctrl;		       \
9530Sstevel@tonic-gate 			ASSERT((sq)->sq_type & SQ_CIPUT);		       \
9540Sstevel@tonic-gate 			for (i = 0; i <= ncounts; i++) {		       \
9550Sstevel@tonic-gate 				(count) += ((cip[i].ciputctrl_count) &	       \
9560Sstevel@tonic-gate 				    SQ_FASTMASK);			       \
9570Sstevel@tonic-gate 			}						       \
9580Sstevel@tonic-gate 		}							       \
9590Sstevel@tonic-gate 	}
9600Sstevel@tonic-gate 
9610Sstevel@tonic-gate #define	CLAIM_QNEXT_LOCK(stp)	mutex_enter(&(stp)->sd_lock)
9620Sstevel@tonic-gate #define	RELEASE_QNEXT_LOCK(stp)	mutex_exit(&(stp)->sd_lock)
9630Sstevel@tonic-gate 
9640Sstevel@tonic-gate /*
9650Sstevel@tonic-gate  * syncq message manipulation macros.
9660Sstevel@tonic-gate  */
9670Sstevel@tonic-gate /*
9680Sstevel@tonic-gate  * Put a message on the queue syncq.
9690Sstevel@tonic-gate  * Assumes QLOCK held.
9700Sstevel@tonic-gate  */
9710Sstevel@tonic-gate #define	SQPUT_MP(qp, mp)						\
9720Sstevel@tonic-gate 	{								\
9730Sstevel@tonic-gate 		qp->q_syncqmsgs++;					\
9740Sstevel@tonic-gate 		if (qp->q_sqhead == NULL) {				\
9750Sstevel@tonic-gate 			qp->q_sqhead = qp->q_sqtail = mp;		\
9760Sstevel@tonic-gate 		} else {						\
9770Sstevel@tonic-gate 			qp->q_sqtail->b_next = mp;			\
9780Sstevel@tonic-gate 			qp->q_sqtail = mp;				\
9790Sstevel@tonic-gate 		}							\
9806380Sjk115741 		set_qfull(qp);						\
9810Sstevel@tonic-gate 	}
9820Sstevel@tonic-gate 
9830Sstevel@tonic-gate /*
9840Sstevel@tonic-gate  * Miscellaneous parameters and flags.
9850Sstevel@tonic-gate  */
9860Sstevel@tonic-gate 
9870Sstevel@tonic-gate /*
9880Sstevel@tonic-gate  * Default timeout in milliseconds for ioctls and close
9890Sstevel@tonic-gate  */
9900Sstevel@tonic-gate #define	STRTIMOUT 15000
9910Sstevel@tonic-gate 
9920Sstevel@tonic-gate /*
9930Sstevel@tonic-gate  * Flag values for stream io
9940Sstevel@tonic-gate  */
9950Sstevel@tonic-gate #define	WRITEWAIT	0x1	/* waiting for write event */
9960Sstevel@tonic-gate #define	READWAIT	0x2	/* waiting for read event */
9970Sstevel@tonic-gate #define	NOINTR		0x4	/* error is not to be set for signal */
9980Sstevel@tonic-gate #define	GETWAIT		0x8	/* waiting for getmsg event */
9990Sstevel@tonic-gate 
10000Sstevel@tonic-gate /*
10010Sstevel@tonic-gate  * These flags need to be unique for stream io name space
10020Sstevel@tonic-gate  * and copy modes name space.  These flags allow strwaitq
10030Sstevel@tonic-gate  * and strdoioctl to proceed as if signals or errors on the stream
10040Sstevel@tonic-gate  * head have not occurred; i.e. they will be detected by some other
10050Sstevel@tonic-gate  * means.
10060Sstevel@tonic-gate  * STR_NOSIG does not allow signals to interrupt the call
10070Sstevel@tonic-gate  * STR_NOERROR does not allow stream head read, write or hup errors to
10080Sstevel@tonic-gate  * affect the call.  When used with strdoioctl(), if a previous ioctl
10090Sstevel@tonic-gate  * is pending and times out, STR_NOERROR will cause strdoioctl() to not
10100Sstevel@tonic-gate  * return ETIME. If, however, the requested ioctl times out, ETIME
10110Sstevel@tonic-gate  * will be returned (use ic_timout instead)
10120Sstevel@tonic-gate  * STR_PEEK is used to inform strwaitq that the reader is peeking at data
10130Sstevel@tonic-gate  * and that a non-persistent error should not be cleared.
10140Sstevel@tonic-gate  * STR_DELAYERR is used to inform strwaitq that it should not check errors
10150Sstevel@tonic-gate  * after being awoken since, in addition to an error, there might also be
10160Sstevel@tonic-gate  * data queued on the stream head read queue.
10170Sstevel@tonic-gate  */
10180Sstevel@tonic-gate #define	STR_NOSIG	0x10	/* Ignore signals during strdoioctl/strwaitq */
10190Sstevel@tonic-gate #define	STR_NOERROR	0x20	/* Ignore errors during strdoioctl/strwaitq */
10200Sstevel@tonic-gate #define	STR_PEEK	0x40	/* Peeking behavior on non-persistent errors */
10210Sstevel@tonic-gate #define	STR_DELAYERR	0x80	/* Do not check errors on return */
10220Sstevel@tonic-gate 
10230Sstevel@tonic-gate /*
10240Sstevel@tonic-gate  * Copy modes for tty and I_STR ioctls
10250Sstevel@tonic-gate  */
10260Sstevel@tonic-gate #define	U_TO_K 	01			/* User to Kernel */
10270Sstevel@tonic-gate #define	K_TO_K  02			/* Kernel to Kernel */
10280Sstevel@tonic-gate 
10290Sstevel@tonic-gate /*
10300Sstevel@tonic-gate  * Mux defines.
10310Sstevel@tonic-gate  */
10320Sstevel@tonic-gate #define	LINKNORMAL	0x01		/* normal mux link */
10330Sstevel@tonic-gate #define	LINKPERSIST	0x02		/* persistent mux link */
10340Sstevel@tonic-gate #define	LINKTYPEMASK	0x03		/* bitmask of all link types */
10350Sstevel@tonic-gate #define	LINKCLOSE	0x04		/* unlink from strclose */
10360Sstevel@tonic-gate 
10370Sstevel@tonic-gate /*
10380Sstevel@tonic-gate  * Definitions of Streams macros and function interfaces.
10390Sstevel@tonic-gate  */
10400Sstevel@tonic-gate 
10410Sstevel@tonic-gate /*
10420Sstevel@tonic-gate  * Obsolete queue scheduling macros. They are not used anymore, but still kept
10430Sstevel@tonic-gate  * here for 3-d party modules and drivers who might still use them.
10440Sstevel@tonic-gate  */
10450Sstevel@tonic-gate #define	setqsched()
10460Sstevel@tonic-gate #define	qready()	1
10470Sstevel@tonic-gate 
10480Sstevel@tonic-gate #ifdef _KERNEL
10490Sstevel@tonic-gate #define	runqueues()
10500Sstevel@tonic-gate #define	queuerun()
10510Sstevel@tonic-gate #endif
10520Sstevel@tonic-gate 
10530Sstevel@tonic-gate /* compatibility module for style 2 drivers with DR race condition */
10540Sstevel@tonic-gate #define	DRMODNAME	"drcompat"
10550Sstevel@tonic-gate 
10560Sstevel@tonic-gate /*
10570Sstevel@tonic-gate  * Macros dealing with mux_nodes.
10580Sstevel@tonic-gate  */
10590Sstevel@tonic-gate #define	MUX_VISIT(X)	((X)->mn_flags |= VISITED)
10600Sstevel@tonic-gate #define	MUX_CLEAR(X)	((X)->mn_flags &= (~VISITED)); \
10610Sstevel@tonic-gate 			((X)->mn_originp = NULL)
10620Sstevel@tonic-gate #define	MUX_DIDVISIT(X)	((X)->mn_flags & VISITED)
10630Sstevel@tonic-gate 
10640Sstevel@tonic-gate 
10650Sstevel@tonic-gate /*
10660Sstevel@tonic-gate  * Twisted stream macros
10670Sstevel@tonic-gate  */
10680Sstevel@tonic-gate #define	STRMATED(X)	((X)->sd_flag & STRMATE)
10690Sstevel@tonic-gate #define	STRLOCKMATES(X)	if (&((X)->sd_lock) > &(((X)->sd_mate)->sd_lock)) { \
10700Sstevel@tonic-gate 				mutex_enter(&((X)->sd_lock)); \
10710Sstevel@tonic-gate 				mutex_enter(&(((X)->sd_mate)->sd_lock));  \
10720Sstevel@tonic-gate 			} else {  \
10730Sstevel@tonic-gate 				mutex_enter(&(((X)->sd_mate)->sd_lock)); \
10740Sstevel@tonic-gate 				mutex_enter(&((X)->sd_lock)); \
10750Sstevel@tonic-gate 			}
10760Sstevel@tonic-gate #define	STRUNLOCKMATES(X)	mutex_exit(&((X)->sd_lock)); \
10770Sstevel@tonic-gate 			mutex_exit(&(((X)->sd_mate)->sd_lock))
10780Sstevel@tonic-gate 
10790Sstevel@tonic-gate #ifdef _KERNEL
10800Sstevel@tonic-gate 
10810Sstevel@tonic-gate extern void strinit(void);
10820Sstevel@tonic-gate extern int strdoioctl(struct stdata *, struct strioctl *, int, int,
10830Sstevel@tonic-gate     cred_t *, int *);
10840Sstevel@tonic-gate extern void strsendsig(struct strsig *, int, uchar_t, int);
10850Sstevel@tonic-gate extern void str_sendsig(vnode_t *, int, uchar_t, int);
10860Sstevel@tonic-gate extern void strhup(struct stdata *);
10870Sstevel@tonic-gate extern int qattach(queue_t *, dev_t *, int, cred_t *, fmodsw_impl_t *,
10880Sstevel@tonic-gate     boolean_t);
10890Sstevel@tonic-gate extern int qreopen(queue_t *, dev_t *, int, cred_t *);
10900Sstevel@tonic-gate extern void qdetach(queue_t *, int, int, cred_t *, boolean_t);
10910Sstevel@tonic-gate extern void enterq(queue_t *);
10920Sstevel@tonic-gate extern void leaveq(queue_t *);
10930Sstevel@tonic-gate extern int putiocd(mblk_t *, caddr_t, int, cred_t *);
10940Sstevel@tonic-gate extern int getiocd(mblk_t *, caddr_t, int);
10950Sstevel@tonic-gate extern struct linkinfo *alloclink(queue_t *, queue_t *, struct file *);
10960Sstevel@tonic-gate extern void lbfree(struct linkinfo *);
10973448Sdh155122 extern int linkcycle(stdata_t *, stdata_t *, str_stack_t *);
10983448Sdh155122 extern struct linkinfo *findlinks(stdata_t *, int, int, str_stack_t *);
10990Sstevel@tonic-gate extern queue_t *getendq(queue_t *);
11000Sstevel@tonic-gate extern int mlink(vnode_t *, int, int, cred_t *, int *, int);
11010Sstevel@tonic-gate extern int mlink_file(vnode_t *, int, struct file *, cred_t *, int *, int);
11023448Sdh155122 extern int munlink(struct stdata *, struct linkinfo *, int, cred_t *, int *,
11033448Sdh155122     str_stack_t *);
11043448Sdh155122 extern int munlinkall(struct stdata *, int, cred_t *, int *, str_stack_t *);
11053448Sdh155122 extern void mux_addedge(stdata_t *, stdata_t *, int, str_stack_t *);
11063448Sdh155122 extern void mux_rmvedge(stdata_t *, int, str_stack_t *);
11070Sstevel@tonic-gate extern int devflg_to_qflag(struct streamtab *, uint32_t, uint32_t *,
11080Sstevel@tonic-gate     uint32_t *);
11090Sstevel@tonic-gate extern void setq(queue_t *, struct qinit *, struct qinit *, perdm_t *,
11100Sstevel@tonic-gate     uint32_t, uint32_t, boolean_t);
11110Sstevel@tonic-gate extern perdm_t *hold_dm(struct streamtab *, uint32_t, uint32_t);
11120Sstevel@tonic-gate extern void rele_dm(perdm_t *);
11130Sstevel@tonic-gate extern int strmakectl(struct strbuf *, int32_t, int32_t, mblk_t **);
11140Sstevel@tonic-gate extern int strmakedata(ssize_t *, struct uio *, stdata_t *, int32_t, mblk_t **);
11150Sstevel@tonic-gate extern int strmakemsg(struct strbuf *, ssize_t *, struct uio *,
11160Sstevel@tonic-gate     struct stdata *, int32_t, mblk_t **);
11170Sstevel@tonic-gate extern int strgetmsg(vnode_t *, struct strbuf *, struct strbuf *, uchar_t *,
11180Sstevel@tonic-gate     int *, int, rval_t *);
11190Sstevel@tonic-gate extern int strputmsg(vnode_t *, struct strbuf *, struct strbuf *, uchar_t,
11200Sstevel@tonic-gate     int flag, int fmode);
11210Sstevel@tonic-gate extern int strstartplumb(struct stdata *, int, int);
11220Sstevel@tonic-gate extern void strendplumb(struct stdata *);
11230Sstevel@tonic-gate extern int stropen(struct vnode *, dev_t *, int, cred_t *);
11240Sstevel@tonic-gate extern int strclose(struct vnode *, int, cred_t *);
11250Sstevel@tonic-gate extern int strpoll(register struct stdata *, short, int, short *,
11260Sstevel@tonic-gate     struct pollhead **);
11270Sstevel@tonic-gate extern void strclean(struct vnode *);
11280Sstevel@tonic-gate extern void str_cn_clean();	/* XXX hook for consoles signal cleanup */
11290Sstevel@tonic-gate extern int strwrite(struct vnode *, struct uio *, cred_t *);
1130741Smasputra extern int strwrite_common(struct vnode *, struct uio *, cred_t *, int);
1131741Smasputra extern int kstrwritemp(struct vnode *, mblk_t *, ushort_t);
11320Sstevel@tonic-gate extern int strread(struct vnode *, struct uio *, cred_t *);
11330Sstevel@tonic-gate extern int strioctl(struct vnode *, int, intptr_t, int, int, cred_t *, int *);
11340Sstevel@tonic-gate extern int strrput(queue_t *, mblk_t *);
11350Sstevel@tonic-gate extern int strrput_nondata(queue_t *, mblk_t *);
11360Sstevel@tonic-gate extern mblk_t *strrput_proto(vnode_t *, mblk_t *,
11370Sstevel@tonic-gate     strwakeup_t *, strsigset_t *, strsigset_t *, strpollset_t *);
11380Sstevel@tonic-gate extern mblk_t *strrput_misc(vnode_t *, mblk_t *,
11390Sstevel@tonic-gate     strwakeup_t *, strsigset_t *, strsigset_t *, strpollset_t *);
11400Sstevel@tonic-gate extern int getiocseqno(void);
11410Sstevel@tonic-gate extern int strwaitbuf(size_t, int);
11420Sstevel@tonic-gate extern int strwaitq(stdata_t *, int, ssize_t, int, clock_t, int *);
11430Sstevel@tonic-gate extern struct stdata *shalloc(queue_t *);
11440Sstevel@tonic-gate extern void shfree(struct stdata *s);
11450Sstevel@tonic-gate extern queue_t *allocq(void);
11460Sstevel@tonic-gate extern void freeq(queue_t *);
11470Sstevel@tonic-gate extern qband_t *allocband(void);
11480Sstevel@tonic-gate extern void freeband(qband_t *);
11490Sstevel@tonic-gate extern void freebs_enqueue(mblk_t *, dblk_t *);
11500Sstevel@tonic-gate extern void setqback(queue_t *, unsigned char);
11510Sstevel@tonic-gate extern int strcopyin(void *, void *, size_t, int);
11520Sstevel@tonic-gate extern int strcopyout(void *, void *, size_t, int);
11530Sstevel@tonic-gate extern void strsignal(struct stdata *, int, int32_t);
11540Sstevel@tonic-gate extern clock_t str_cv_wait(kcondvar_t *, kmutex_t *, clock_t, int);
11550Sstevel@tonic-gate extern void disable_svc(queue_t *);
11560Sstevel@tonic-gate extern void remove_runlist(queue_t *);
11570Sstevel@tonic-gate extern void wait_svc(queue_t *);
1158235Smicheng extern void backenable(queue_t *, uchar_t);
11590Sstevel@tonic-gate extern void set_qend(queue_t *);
11600Sstevel@tonic-gate extern int strgeterr(stdata_t *, int32_t, int);
11610Sstevel@tonic-gate extern void qenable_locked(queue_t *);
1162*6769Sja97890 extern mblk_t *getq_noenab(queue_t *, ssize_t);
11630Sstevel@tonic-gate extern void rmvq_noenab(queue_t *, mblk_t *);
1164235Smicheng extern void qbackenable(queue_t *, uchar_t);
11656380Sjk115741 extern void set_qfull(queue_t *);
11660Sstevel@tonic-gate 
11670Sstevel@tonic-gate extern void strblock(queue_t *);
11680Sstevel@tonic-gate extern void strunblock(queue_t *);
11690Sstevel@tonic-gate extern int qclaimed(queue_t *);
11700Sstevel@tonic-gate extern int straccess(struct stdata *, enum jcaccess);
11710Sstevel@tonic-gate 
11720Sstevel@tonic-gate extern void entersq(syncq_t *, int);
11730Sstevel@tonic-gate extern void leavesq(syncq_t *, int);
11740Sstevel@tonic-gate extern void claimq(queue_t *);
11750Sstevel@tonic-gate extern void releaseq(queue_t *);
11760Sstevel@tonic-gate extern void claimstr(queue_t *);
11770Sstevel@tonic-gate extern void releasestr(queue_t *);
11780Sstevel@tonic-gate extern void removeq(queue_t *);
11790Sstevel@tonic-gate extern void insertq(struct stdata *, queue_t *);
11800Sstevel@tonic-gate extern void drain_syncq(syncq_t *);
11810Sstevel@tonic-gate extern void qfill_syncq(syncq_t *, queue_t *, mblk_t *);
11820Sstevel@tonic-gate extern void qdrain_syncq(syncq_t *, queue_t *);
11830Sstevel@tonic-gate extern int flush_syncq(syncq_t *, queue_t *);
11840Sstevel@tonic-gate extern void wait_sq_svc(syncq_t *);
11850Sstevel@tonic-gate 
11860Sstevel@tonic-gate extern void outer_enter(syncq_t *, uint16_t);
11870Sstevel@tonic-gate extern void outer_exit(syncq_t *);
11880Sstevel@tonic-gate extern void qwriter_inner(queue_t *, mblk_t *, void (*)());
11890Sstevel@tonic-gate extern void qwriter_outer(queue_t *, mblk_t *, void (*)());
11900Sstevel@tonic-gate 
11910Sstevel@tonic-gate extern callbparams_t *callbparams_alloc(syncq_t *, void (*)(void *),
11920Sstevel@tonic-gate     void *, int);
11930Sstevel@tonic-gate extern void callbparams_free(syncq_t *, callbparams_t *);
11940Sstevel@tonic-gate extern void callbparams_free_id(syncq_t *, callbparams_id_t, int32_t);
11950Sstevel@tonic-gate extern void qcallbwrapper(void *);
11960Sstevel@tonic-gate 
1197455Smeem extern mblk_t *esballoc_wait(unsigned char *, size_t, uint_t, frtn_t *);
11980Sstevel@tonic-gate extern mblk_t *esballoca(unsigned char *, size_t, uint_t, frtn_t *);
11990Sstevel@tonic-gate extern mblk_t *desballoca(unsigned char *, size_t, uint_t, frtn_t *);
12000Sstevel@tonic-gate extern int do_sendfp(struct stdata *, struct file *, struct cred *);
12010Sstevel@tonic-gate extern int frozenstr(queue_t *);
12020Sstevel@tonic-gate extern size_t xmsgsize(mblk_t *);
12030Sstevel@tonic-gate 
12040Sstevel@tonic-gate extern void putnext_tail(syncq_t *, queue_t *, uint32_t);
12050Sstevel@tonic-gate extern void stream_willservice(stdata_t *);
12060Sstevel@tonic-gate extern void stream_runservice(stdata_t *);
12070Sstevel@tonic-gate 
12080Sstevel@tonic-gate extern void strmate(vnode_t *, vnode_t *);
12090Sstevel@tonic-gate extern queue_t *strvp2wq(vnode_t *);
12100Sstevel@tonic-gate extern vnode_t *strq2vp(queue_t *);
12110Sstevel@tonic-gate extern mblk_t *allocb_wait(size_t, uint_t, uint_t, int *);
12120Sstevel@tonic-gate extern mblk_t *allocb_cred(size_t, cred_t *);
12130Sstevel@tonic-gate extern mblk_t *allocb_cred_wait(size_t, uint_t, int *, cred_t *);
12140Sstevel@tonic-gate extern mblk_t *allocb_tmpl(size_t, const mblk_t *);
1215741Smasputra extern mblk_t *allocb_tryhard(size_t);
12160Sstevel@tonic-gate extern void mblk_setcred(mblk_t *, cred_t *);
1217560Smeem extern void strpollwakeup(vnode_t *, short);
12180Sstevel@tonic-gate extern int putnextctl_wait(queue_t *, int);
12190Sstevel@tonic-gate 
1220560Smeem extern int kstrputmsg(struct vnode *, mblk_t *, struct uio *, ssize_t,
12210Sstevel@tonic-gate     unsigned char, int, int);
1222560Smeem extern int kstrgetmsg(struct vnode *, mblk_t **, struct uio *,
12230Sstevel@tonic-gate     unsigned char *, int *, clock_t, rval_t *);
12240Sstevel@tonic-gate 
1225560Smeem extern void strsetrerror(vnode_t *, int, int, errfunc_t);
1226560Smeem extern void strsetwerror(vnode_t *, int, int, errfunc_t);
1227560Smeem extern void strseteof(vnode_t *, int);
1228560Smeem extern void strflushrq(vnode_t *, int);
1229560Smeem extern void strsetrputhooks(vnode_t *, uint_t, msgfunc_t, msgfunc_t);
1230560Smeem extern void strsetwputhooks(vnode_t *, uint_t, clock_t);
1231898Skais extern void strsetrwputdatahooks(vnode_t *, msgfunc_t, msgfunc_t);
1232560Smeem extern int strwaitmark(vnode_t *);
12330Sstevel@tonic-gate extern void strsignal_nolock(stdata_t *, int, int32_t);
12340Sstevel@tonic-gate 
12350Sstevel@tonic-gate struct multidata_s;
12360Sstevel@tonic-gate struct pdesc_s;
12370Sstevel@tonic-gate extern int hcksum_assoc(mblk_t *, struct multidata_s *, struct pdesc_s  *,
12380Sstevel@tonic-gate     uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, int);
12390Sstevel@tonic-gate extern void hcksum_retrieve(mblk_t *, struct multidata_s *, struct pdesc_s *,
12400Sstevel@tonic-gate     uint32_t *, uint32_t *, uint32_t *, uint32_t *, uint32_t *);
12410Sstevel@tonic-gate extern unsigned int bcksum(uchar_t *, int, unsigned int);
12420Sstevel@tonic-gate extern boolean_t is_vmloaned_mblk(mblk_t *, struct multidata_s *,
12430Sstevel@tonic-gate     struct pdesc_s *);
12440Sstevel@tonic-gate 
12450Sstevel@tonic-gate extern int fmodsw_register(const char *, struct streamtab *, int);
12460Sstevel@tonic-gate extern int fmodsw_unregister(const char *);
12470Sstevel@tonic-gate extern fmodsw_impl_t *fmodsw_find(const char *, fmodsw_flags_t);
12480Sstevel@tonic-gate extern void fmodsw_rele(fmodsw_impl_t *);
12490Sstevel@tonic-gate 
12500Sstevel@tonic-gate extern void freemsgchain(mblk_t *);
12510Sstevel@tonic-gate extern mblk_t *copymsgchain(mblk_t *);
12520Sstevel@tonic-gate 
1253741Smasputra extern mblk_t *mcopyinuio(struct stdata *, uio_t *, ssize_t, ssize_t, int *);
1254741Smasputra 
12550Sstevel@tonic-gate /*
12560Sstevel@tonic-gate  * shared or externally configured data structures
12570Sstevel@tonic-gate  */
12580Sstevel@tonic-gate extern ssize_t strmsgsz;		/* maximum stream message size */
12590Sstevel@tonic-gate extern ssize_t strctlsz;		/* maximum size of ctl message */
12600Sstevel@tonic-gate extern int nstrpush;			/* maximum number of pushes allowed */
12610Sstevel@tonic-gate 
12620Sstevel@tonic-gate /*
12630Sstevel@tonic-gate  * Bufcalls related variables.
12640Sstevel@tonic-gate  */
12650Sstevel@tonic-gate extern struct bclist strbcalls;		/* List of bufcalls */
12660Sstevel@tonic-gate extern kmutex_t	strbcall_lock;		/* Protects the list of bufcalls */
12670Sstevel@tonic-gate extern kcondvar_t strbcall_cv;		/* Signaling when a bufcall is added */
12680Sstevel@tonic-gate extern kcondvar_t bcall_cv;	/* wait of executing bufcall completes */
12690Sstevel@tonic-gate 
12700Sstevel@tonic-gate extern frtn_t frnop;
12710Sstevel@tonic-gate 
12720Sstevel@tonic-gate extern struct kmem_cache *ciputctrl_cache;
12730Sstevel@tonic-gate extern int n_ciputctrl;
12740Sstevel@tonic-gate extern int max_n_ciputctrl;
12750Sstevel@tonic-gate extern int min_n_ciputctrl;
12760Sstevel@tonic-gate 
12770Sstevel@tonic-gate extern cdevsw_impl_t *devimpl;
12783932Sss146032 
12793932Sss146032 /*
12803932Sss146032  * esballoc queue for throttling
12813932Sss146032  */
12823932Sss146032 typedef struct esb_queue {
12833932Sss146032 	kmutex_t	eq_lock;
12843932Sss146032 	uint_t		eq_len;		/* number of queued messages */
12853932Sss146032 	mblk_t		*eq_head;	/* head of queue */
12863932Sss146032 	mblk_t		*eq_tail;	/* tail of queue */
12873932Sss146032 	uint_t		eq_flags;	/* esballoc queue flags */
12883932Sss146032 } esb_queue_t;
12893932Sss146032 
12903932Sss146032 /*
12913932Sss146032  * esballoc flags for queue processing.
12923932Sss146032  */
12933932Sss146032 #define	ESBQ_PROCESSING	0x01	/* queue is being processed */
12943932Sss146032 #define	ESBQ_TIMER	0x02	/* timer is active */
12953932Sss146032 
12963932Sss146032 extern void esballoc_queue_init(void);
12973932Sss146032 
12980Sstevel@tonic-gate #endif	/* _KERNEL */
12990Sstevel@tonic-gate 
13000Sstevel@tonic-gate /*
13010Sstevel@tonic-gate  * Note: Use of these macros are restricted to kernel/unix and
13020Sstevel@tonic-gate  * intended for the STREAMS framework.
13030Sstevel@tonic-gate  * All modules/drivers should include sys/ddi.h.
13040Sstevel@tonic-gate  *
13050Sstevel@tonic-gate  * Finding related queues
13060Sstevel@tonic-gate  */
13070Sstevel@tonic-gate #define		_OTHERQ(q)	((q)->q_flag&QREADR? (q)+1: (q)-1)
13080Sstevel@tonic-gate #define		_WR(q)		((q)->q_flag&QREADR? (q)+1: (q))
13090Sstevel@tonic-gate #define		_RD(q)		((q)->q_flag&QREADR? (q): (q)-1)
13100Sstevel@tonic-gate #define		_SAMESTR(q)	(!((q)->q_flag & QEND))
13110Sstevel@tonic-gate 
13120Sstevel@tonic-gate /*
13130Sstevel@tonic-gate  * These are also declared here for modules/drivers that erroneously
13140Sstevel@tonic-gate  * include strsubr.h after ddi.h or fail to include ddi.h at all.
13150Sstevel@tonic-gate  */
13160Sstevel@tonic-gate extern struct queue *OTHERQ(queue_t *); /* stream.h */
13170Sstevel@tonic-gate extern struct queue *RD(queue_t *);
13180Sstevel@tonic-gate extern struct queue *WR(queue_t *);
13190Sstevel@tonic-gate extern int SAMESTR(queue_t *);
13200Sstevel@tonic-gate 
1321741Smasputra /*
1322741Smasputra  * The following hardware checksum related macros are private
1323741Smasputra  * interfaces that are subject to change without notice.
1324741Smasputra  */
1325741Smasputra #ifdef _KERNEL
1326741Smasputra #define	DB_CKSUMSTART(mp)	((mp)->b_datap->db_cksumstart)
1327741Smasputra #define	DB_CKSUMEND(mp)		((mp)->b_datap->db_cksumend)
1328741Smasputra #define	DB_CKSUMSTUFF(mp)	((mp)->b_datap->db_cksumstuff)
1329741Smasputra #define	DB_CKSUMFLAGS(mp)	((mp)->b_datap->db_struioun.cksum.flags)
1330741Smasputra #define	DB_CKSUM16(mp)		((mp)->b_datap->db_cksum16)
1331741Smasputra #define	DB_CKSUM32(mp)		((mp)->b_datap->db_cksum32)
13323115Syl150051 #define	DB_LSOFLAGS(mp)		((mp)->b_datap->db_struioun.cksum.flags)
13333115Syl150051 #define	DB_LSOMSS(mp)		((mp)->b_datap->db_struioun.cksum.pad)
1334741Smasputra #endif	/* _KERNEL */
1335741Smasputra 
13360Sstevel@tonic-gate #ifdef	__cplusplus
13370Sstevel@tonic-gate }
13380Sstevel@tonic-gate #endif
13390Sstevel@tonic-gate 
13400Sstevel@tonic-gate 
13410Sstevel@tonic-gate #endif	/* _SYS_STRSUBR_H */
1342