xref: /illumos-gate/usr/src/uts/common/sys/stream.h (revision ff550d0e264b51131fb34e9e83163b348d916640)
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
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifndef _SYS_STREAM_H
327c478bd9Sstevel@tonic-gate #define	_SYS_STREAM_H
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 11.44	*/
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate /*
377c478bd9Sstevel@tonic-gate  * For source compatibility
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
407c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
417c478bd9Sstevel@tonic-gate #include <sys/poll.h>
427c478bd9Sstevel@tonic-gate #include <sys/strmdep.h>
437c478bd9Sstevel@tonic-gate #include <sys/cred.h>
447c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
457c478bd9Sstevel@tonic-gate #include <sys/model.h>
467c478bd9Sstevel@tonic-gate #include <sys/strft.h>
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
497c478bd9Sstevel@tonic-gate extern "C" {
507c478bd9Sstevel@tonic-gate #endif
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate /*
537c478bd9Sstevel@tonic-gate  * Both the queue and the data block structures have embedded
547c478bd9Sstevel@tonic-gate  * mutexes: q_lock and db_lock.  In general, these mutexes protect
557c478bd9Sstevel@tonic-gate  * the consistency of the data structure.  In addition, q_lock
567c478bd9Sstevel@tonic-gate  * is used, with the stream head condition variable, to implement
577c478bd9Sstevel@tonic-gate  * a monitor at the stream head for blocking reads and writes.
587c478bd9Sstevel@tonic-gate  * Neither of these locks should be acquired by module or driver code.
597c478bd9Sstevel@tonic-gate  *
607c478bd9Sstevel@tonic-gate  * In particular, q_lock protects the following fields:
617c478bd9Sstevel@tonic-gate  *	q_first
627c478bd9Sstevel@tonic-gate  *	q_last
637c478bd9Sstevel@tonic-gate  *	q_link
647c478bd9Sstevel@tonic-gate  *	q_count
657c478bd9Sstevel@tonic-gate  *	q_bandp
667c478bd9Sstevel@tonic-gate  *	q_nband
677c478bd9Sstevel@tonic-gate  *
687c478bd9Sstevel@tonic-gate  * q_next is protected by stream head locking; this links the
697c478bd9Sstevel@tonic-gate  * stream together, and should be thought of as part of the stream
707c478bd9Sstevel@tonic-gate  * data structure, not the queue.
717c478bd9Sstevel@tonic-gate  *
727c478bd9Sstevel@tonic-gate  * The remaining fields are either modified only by the allocator,
737c478bd9Sstevel@tonic-gate  * which has exclusive access to them at that time, or are not to
747c478bd9Sstevel@tonic-gate  * be touched by anything but the MT synchronization primitives
757c478bd9Sstevel@tonic-gate  * (i.e. q_wait).
767c478bd9Sstevel@tonic-gate  *
777c478bd9Sstevel@tonic-gate  * q_sqnext and q_sqprev are special - they are protected by
787c478bd9Sstevel@tonic-gate  * SQLOCK(q->syncq).
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /*
827c478bd9Sstevel@tonic-gate  * Data queue
837c478bd9Sstevel@tonic-gate  */
847c478bd9Sstevel@tonic-gate typedef struct	queue {
857c478bd9Sstevel@tonic-gate 	struct	qinit	*q_qinfo;	/* procs and limits for queue	*/
867c478bd9Sstevel@tonic-gate 	struct	msgb	*q_first;	/* first data block		*/
877c478bd9Sstevel@tonic-gate 	struct	msgb	*q_last;	/* last data block		*/
887c478bd9Sstevel@tonic-gate 	struct	queue	*q_next;	/* Q of next stream		*/
897c478bd9Sstevel@tonic-gate 	struct	queue	*q_link;	/* to next Q for scheduling	*/
907c478bd9Sstevel@tonic-gate 	void		*q_ptr;		/* to private data structure	*/
917c478bd9Sstevel@tonic-gate 	size_t		q_count;	/* number of bytes on Q		*/
927c478bd9Sstevel@tonic-gate 	uint_t		q_flag;		/* queue state			*/
937c478bd9Sstevel@tonic-gate 	ssize_t		q_minpsz;	/* min packet size accepted by	*/
947c478bd9Sstevel@tonic-gate 					/* this module			*/
957c478bd9Sstevel@tonic-gate 	ssize_t		q_maxpsz;	/* max packet size accepted by	*/
967c478bd9Sstevel@tonic-gate 					/* this module			*/
977c478bd9Sstevel@tonic-gate 	size_t		q_hiwat;	/* queue high water mark	*/
987c478bd9Sstevel@tonic-gate 	size_t		q_lowat;	/* queue low water mark		*/
997c478bd9Sstevel@tonic-gate 	struct qband	*q_bandp;	/* separate flow information */
1007c478bd9Sstevel@tonic-gate 	kmutex_t	q_lock;		/* protect data queue		*/
1017c478bd9Sstevel@tonic-gate 	struct stdata 	*q_stream;	/* for head locks		*/
1027c478bd9Sstevel@tonic-gate 	struct	syncq	*q_syncq;	/* sync queue object		*/
1037c478bd9Sstevel@tonic-gate 	unsigned char	q_nband;	/* number of priority bands > 0	*/
1047c478bd9Sstevel@tonic-gate 	kcondvar_t	q_wait;		/* read/write sleeps		*/
1057c478bd9Sstevel@tonic-gate 	struct	queue	*q_nfsrv;	/* next q fwd with service routine */
1067c478bd9Sstevel@tonic-gate 	ushort_t	q_draining;	/* protected by QLOCK - drain_syncq */
1077c478bd9Sstevel@tonic-gate 	short		q_struiot;	/* stream uio type for struio()	*/
1087c478bd9Sstevel@tonic-gate 	uint_t		q_syncqmsgs;	/* messages in syncq for this queue */
1097c478bd9Sstevel@tonic-gate 	size_t		q_mblkcnt;	/* mblk counter for runaway msgs */
1107c478bd9Sstevel@tonic-gate 	/*
1117c478bd9Sstevel@tonic-gate 	 * Syncq scheduling.
1127c478bd9Sstevel@tonic-gate 	 * These fields are initially protected by the SQLOCK,
1137c478bd9Sstevel@tonic-gate 	 * but they will eventually be protected by the QLOCK.
1147c478bd9Sstevel@tonic-gate 	 * The lock ordering is QLOCK then SQLOCK.
1157c478bd9Sstevel@tonic-gate 	 * Note that  q_syncqmsgs can either disappear, or be an additional
1167c478bd9Sstevel@tonic-gate 	 * count of messages instead of bytes (need bytes for QFULL).
1177c478bd9Sstevel@tonic-gate 	 */
1187c478bd9Sstevel@tonic-gate 	struct msgb	*q_sqhead;	/* first syncq message		*/
1197c478bd9Sstevel@tonic-gate 	struct msgb	*q_sqtail;	/* last syncq message		*/
1207c478bd9Sstevel@tonic-gate 	uint_t		q_sqflags;	/* Queue flags, protected by SQLOCK */
1217c478bd9Sstevel@tonic-gate 	size_t		q_rwcnt;	/* Number of threads synchronously */
1227c478bd9Sstevel@tonic-gate 					/* entering Q */
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 	/*
1257c478bd9Sstevel@tonic-gate 	 * These fields need to be protected by the SQLOCK since
1267c478bd9Sstevel@tonic-gate 	 * the corresponding syncq fields are (sq_head/sq_tail).
1277c478bd9Sstevel@tonic-gate 	 */
1287c478bd9Sstevel@tonic-gate 	struct queue	*q_sqnext;	/* Next Q on syncq list		*/
1297c478bd9Sstevel@tonic-gate 	struct queue	*q_sqprev;	/* Previous Q on syncq list	*/
1307c478bd9Sstevel@tonic-gate 	clock_t		q_sqtstamp;	/* Time when Q was scheduled for sq */
1317c478bd9Sstevel@tonic-gate 	clock_t		q_qtstamp;	/* Time when Q was enabled	*/
1327c478bd9Sstevel@tonic-gate 	pri_t		q_spri;		/* Scheduling priority		*/
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 	/*
1357c478bd9Sstevel@tonic-gate 	 * Reference to the queue's module's implementation structure. This
1367c478bd9Sstevel@tonic-gate 	 * will be NULL for queues associated with drivers.
1377c478bd9Sstevel@tonic-gate 	 */
1387c478bd9Sstevel@tonic-gate 	struct fmodsw_impl	*q_fp;
1397c478bd9Sstevel@tonic-gate } queue_t;
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate /*
1427c478bd9Sstevel@tonic-gate  * Queue flags; unused flags not documented in queue(9S) can be recycled.
1437c478bd9Sstevel@tonic-gate  */
1447c478bd9Sstevel@tonic-gate #define	QENAB		0x00000001	/* Queue is already enabled to run */
1457c478bd9Sstevel@tonic-gate #define	QWANTR		0x00000002	/* Someone wants to read Q	*/
1467c478bd9Sstevel@tonic-gate #define	QWANTW		0x00000004	/* Someone wants to write Q	*/
1477c478bd9Sstevel@tonic-gate #define	QFULL		0x00000008	/* Q is considered full		*/
1487c478bd9Sstevel@tonic-gate #define	QREADR		0x00000010	/* This is the reader (first) Q	*/
1497c478bd9Sstevel@tonic-gate #define	QUSE		0x00000020	/* This queue in use (allocation) */
1507c478bd9Sstevel@tonic-gate #define	QNOENB		0x00000040	/* Don't enable Q via putq	*/
1517c478bd9Sstevel@tonic-gate #define	QWANTRMQSYNC	0x00000080	/* Want to remove sync stream Q */
1527c478bd9Sstevel@tonic-gate #define	QBACK		0x00000100	/* queue has been back-enabled	*/
1537c478bd9Sstevel@tonic-gate /*	UNUSED		0x00000200	   was QHLIST			*/
1547c478bd9Sstevel@tonic-gate /* 	UNUSED 		0x00000400	   was QUNSAFE			*/
1557c478bd9Sstevel@tonic-gate #define	QPAIR		0x00000800	/* per queue-pair syncq		*/
1567c478bd9Sstevel@tonic-gate #define	QPERQ 		0x00001000	/* per queue-instance syncq	*/
1577c478bd9Sstevel@tonic-gate #define	QPERMOD		0x00002000	/* per module syncq		*/
1587c478bd9Sstevel@tonic-gate #define	QMTSAFE		0x00004000	/* stream module is MT-safe	*/
1597c478bd9Sstevel@tonic-gate #define	QMTOUTPERIM	0x00008000	/* Has outer perimeter		*/
1607c478bd9Sstevel@tonic-gate #define	QMT_TYPEMASK	(QPAIR|QPERQ|QPERMOD|QMTSAFE|QMTOUTPERIM)
1617c478bd9Sstevel@tonic-gate 					/* all MT type flags		*/
1627c478bd9Sstevel@tonic-gate #define	QINSERVICE	0x00010000	/* service routine executing	*/
1637c478bd9Sstevel@tonic-gate #define	QWCLOSE		0x00020000	/* will not be enabled		*/
1647c478bd9Sstevel@tonic-gate #define	QEND		0x00040000	/* last queue in stream		*/
1657c478bd9Sstevel@tonic-gate #define	QWANTWSYNC	0x00080000	/* Streamhead wants to write Q	*/
1667c478bd9Sstevel@tonic-gate #define	QSYNCSTR	0x00100000	/* Q supports Synchronous STREAMS */
1677c478bd9Sstevel@tonic-gate #define	QISDRV		0x00200000	/* the Queue is attached to a driver */
1687c478bd9Sstevel@tonic-gate /*	UNUSED		0x00400000	   was QHOT			*/
1697c478bd9Sstevel@tonic-gate /*	UNUSED		0x00800000	   was QNEXTHOT			*/
1707c478bd9Sstevel@tonic-gate /* 	UNUSED		0x01000000	   was _QNEXTLESS		*/
1717c478bd9Sstevel@tonic-gate #define	_QINSERTING	0x04000000	/* Private, module is being inserted */
1727c478bd9Sstevel@tonic-gate #define	_QREMOVING	0x08000000	/* Private, module is being removed */
1737c478bd9Sstevel@tonic-gate #define	_QASSOCIATED	0x10000000	/* queue is associated with a device */
174*ff550d0eSmasputra #define	_QDIRECT	0x20000000	/* Private; transport module uses */
175*ff550d0eSmasputra 					/* direct interface to/from sockfs */
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate /* queue sqflags (protected by SQLOCK). */
1787c478bd9Sstevel@tonic-gate #define	Q_SQQUEUED	0x01		/* Queue is in the syncq list */
1797c478bd9Sstevel@tonic-gate #define	Q_SQDRAINING	0x02		/* Servicing suncq msgs.	*/
1807c478bd9Sstevel@tonic-gate 					/* This is also noted by the	*/
1817c478bd9Sstevel@tonic-gate 					/* q_draining field, but this one is */
1827c478bd9Sstevel@tonic-gate 					/* protected by SQLOCK */
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate /*
1857c478bd9Sstevel@tonic-gate  * Structure that describes the separate information
1867c478bd9Sstevel@tonic-gate  * for each priority band in the queue.
1877c478bd9Sstevel@tonic-gate  */
1887c478bd9Sstevel@tonic-gate typedef struct qband {
1897c478bd9Sstevel@tonic-gate 	struct qband	*qb_next;	/* next band's info */
1907c478bd9Sstevel@tonic-gate 	size_t		qb_count;	/* number of bytes in band */
1917c478bd9Sstevel@tonic-gate 	struct msgb	*qb_first;	/* beginning of band's data */
1927c478bd9Sstevel@tonic-gate 	struct msgb	*qb_last;	/* end of band's data */
1937c478bd9Sstevel@tonic-gate 	size_t		qb_hiwat;	/* high water mark for band */
1947c478bd9Sstevel@tonic-gate 	size_t		qb_lowat;	/* low water mark for band */
1957c478bd9Sstevel@tonic-gate 	uint_t		qb_flag;	/* see below */
1967c478bd9Sstevel@tonic-gate 	size_t		qb_mblkcnt;	/* mblk counter for runaway msgs */
1977c478bd9Sstevel@tonic-gate } qband_t;
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate /*
2007c478bd9Sstevel@tonic-gate  * qband flags
2017c478bd9Sstevel@tonic-gate  */
2027c478bd9Sstevel@tonic-gate #define	QB_FULL		0x01		/* band is considered full */
2037c478bd9Sstevel@tonic-gate #define	QB_WANTW	0x02		/* Someone wants to write to band */
2047c478bd9Sstevel@tonic-gate #define	QB_BACK		0x04		/* queue has been back-enabled */
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate /*
2077c478bd9Sstevel@tonic-gate  * Maximum number of bands.
2087c478bd9Sstevel@tonic-gate  */
2097c478bd9Sstevel@tonic-gate #define	NBAND	256
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate /*
2127c478bd9Sstevel@tonic-gate  * Fields that can be manipulated through strqset() and strqget().
2137c478bd9Sstevel@tonic-gate  */
2147c478bd9Sstevel@tonic-gate typedef enum qfields {
2157c478bd9Sstevel@tonic-gate 	QHIWAT	= 0,		/* q_hiwat or qb_hiwat */
2167c478bd9Sstevel@tonic-gate 	QLOWAT	= 1,		/* q_lowat or qb_lowat */
2177c478bd9Sstevel@tonic-gate 	QMAXPSZ	= 2,		/* q_maxpsz */
2187c478bd9Sstevel@tonic-gate 	QMINPSZ	= 3,		/* q_minpsz */
2197c478bd9Sstevel@tonic-gate 	QCOUNT	= 4,		/* q_count or qb_count */
2207c478bd9Sstevel@tonic-gate 	QFIRST	= 5,		/* q_first or qb_first */
2217c478bd9Sstevel@tonic-gate 	QLAST	= 6,		/* q_last or qb_last */
2227c478bd9Sstevel@tonic-gate 	QFLAG	= 7,		/* q_flag or qb_flag */
2237c478bd9Sstevel@tonic-gate 	QSTRUIOT = 8,		/* q_struiot */
2247c478bd9Sstevel@tonic-gate 	QBAD	= 9
2257c478bd9Sstevel@tonic-gate } qfields_t;
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate /*
2287c478bd9Sstevel@tonic-gate  * Module information structure
2297c478bd9Sstevel@tonic-gate  */
2307c478bd9Sstevel@tonic-gate struct module_info {
2317c478bd9Sstevel@tonic-gate 	ushort_t mi_idnum;		/* module id number */
2327c478bd9Sstevel@tonic-gate 	char 	*mi_idname;		/* module name */
2337c478bd9Sstevel@tonic-gate 	ssize_t	mi_minpsz;		/* min packet size accepted */
2347c478bd9Sstevel@tonic-gate 	ssize_t	mi_maxpsz;		/* max packet size accepted */
2357c478bd9Sstevel@tonic-gate 	size_t	mi_hiwat;		/* hi-water mark */
2367c478bd9Sstevel@tonic-gate 	size_t 	mi_lowat;		/* lo-water mark */
2377c478bd9Sstevel@tonic-gate };
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate /*
2407c478bd9Sstevel@tonic-gate  * queue information structure (with Synchronous STREAMS extensions)
2417c478bd9Sstevel@tonic-gate  */
2427c478bd9Sstevel@tonic-gate struct	qinit {
2437c478bd9Sstevel@tonic-gate 	int	(*qi_putp)();		/* put procedure */
2447c478bd9Sstevel@tonic-gate 	int	(*qi_srvp)();		/* service procedure */
2457c478bd9Sstevel@tonic-gate 	int	(*qi_qopen)();		/* called on startup */
2467c478bd9Sstevel@tonic-gate 	int	(*qi_qclose)();		/* called on finish */
2477c478bd9Sstevel@tonic-gate 	int	(*qi_qadmin)();		/* for future use */
2487c478bd9Sstevel@tonic-gate 	struct module_info *qi_minfo;	/* module information structure */
2497c478bd9Sstevel@tonic-gate 	struct module_stat *qi_mstat;	/* module statistics structure */
2507c478bd9Sstevel@tonic-gate 	int	(*qi_rwp)();		/* r/w procedure */
2517c478bd9Sstevel@tonic-gate 	int	(*qi_infop)();		/* information procedure */
2527c478bd9Sstevel@tonic-gate 	int	qi_struiot;		/* stream uio type for struio() */
2537c478bd9Sstevel@tonic-gate };
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate /*
2567c478bd9Sstevel@tonic-gate  * Values for qi_struiot and q_struiot:
2577c478bd9Sstevel@tonic-gate  */
2587c478bd9Sstevel@tonic-gate #define	STRUIOT_NONE		-1	/* doesn't support struio() */
2597c478bd9Sstevel@tonic-gate #define	STRUIOT_DONTCARE	0	/* use current uiomove() (default) */
2607c478bd9Sstevel@tonic-gate #define	STRUIOT_STANDARD	1	/* use standard uiomove() */
2617c478bd9Sstevel@tonic-gate 
2627c478bd9Sstevel@tonic-gate /*
2637c478bd9Sstevel@tonic-gate  * Streamtab (used in cdevsw and fmodsw to point to module or driver)
2647c478bd9Sstevel@tonic-gate  */
2657c478bd9Sstevel@tonic-gate struct streamtab {
2667c478bd9Sstevel@tonic-gate 	struct qinit *st_rdinit;
2677c478bd9Sstevel@tonic-gate 	struct qinit *st_wrinit;
2687c478bd9Sstevel@tonic-gate 	struct qinit *st_muxrinit;
2697c478bd9Sstevel@tonic-gate 	struct qinit *st_muxwinit;
2707c478bd9Sstevel@tonic-gate };
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate /*
2737c478bd9Sstevel@tonic-gate  * Structure sent to mux drivers to indicate a link.
2747c478bd9Sstevel@tonic-gate  */
2757c478bd9Sstevel@tonic-gate struct linkblk {
2767c478bd9Sstevel@tonic-gate 	queue_t *l_qtop;	/* lowest level write queue of upper stream */
2777c478bd9Sstevel@tonic-gate 				/* (set to NULL for persistent links) */
2787c478bd9Sstevel@tonic-gate 	queue_t *l_qbot;	/* highest level write queue of lower stream */
2797c478bd9Sstevel@tonic-gate 	int	l_index;	/* index for lower stream. */
2807c478bd9Sstevel@tonic-gate };
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate /*
2837c478bd9Sstevel@tonic-gate  * Esballoc data buffer freeing routine
2847c478bd9Sstevel@tonic-gate  */
2857c478bd9Sstevel@tonic-gate typedef struct free_rtn {
2867c478bd9Sstevel@tonic-gate 	void	(*free_func)();
2877c478bd9Sstevel@tonic-gate 	caddr_t	free_arg;
2887c478bd9Sstevel@tonic-gate } frtn_t;
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate /*
2917c478bd9Sstevel@tonic-gate  * Data block descriptor
2927c478bd9Sstevel@tonic-gate  *
2937c478bd9Sstevel@tonic-gate  * NOTE: db_base, db_lim, db_ref and db_type are the *only* public fields,
2947c478bd9Sstevel@tonic-gate  * as described in datab(9S).  Everything else is implementation-private.
2957c478bd9Sstevel@tonic-gate  */
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate #define	DBLK_REFMAX	255U
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate typedef struct datab {
3007c478bd9Sstevel@tonic-gate 	frtn_t		*db_frtnp;
3017c478bd9Sstevel@tonic-gate 	unsigned char	*db_base;
3027c478bd9Sstevel@tonic-gate 	unsigned char	*db_lim;
3037c478bd9Sstevel@tonic-gate 	unsigned char	db_ref;
3047c478bd9Sstevel@tonic-gate 	unsigned char	db_type;
3057c478bd9Sstevel@tonic-gate 	unsigned char	db_flags;
3067c478bd9Sstevel@tonic-gate 	unsigned char	db_struioflag;
3077c478bd9Sstevel@tonic-gate 	pid_t		db_cpid;	/* cached pid, needs verification */
3087c478bd9Sstevel@tonic-gate 	void		*db_cache;	/* kmem cache descriptor */
3097c478bd9Sstevel@tonic-gate 	struct msgb	*db_mblk;
3107c478bd9Sstevel@tonic-gate 	void		(*db_free)(struct msgb *, struct datab *);
3117c478bd9Sstevel@tonic-gate 	void		(*db_lastfree)(struct msgb *, struct datab *);
3127c478bd9Sstevel@tonic-gate 	intptr_t	db_cksumstart;
3137c478bd9Sstevel@tonic-gate 	intptr_t	db_cksumend;
3147c478bd9Sstevel@tonic-gate 	intptr_t	db_cksumstuff;
3157c478bd9Sstevel@tonic-gate 	union {
3167c478bd9Sstevel@tonic-gate 		double enforce_alignment;
3177c478bd9Sstevel@tonic-gate 		unsigned char data[8];
3187c478bd9Sstevel@tonic-gate 		struct {
3197c478bd9Sstevel@tonic-gate 			union {
3207c478bd9Sstevel@tonic-gate 				uint32_t u32;
3217c478bd9Sstevel@tonic-gate 				uint16_t u16;
3227c478bd9Sstevel@tonic-gate 			} cksum_val;    /* used to store calculated cksum */
3237c478bd9Sstevel@tonic-gate 			uint16_t flags;
3247c478bd9Sstevel@tonic-gate 			uint16_t pad;
3257c478bd9Sstevel@tonic-gate 		} cksum;
3267c478bd9Sstevel@tonic-gate 		/*
3277c478bd9Sstevel@tonic-gate 		 * Union used for future extensions (pointer to data ?).
3287c478bd9Sstevel@tonic-gate 		 */
3297c478bd9Sstevel@tonic-gate 	} db_struioun;
3307c478bd9Sstevel@tonic-gate 	fthdr_t		*db_fthdr;
3317c478bd9Sstevel@tonic-gate 	cred_t		*db_credp;	/* credential */
3327c478bd9Sstevel@tonic-gate } dblk_t;
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate #define	db_cksum16	db_struioun.cksum.cksum_val.u16
3357c478bd9Sstevel@tonic-gate #define	db_cksum32	db_struioun.cksum.cksum_val.u32
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate /*
3387c478bd9Sstevel@tonic-gate  * Accessor macros for private dblk_t fields (the rest are in <sys/strsun.h>).
3397c478bd9Sstevel@tonic-gate  */
3407c478bd9Sstevel@tonic-gate #define	DB_CPID(mp)		((mp)->b_datap->db_cpid)
3417c478bd9Sstevel@tonic-gate #define	DB_CRED(mp)		((mp)->b_datap->db_credp)
3427c478bd9Sstevel@tonic-gate #define	DB_CREDDEF(mp, cr)	(DB_CRED(mp) != NULL ? DB_CRED(mp) : (cr))
3437c478bd9Sstevel@tonic-gate #define	DB_FTHDR(mp)		((mp)->b_datap->db_fthdr)
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate /*
3467c478bd9Sstevel@tonic-gate  * Message block descriptor
3477c478bd9Sstevel@tonic-gate  */
3487c478bd9Sstevel@tonic-gate typedef struct	msgb {
3497c478bd9Sstevel@tonic-gate 	struct	msgb	*b_next;
3507c478bd9Sstevel@tonic-gate 	struct  msgb	*b_prev;
3517c478bd9Sstevel@tonic-gate 	struct	msgb	*b_cont;
3527c478bd9Sstevel@tonic-gate 	unsigned char	*b_rptr;
3537c478bd9Sstevel@tonic-gate 	unsigned char	*b_wptr;
3547c478bd9Sstevel@tonic-gate 	struct datab 	*b_datap;
3557c478bd9Sstevel@tonic-gate 	unsigned char	b_band;
3567c478bd9Sstevel@tonic-gate 	unsigned char	b_tag;
3577c478bd9Sstevel@tonic-gate 	unsigned short	b_flag;
3587c478bd9Sstevel@tonic-gate 	queue_t		*b_queue;	/* for sync queues */
3597c478bd9Sstevel@tonic-gate } mblk_t;
3607c478bd9Sstevel@tonic-gate 
3617c478bd9Sstevel@tonic-gate /*
3627c478bd9Sstevel@tonic-gate  * bcache descriptor
3637c478bd9Sstevel@tonic-gate  */
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate typedef	struct	bcache {
3667c478bd9Sstevel@tonic-gate 	kmutex_t		mutex;
3677c478bd9Sstevel@tonic-gate 	struct kmem_cache	*buffer_cache;
3687c478bd9Sstevel@tonic-gate 	struct kmem_cache	*dblk_cache;
3697c478bd9Sstevel@tonic-gate 	int			alloc;
3707c478bd9Sstevel@tonic-gate 	int			destroy;
3717c478bd9Sstevel@tonic-gate 	size_t			size;
3727c478bd9Sstevel@tonic-gate 	uint_t			align;
3737c478bd9Sstevel@tonic-gate } bcache_t;
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate /*
3767c478bd9Sstevel@tonic-gate  * db_flags values (all implementation private!)
3777c478bd9Sstevel@tonic-gate  */
3787c478bd9Sstevel@tonic-gate #define	DBLK_REFMIN	0x01		/* min refcnt stored in low bit */
3797c478bd9Sstevel@tonic-gate 
3807c478bd9Sstevel@tonic-gate /*
3817c478bd9Sstevel@tonic-gate  * db_struioflag values:
3827c478bd9Sstevel@tonic-gate  */
3837c478bd9Sstevel@tonic-gate #define	STRUIO_SPEC	0x01	/* struio{get,put}() special mblk */
3847c478bd9Sstevel@tonic-gate #define	STRUIO_DONE	0x02	/* struio done (could be partial) */
3857c478bd9Sstevel@tonic-gate #define	STRUIO_IP	0x04	/* IP checksum stored in db_struioun */
3867c478bd9Sstevel@tonic-gate #define	STRUIO_ZC	0x08	/* mblk eligible for zero-copy */
3877c478bd9Sstevel@tonic-gate #define	STRUIO_ZCNOTIFY	0x10	/* notify stream head when mblk acked */
3887c478bd9Sstevel@tonic-gate #define	STRUIO_EAGER	0x20	/* new eager; db_cksumstart has squeue to use */
3897c478bd9Sstevel@tonic-gate #define	STRUIO_POLICY	0x40	/* new eager when IPsec is enabled */
3907c478bd9Sstevel@tonic-gate 
3917c478bd9Sstevel@tonic-gate /*
3927c478bd9Sstevel@tonic-gate  * Message flags.  These are interpreted by the stream head.
3937c478bd9Sstevel@tonic-gate  */
3947c478bd9Sstevel@tonic-gate #define	MSGMARK		0x01	/* last byte of message is "marked" */
3957c478bd9Sstevel@tonic-gate #define	MSGNOLOOP	0x02	/* don't loop message around to */
3967c478bd9Sstevel@tonic-gate 				/* write side of stream */
3977c478bd9Sstevel@tonic-gate #define	MSGDELIM	0x04	/* message is delimited */
3987c478bd9Sstevel@tonic-gate /*	UNUSED		0x08	   was MSGNOGET (can be recycled) */
3997c478bd9Sstevel@tonic-gate #define	MSGMARKNEXT	0x10	/* Private: first byte of next msg marked */
4007c478bd9Sstevel@tonic-gate #define	MSGNOTMARKNEXT	0x20	/* Private: ... not marked */
4017c478bd9Sstevel@tonic-gate #define	MSGHASREF	0x40	/* Private: message has reference to owner */
4027c478bd9Sstevel@tonic-gate 
4037c478bd9Sstevel@tonic-gate /*
4047c478bd9Sstevel@tonic-gate  * Streams message types.
4057c478bd9Sstevel@tonic-gate  */
4067c478bd9Sstevel@tonic-gate 
4077c478bd9Sstevel@tonic-gate /*
4087c478bd9Sstevel@tonic-gate  * Data and protocol messages (regular and priority)
4097c478bd9Sstevel@tonic-gate  */
4107c478bd9Sstevel@tonic-gate #define	M_DATA		0x00		/* regular data */
4117c478bd9Sstevel@tonic-gate #define	M_PROTO		0x01		/* protocol control */
4127c478bd9Sstevel@tonic-gate #define	M_MULTIDATA	0x02		/* reserved for Multidata use only */
4137c478bd9Sstevel@tonic-gate 
4147c478bd9Sstevel@tonic-gate /*
4157c478bd9Sstevel@tonic-gate  * Control messages (regular and priority)
4167c478bd9Sstevel@tonic-gate  */
4177c478bd9Sstevel@tonic-gate #define	M_BREAK		0x08		/* line break */
4187c478bd9Sstevel@tonic-gate #define	M_PASSFP	0x09		/* pass file pointer */
4197c478bd9Sstevel@tonic-gate #define	M_EVENT		0x0a		/* Obsoleted: do not use */
4207c478bd9Sstevel@tonic-gate #define	M_SIG		0x0b		/* generate process signal */
4217c478bd9Sstevel@tonic-gate #define	M_DELAY		0x0c		/* real-time xmit delay (1 param) */
4227c478bd9Sstevel@tonic-gate #define	M_CTL		0x0d		/* device-specific control message */
4237c478bd9Sstevel@tonic-gate #define	M_IOCTL		0x0e		/* ioctl; set/get params */
4247c478bd9Sstevel@tonic-gate #define	M_SETOPTS	0x10		/* set various stream head options */
4257c478bd9Sstevel@tonic-gate #define	M_RSE		0x11		/* reserved for RSE use only */
4267c478bd9Sstevel@tonic-gate 
4277c478bd9Sstevel@tonic-gate /*
4287c478bd9Sstevel@tonic-gate  * Control messages (high priority; go to head of queue)
4297c478bd9Sstevel@tonic-gate  */
4307c478bd9Sstevel@tonic-gate #define	M_IOCACK	0x81		/* acknowledge ioctl */
4317c478bd9Sstevel@tonic-gate #define	M_IOCNAK	0x82		/* negative ioctl acknowledge */
4327c478bd9Sstevel@tonic-gate #define	M_PCPROTO	0x83		/* priority proto message */
4337c478bd9Sstevel@tonic-gate #define	M_PCSIG		0x84		/* generate process signal */
4347c478bd9Sstevel@tonic-gate #define	M_READ		0x85		/* generate read notification */
4357c478bd9Sstevel@tonic-gate #define	M_FLUSH		0x86		/* flush your queues */
4367c478bd9Sstevel@tonic-gate #define	M_STOP		0x87		/* stop transmission immediately */
4377c478bd9Sstevel@tonic-gate #define	M_START		0x88		/* restart transmission after stop */
4387c478bd9Sstevel@tonic-gate #define	M_HANGUP	0x89		/* line disconnect */
4397c478bd9Sstevel@tonic-gate #define	M_ERROR		0x8a		/* send error to stream head */
4407c478bd9Sstevel@tonic-gate #define	M_COPYIN	0x8b		/* request to copyin data */
4417c478bd9Sstevel@tonic-gate #define	M_COPYOUT	0x8c		/* request to copyout data */
4427c478bd9Sstevel@tonic-gate #define	M_IOCDATA	0x8d		/* response to M_COPYIN and M_COPYOUT */
4437c478bd9Sstevel@tonic-gate #define	M_PCRSE		0x8e		/* reserved for RSE use only */
4447c478bd9Sstevel@tonic-gate #define	M_STOPI		0x8f		/* stop reception immediately */
4457c478bd9Sstevel@tonic-gate #define	M_STARTI	0x90		/* restart reception after stop */
4467c478bd9Sstevel@tonic-gate #define	M_PCEVENT	0x91		/* Obsoleted: do not use */
4477c478bd9Sstevel@tonic-gate #define	M_UNHANGUP	0x92		/* line reconnect, sigh */
4487c478bd9Sstevel@tonic-gate 
4497c478bd9Sstevel@tonic-gate /*
4507c478bd9Sstevel@tonic-gate  * Queue message class definitions.
4517c478bd9Sstevel@tonic-gate  */
4527c478bd9Sstevel@tonic-gate #define	QNORM		0x00		/* normal priority messages */
4537c478bd9Sstevel@tonic-gate #define	QPCTL		0x80		/* high priority cntrl messages */
4547c478bd9Sstevel@tonic-gate 
4557c478bd9Sstevel@tonic-gate /*
4567c478bd9Sstevel@tonic-gate  *  IOCTL structure - this structure is the format of the M_IOCTL message type.
4577c478bd9Sstevel@tonic-gate  */
4587c478bd9Sstevel@tonic-gate #if	defined(_LP64)
4597c478bd9Sstevel@tonic-gate struct iocblk {
4607c478bd9Sstevel@tonic-gate 	int 	ioc_cmd;		/* ioctl command type */
4617c478bd9Sstevel@tonic-gate 	cred_t	*ioc_cr;		/* full credentials */
4627c478bd9Sstevel@tonic-gate 	uint_t	ioc_id;			/* ioctl id */
4637c478bd9Sstevel@tonic-gate 	uint_t	ioc_flag;		/* see below */
4647c478bd9Sstevel@tonic-gate 	size_t	ioc_count;		/* count of bytes in data field */
4657c478bd9Sstevel@tonic-gate 	int	ioc_rval;		/* return value  */
4667c478bd9Sstevel@tonic-gate 	int	ioc_error;		/* error code */
4677c478bd9Sstevel@tonic-gate };
4687c478bd9Sstevel@tonic-gate #else
4697c478bd9Sstevel@tonic-gate struct iocblk {
4707c478bd9Sstevel@tonic-gate 	int 	ioc_cmd;		/* ioctl command type */
4717c478bd9Sstevel@tonic-gate 	cred_t	*ioc_cr;		/* full credentials */
4727c478bd9Sstevel@tonic-gate 	uint_t	ioc_id;			/* ioctl id */
4737c478bd9Sstevel@tonic-gate 	size_t	ioc_count;		/* count of bytes in data field */
4747c478bd9Sstevel@tonic-gate 	int	ioc_error;		/* error code */
4757c478bd9Sstevel@tonic-gate 	int	ioc_rval;		/* return value  */
4767c478bd9Sstevel@tonic-gate 	int	ioc_fill1;
4777c478bd9Sstevel@tonic-gate 	uint_t	ioc_flag;		/* see below */
4787c478bd9Sstevel@tonic-gate 	int	ioc_filler[2];		/* reserved for future use */
4797c478bd9Sstevel@tonic-gate };
4807c478bd9Sstevel@tonic-gate #endif	/* _LP64 */
4817c478bd9Sstevel@tonic-gate 
4827c478bd9Sstevel@tonic-gate typedef	struct iocblk	*IOCP;
4837c478bd9Sstevel@tonic-gate 
4847c478bd9Sstevel@tonic-gate /* {ioc,cp}_flags values */
4857c478bd9Sstevel@tonic-gate 
4867c478bd9Sstevel@tonic-gate #define	IOC_MODELS	DATAMODEL_MASK	/* Note: 0x0FF00000 */
4877c478bd9Sstevel@tonic-gate #define	IOC_ILP32	DATAMODEL_ILP32	/* ioctl origin is ILP32 */
4887c478bd9Sstevel@tonic-gate #define	IOC_LP64	DATAMODEL_LP64	/* ioctl origin is LP64 */
4897c478bd9Sstevel@tonic-gate #define	IOC_NATIVE	DATAMODEL_NATIVE
4907c478bd9Sstevel@tonic-gate #define	IOC_NONE	DATAMODEL_NONE	/* dummy comparison value */
4917c478bd9Sstevel@tonic-gate 
4927c478bd9Sstevel@tonic-gate /*
4937c478bd9Sstevel@tonic-gate  *	Is the ioctl data formatted for our native model?
4947c478bd9Sstevel@tonic-gate  */
4957c478bd9Sstevel@tonic-gate #define	IOC_CONVERT_FROM(iocp)	ddi_model_convert_from( \
4967c478bd9Sstevel@tonic-gate 				    ((struct iocblk *)iocp)->ioc_flag)
4977c478bd9Sstevel@tonic-gate 
4987c478bd9Sstevel@tonic-gate /*
4997c478bd9Sstevel@tonic-gate  * structure for the M_COPYIN and M_COPYOUT message types.
5007c478bd9Sstevel@tonic-gate  */
5017c478bd9Sstevel@tonic-gate #if	defined(_LP64)
5027c478bd9Sstevel@tonic-gate struct copyreq {
5037c478bd9Sstevel@tonic-gate 	int	cq_cmd;			/* ioctl command (from ioc_cmd) */
5047c478bd9Sstevel@tonic-gate 	cred_t	*cq_cr;			/* full credentials (from ioc_cmd) */
5057c478bd9Sstevel@tonic-gate 	uint_t	cq_id;			/* ioctl id (from ioc_id) */
5067c478bd9Sstevel@tonic-gate 	uint_t	cq_flag;		/* must be zero */
5077c478bd9Sstevel@tonic-gate 	mblk_t	*cq_private;		/* private state information */
5087c478bd9Sstevel@tonic-gate 	caddr_t	cq_addr;		/* address to copy data to/from */
5097c478bd9Sstevel@tonic-gate 	size_t	cq_size;		/* number of bytes to copy */
5107c478bd9Sstevel@tonic-gate };
5117c478bd9Sstevel@tonic-gate #else
5127c478bd9Sstevel@tonic-gate struct copyreq {
5137c478bd9Sstevel@tonic-gate 	int	cq_cmd;			/* ioctl command (from ioc_cmd) */
5147c478bd9Sstevel@tonic-gate 	cred_t	*cq_cr;			/* full credentials */
5157c478bd9Sstevel@tonic-gate 	uint_t	cq_id;			/* ioctl id (from ioc_id) */
5167c478bd9Sstevel@tonic-gate 	caddr_t	cq_addr;		/* address to copy data to/from */
5177c478bd9Sstevel@tonic-gate 	size_t	cq_size;		/* number of bytes to copy */
5187c478bd9Sstevel@tonic-gate 	uint_t	cq_flag;		/* must be zero */
5197c478bd9Sstevel@tonic-gate 	mblk_t	*cq_private;		/* private state information */
5207c478bd9Sstevel@tonic-gate 	int	cq_filler[4];		/* reserved for future use */
5217c478bd9Sstevel@tonic-gate };
5227c478bd9Sstevel@tonic-gate #endif	/* _LP64 */
5237c478bd9Sstevel@tonic-gate 
5247c478bd9Sstevel@tonic-gate /*
5257c478bd9Sstevel@tonic-gate  * structure for the M_IOCDATA message type.
5267c478bd9Sstevel@tonic-gate  */
5277c478bd9Sstevel@tonic-gate #if	defined(_LP64)
5287c478bd9Sstevel@tonic-gate struct copyresp {
5297c478bd9Sstevel@tonic-gate 	int	cp_cmd;			/* ioctl command (from ioc_cmd) */
5307c478bd9Sstevel@tonic-gate 	cred_t	*cp_cr;			/* full credentials (from ioc_cmd) */
5317c478bd9Sstevel@tonic-gate 	uint_t	cp_id;			/* ioctl id (from ioc_id) */
5327c478bd9Sstevel@tonic-gate 	uint_t	cp_flag;		/* datamodel IOC_ flags; see above */
5337c478bd9Sstevel@tonic-gate 	mblk_t *cp_private;		/* private state information */
5347c478bd9Sstevel@tonic-gate 	caddr_t	cp_rval;		/* status of request: 0 -> success */
5357c478bd9Sstevel@tonic-gate 					/* 		non-zero -> failure */
5367c478bd9Sstevel@tonic-gate };
5377c478bd9Sstevel@tonic-gate #else
5387c478bd9Sstevel@tonic-gate struct copyresp {
5397c478bd9Sstevel@tonic-gate 	int	cp_cmd;			/* ioctl command (from ioc_cmd) */
5407c478bd9Sstevel@tonic-gate 	cred_t	*cp_cr;			/* full credentials */
5417c478bd9Sstevel@tonic-gate 	uint_t	cp_id;			/* ioctl id (from ioc_id) */
5427c478bd9Sstevel@tonic-gate 	caddr_t	cp_rval;		/* status of request: 0 -> success */
5437c478bd9Sstevel@tonic-gate 					/* 		non-zero -> failure */
5447c478bd9Sstevel@tonic-gate 	size_t	cp_pad1;
5457c478bd9Sstevel@tonic-gate 	uint_t	cp_pad2;
5467c478bd9Sstevel@tonic-gate 	mblk_t *cp_private;		/* private state information */
5477c478bd9Sstevel@tonic-gate 	uint_t	cp_flag;		/* datamodel IOC_ flags; see above */
5487c478bd9Sstevel@tonic-gate 	int	cp_filler[3];
5497c478bd9Sstevel@tonic-gate };
5507c478bd9Sstevel@tonic-gate #endif	/* _LP64 */
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate /*
5537c478bd9Sstevel@tonic-gate  * Since these structures are all intended to travel in the same message
5547c478bd9Sstevel@tonic-gate  * at different stages of a STREAMS ioctl, this union is used to determine
5557c478bd9Sstevel@tonic-gate  * the message size in strdoioctl().
5567c478bd9Sstevel@tonic-gate  */
5577c478bd9Sstevel@tonic-gate union ioctypes {
5587c478bd9Sstevel@tonic-gate 	struct iocblk	iocblk;
5597c478bd9Sstevel@tonic-gate 	struct copyreq	copyreq;
5607c478bd9Sstevel@tonic-gate 	struct copyresp	copyresp;
5617c478bd9Sstevel@tonic-gate };
5627c478bd9Sstevel@tonic-gate 
5637c478bd9Sstevel@tonic-gate /*
5647c478bd9Sstevel@tonic-gate  * Options structure for M_SETOPTS message.  This is sent upstream
5657c478bd9Sstevel@tonic-gate  * by a module or driver to set stream head options.
5667c478bd9Sstevel@tonic-gate  */
5677c478bd9Sstevel@tonic-gate 
5687c478bd9Sstevel@tonic-gate struct stroptions {
5697c478bd9Sstevel@tonic-gate 	uint_t	so_flags;		/* options to set */
5707c478bd9Sstevel@tonic-gate 	short	so_readopt;		/* read option */
5717c478bd9Sstevel@tonic-gate 	ushort_t so_wroff;		/* write offset */
5727c478bd9Sstevel@tonic-gate 	ssize_t	so_minpsz;		/* minimum read packet size */
5737c478bd9Sstevel@tonic-gate 	ssize_t	so_maxpsz;		/* maximum read packet size */
5747c478bd9Sstevel@tonic-gate 	size_t	so_hiwat;		/* read queue high water mark */
5757c478bd9Sstevel@tonic-gate 	size_t	so_lowat;		/* read queue low water mark */
5767c478bd9Sstevel@tonic-gate 	unsigned char so_band;		/* band for water marks */
5777c478bd9Sstevel@tonic-gate 	ushort_t so_erropt;		/* error option */
5787c478bd9Sstevel@tonic-gate 	ssize_t	so_maxblk;		/* maximum message block size */
5797c478bd9Sstevel@tonic-gate 	ushort_t so_copyopt;		/* copy options (see stropts.h) */
5807c478bd9Sstevel@tonic-gate };
5817c478bd9Sstevel@tonic-gate 
5827c478bd9Sstevel@tonic-gate /* flags for stream options set message */
5837c478bd9Sstevel@tonic-gate 
5847c478bd9Sstevel@tonic-gate #define	SO_ALL		0x003f	/* set all old options */
5857c478bd9Sstevel@tonic-gate #define	SO_READOPT	0x0001	/* set read option */
5867c478bd9Sstevel@tonic-gate #define	SO_WROFF	0x0002	/* set write offset */
5877c478bd9Sstevel@tonic-gate #define	SO_MINPSZ	0x0004	/* set min packet size */
5887c478bd9Sstevel@tonic-gate #define	SO_MAXPSZ	0x0008	/* set max packet size */
5897c478bd9Sstevel@tonic-gate #define	SO_HIWAT	0x0010	/* set high water mark */
5907c478bd9Sstevel@tonic-gate #define	SO_LOWAT	0x0020	/* set low water mark */
5917c478bd9Sstevel@tonic-gate #define	SO_MREADON	0x0040	/* set read notification ON */
5927c478bd9Sstevel@tonic-gate #define	SO_MREADOFF	0x0080	/* set read notification OFF */
5937c478bd9Sstevel@tonic-gate #define	SO_NDELON	0x0100	/* old TTY semantics for NDELAY reads/writes */
5947c478bd9Sstevel@tonic-gate #define	SO_NDELOFF	0x0200	/* STREAMS semantics for NDELAY reads/writes */
5957c478bd9Sstevel@tonic-gate #define	SO_ISTTY	0x0400	/* the stream is acting as a terminal */
5967c478bd9Sstevel@tonic-gate #define	SO_ISNTTY	0x0800	/* the stream is not acting as a terminal */
5977c478bd9Sstevel@tonic-gate #define	SO_TOSTOP	0x1000	/* stop on background writes to this stream */
5987c478bd9Sstevel@tonic-gate #define	SO_TONSTOP	0x2000	/* do not stop on background writes to stream */
5997c478bd9Sstevel@tonic-gate #define	SO_BAND		0x4000	/* water marks affect band */
6007c478bd9Sstevel@tonic-gate #define	SO_DELIM	0x8000	/* messages are delimited */
6017c478bd9Sstevel@tonic-gate #define	SO_NODELIM	0x010000	/* turn off delimiters */
6027c478bd9Sstevel@tonic-gate #define	SO_STRHOLD	0x020000	/* No longer implemented */
6037c478bd9Sstevel@tonic-gate #define	SO_ERROPT	0x040000	/* set error option */
6047c478bd9Sstevel@tonic-gate #define	SO_COPYOPT	0x080000	/* copy option(s) present */
6057c478bd9Sstevel@tonic-gate #define	SO_MAXBLK	0x100000	/* set maximum message block size */
6067c478bd9Sstevel@tonic-gate 
6077c478bd9Sstevel@tonic-gate #ifdef _KERNEL
6087c478bd9Sstevel@tonic-gate /*
6097c478bd9Sstevel@tonic-gate  * Structure for rw (read/write) procedure calls. A pointer
6107c478bd9Sstevel@tonic-gate  * to a struiod_t is passed as a parameter to the rwnext() call.
6117c478bd9Sstevel@tonic-gate  *
6127c478bd9Sstevel@tonic-gate  * Note: DEF_IOV_MAX is defined and used as it is in "fs/vncalls.c"
6137c478bd9Sstevel@tonic-gate  *	 as there isn't a formal definition of IOV_MAX ???
6147c478bd9Sstevel@tonic-gate  */
6157c478bd9Sstevel@tonic-gate #define	DEF_IOV_MAX	16
6167c478bd9Sstevel@tonic-gate 
6177c478bd9Sstevel@tonic-gate typedef struct struiod {
6187c478bd9Sstevel@tonic-gate 	mblk_t		*d_mp;		/* pointer to mblk (chain) */
6197c478bd9Sstevel@tonic-gate 	uio_t		d_uio;		/* uio info */
6207c478bd9Sstevel@tonic-gate 	iovec_t d_iov[DEF_IOV_MAX];	/* iov referenced by uio */
6217c478bd9Sstevel@tonic-gate } struiod_t;
6227c478bd9Sstevel@tonic-gate 
6237c478bd9Sstevel@tonic-gate /*
6247c478bd9Sstevel@tonic-gate  * Structure for information procedure calls.
6257c478bd9Sstevel@tonic-gate  */
6267c478bd9Sstevel@tonic-gate typedef struct infod {
6277c478bd9Sstevel@tonic-gate 	unsigned char	d_cmd;		/* info info request command */
6287c478bd9Sstevel@tonic-gate 	unsigned char	d_res;		/* info info command results */
6297c478bd9Sstevel@tonic-gate 	int		d_bytes;	/* mblk(s) byte count */
6307c478bd9Sstevel@tonic-gate 	int		d_count;	/* count of mblk(s) */
6317c478bd9Sstevel@tonic-gate 	uio_t		*d_uiop;	/* pointer to uio struct */
6327c478bd9Sstevel@tonic-gate } infod_t;
6337c478bd9Sstevel@tonic-gate /*
6347c478bd9Sstevel@tonic-gate  * Values for d_cmd & d_res.
6357c478bd9Sstevel@tonic-gate  */
6367c478bd9Sstevel@tonic-gate #define	INFOD_FIRSTBYTES	0x02	/* return msgbsize() of first mblk */
6377c478bd9Sstevel@tonic-gate #define	INFOD_BYTES		0x04	/* return msgbsize() of all mblk(s) */
6387c478bd9Sstevel@tonic-gate #define	INFOD_COUNT		0x08	/* return count of mblk(s) */
6397c478bd9Sstevel@tonic-gate #define	INFOD_COPYOUT		0x10	/* copyout any M_DATA mblk(s) */
6407c478bd9Sstevel@tonic-gate 
6417c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
6427c478bd9Sstevel@tonic-gate 
6437c478bd9Sstevel@tonic-gate /*
6447c478bd9Sstevel@tonic-gate  * Miscellaneous parameters and flags.
6457c478bd9Sstevel@tonic-gate  */
6467c478bd9Sstevel@tonic-gate 
6477c478bd9Sstevel@tonic-gate /*
6487c478bd9Sstevel@tonic-gate  * Values for stream flag in open to indicate module open, clone open,
6497c478bd9Sstevel@tonic-gate  * and the return value for failure.
6507c478bd9Sstevel@tonic-gate  */
6517c478bd9Sstevel@tonic-gate #define	MODOPEN 	0x1		/* open as a module */
6527c478bd9Sstevel@tonic-gate #define	CLONEOPEN	0x2		/* clone open; pick own minor dev */
6537c478bd9Sstevel@tonic-gate #define	OPENFAIL	-1		/* returned for open failure */
6547c478bd9Sstevel@tonic-gate 
6557c478bd9Sstevel@tonic-gate /*
6567c478bd9Sstevel@tonic-gate  * Priority definitions for block allocation.
6577c478bd9Sstevel@tonic-gate  */
6587c478bd9Sstevel@tonic-gate #define	BPRI_LO		1
6597c478bd9Sstevel@tonic-gate #define	BPRI_MED	2
6607c478bd9Sstevel@tonic-gate #define	BPRI_HI		3
6617c478bd9Sstevel@tonic-gate 
6627c478bd9Sstevel@tonic-gate /*
6637c478bd9Sstevel@tonic-gate  * Value for packet size that denotes infinity
6647c478bd9Sstevel@tonic-gate  */
6657c478bd9Sstevel@tonic-gate #define	INFPSZ		-1
6667c478bd9Sstevel@tonic-gate 
6677c478bd9Sstevel@tonic-gate /*
6687c478bd9Sstevel@tonic-gate  * Flags for flushq()
6697c478bd9Sstevel@tonic-gate  */
6707c478bd9Sstevel@tonic-gate #define	FLUSHALL	1	/* flush all messages */
6717c478bd9Sstevel@tonic-gate #define	FLUSHDATA	0	/* don't flush control messages */
6727c478bd9Sstevel@tonic-gate 
6737c478bd9Sstevel@tonic-gate /*
6747c478bd9Sstevel@tonic-gate  * Flag for transparent ioctls
6757c478bd9Sstevel@tonic-gate  */
6767c478bd9Sstevel@tonic-gate #define	TRANSPARENT	(unsigned int)(-1)
6777c478bd9Sstevel@tonic-gate 
6787c478bd9Sstevel@tonic-gate /*
6797c478bd9Sstevel@tonic-gate  * Stream head default high/low water marks
6807c478bd9Sstevel@tonic-gate  */
6817c478bd9Sstevel@tonic-gate #define	STRHIGH 5120
6827c478bd9Sstevel@tonic-gate #define	STRLOW	1024
6837c478bd9Sstevel@tonic-gate 
6847c478bd9Sstevel@tonic-gate /*
6857c478bd9Sstevel@tonic-gate  * Block allocation parameters
6867c478bd9Sstevel@tonic-gate  */
6877c478bd9Sstevel@tonic-gate #define	MAXIOCBSZ	1024		/* max ioctl data block size */
6887c478bd9Sstevel@tonic-gate 
6897c478bd9Sstevel@tonic-gate /*
6907c478bd9Sstevel@tonic-gate  * qwriter perimeter types
6917c478bd9Sstevel@tonic-gate  */
6927c478bd9Sstevel@tonic-gate #define	PERIM_INNER	1		/* The inner perimeter */
6937c478bd9Sstevel@tonic-gate #define	PERIM_OUTER	2		/* The outer perimeter */
6947c478bd9Sstevel@tonic-gate 
6957c478bd9Sstevel@tonic-gate /*
6967c478bd9Sstevel@tonic-gate  * Definitions of Streams macros and function interfaces.
6977c478bd9Sstevel@tonic-gate  */
6987c478bd9Sstevel@tonic-gate 
6997c478bd9Sstevel@tonic-gate /*
7007c478bd9Sstevel@tonic-gate  * canenable - check if queue can be enabled by putq().
7017c478bd9Sstevel@tonic-gate  */
7027c478bd9Sstevel@tonic-gate #define	canenable(q)	!((q)->q_flag & QNOENB)
7037c478bd9Sstevel@tonic-gate 
7047c478bd9Sstevel@tonic-gate /*
7057c478bd9Sstevel@tonic-gate  * Test if data block type is one of the data messages (i.e. not a control
7067c478bd9Sstevel@tonic-gate  * message).
7077c478bd9Sstevel@tonic-gate  */
7087c478bd9Sstevel@tonic-gate #define	datamsg(type) \
7097c478bd9Sstevel@tonic-gate 		((type) == M_DATA || \
7107c478bd9Sstevel@tonic-gate 		    (type) == M_MULTIDATA || \
7117c478bd9Sstevel@tonic-gate 		    (type) == M_PROTO || \
7127c478bd9Sstevel@tonic-gate 		    (type) == M_PCPROTO || \
7137c478bd9Sstevel@tonic-gate 		    (type) == M_DELAY)
7147c478bd9Sstevel@tonic-gate 
7157c478bd9Sstevel@tonic-gate /*
7167c478bd9Sstevel@tonic-gate  * Extract queue class of message block.
7177c478bd9Sstevel@tonic-gate  */
7187c478bd9Sstevel@tonic-gate #define	queclass(bp) (((bp)->b_datap->db_type >= QPCTL) ? QPCTL : QNORM)
7197c478bd9Sstevel@tonic-gate 
7207c478bd9Sstevel@tonic-gate /*
7217c478bd9Sstevel@tonic-gate  * Align address on next lower word boundary.
7227c478bd9Sstevel@tonic-gate  */
7237c478bd9Sstevel@tonic-gate #define	straln(a)	(caddr_t)((intptr_t)(a) & -(sizeof (int)-1))
7247c478bd9Sstevel@tonic-gate 
7257c478bd9Sstevel@tonic-gate /*
7267c478bd9Sstevel@tonic-gate  * Find the max size of data block.
7277c478bd9Sstevel@tonic-gate  */
7287c478bd9Sstevel@tonic-gate #define	bpsize(bp) ((unsigned int)(bp->b_datap->db_lim - bp->b_datap->db_base))
7297c478bd9Sstevel@tonic-gate 
7307c478bd9Sstevel@tonic-gate #ifdef _KERNEL
7317c478bd9Sstevel@tonic-gate 
7327c478bd9Sstevel@tonic-gate /*
7337c478bd9Sstevel@tonic-gate  * For two-byte M_ERROR messages: indication that a side does not have an error
7347c478bd9Sstevel@tonic-gate  */
7357c478bd9Sstevel@tonic-gate #define	NOERROR	((unsigned char)-1)
7367c478bd9Sstevel@tonic-gate 
7377c478bd9Sstevel@tonic-gate /*
7387c478bd9Sstevel@tonic-gate  * declarations of common routines
7397c478bd9Sstevel@tonic-gate  */
7407c478bd9Sstevel@tonic-gate 
7417c478bd9Sstevel@tonic-gate extern mblk_t *allocb(size_t, uint_t);
742bd118333Smeem extern mblk_t *desballoc(unsigned char *, size_t, uint_t, frtn_t *);
7437c478bd9Sstevel@tonic-gate extern mblk_t *esballoc(unsigned char *, size_t, uint_t, frtn_t *);
7447c478bd9Sstevel@tonic-gate extern bcache_t *bcache_create(char *, size_t, uint_t);
7457c478bd9Sstevel@tonic-gate extern void bcache_destroy(bcache_t *);
7467c478bd9Sstevel@tonic-gate extern mblk_t *bcache_allocb(bcache_t *, uint_t);
7477c478bd9Sstevel@tonic-gate extern mblk_t *mkiocb(uint_t);
7487c478bd9Sstevel@tonic-gate extern int testb(size_t, uint_t);
7497c478bd9Sstevel@tonic-gate extern bufcall_id_t bufcall(size_t, uint_t, void (*)(void *), void *);
7507c478bd9Sstevel@tonic-gate extern bufcall_id_t esbbcall(uint_t, void (*)(void *), void *);
7517c478bd9Sstevel@tonic-gate extern void freeb(struct msgb *);
7527c478bd9Sstevel@tonic-gate extern void freemsg(mblk_t *);
7537c478bd9Sstevel@tonic-gate extern mblk_t *dupb(mblk_t *);
7547c478bd9Sstevel@tonic-gate extern mblk_t *dupmsg(mblk_t *);
7557c478bd9Sstevel@tonic-gate extern mblk_t *dupmsg_noloan(mblk_t *);
7567c478bd9Sstevel@tonic-gate extern mblk_t *copyb(mblk_t *);
7577c478bd9Sstevel@tonic-gate extern mblk_t *copymsg(mblk_t *);
7587c478bd9Sstevel@tonic-gate extern void linkb(mblk_t *, mblk_t *);
7597c478bd9Sstevel@tonic-gate extern mblk_t *unlinkb(mblk_t *);
7607c478bd9Sstevel@tonic-gate extern mblk_t *reallocb(mblk_t *, size_t, uint_t);	/* private */
7617c478bd9Sstevel@tonic-gate extern mblk_t *rmvb(mblk_t *, mblk_t *);
7627c478bd9Sstevel@tonic-gate extern int pullupmsg(struct msgb *, ssize_t);
7637c478bd9Sstevel@tonic-gate extern mblk_t *msgpullup(struct msgb *, ssize_t);
7647c478bd9Sstevel@tonic-gate extern int adjmsg(struct msgb *, ssize_t);
7657c478bd9Sstevel@tonic-gate extern size_t msgdsize(struct msgb *);
7667c478bd9Sstevel@tonic-gate extern mblk_t *getq(queue_t *);
7677c478bd9Sstevel@tonic-gate extern void rmvq(queue_t *, mblk_t *);
7687c478bd9Sstevel@tonic-gate extern void flushq(queue_t *, int);
7697c478bd9Sstevel@tonic-gate extern void flushq_common(queue_t *, int, int);
7707c478bd9Sstevel@tonic-gate extern void flushband(queue_t *, unsigned char, int);
7717c478bd9Sstevel@tonic-gate extern int canput(queue_t *);
7727c478bd9Sstevel@tonic-gate extern int bcanput(queue_t *, unsigned char);
7737c478bd9Sstevel@tonic-gate extern int canputnext(queue_t *);
7747c478bd9Sstevel@tonic-gate extern int bcanputnext(queue_t *, unsigned char);
7757c478bd9Sstevel@tonic-gate extern int putq(queue_t *, mblk_t *);
7767c478bd9Sstevel@tonic-gate extern int putbq(queue_t *, mblk_t *);
7777c478bd9Sstevel@tonic-gate extern int insq(queue_t *, mblk_t *, mblk_t *);
7787c478bd9Sstevel@tonic-gate extern void put(queue_t *, mblk_t *);
7797c478bd9Sstevel@tonic-gate extern void putnext(queue_t *, mblk_t *);
7807c478bd9Sstevel@tonic-gate extern int putctl(queue_t *, int);
7817c478bd9Sstevel@tonic-gate extern int putctl1(queue_t *, int, int);
7827c478bd9Sstevel@tonic-gate extern int putnextctl(queue_t *, int);
7837c478bd9Sstevel@tonic-gate extern int putnextctl1(queue_t *, int, int);
7847c478bd9Sstevel@tonic-gate extern queue_t *backq(queue_t *);
7857c478bd9Sstevel@tonic-gate extern void qreply(queue_t *, mblk_t *);
7867c478bd9Sstevel@tonic-gate extern void qenable(queue_t *);
7877c478bd9Sstevel@tonic-gate extern int qsize(queue_t *);
7887c478bd9Sstevel@tonic-gate extern void noenable(queue_t *);
7897c478bd9Sstevel@tonic-gate extern void enableok(queue_t *);
7907c478bd9Sstevel@tonic-gate extern int strqset(queue_t *, qfields_t, unsigned char, intptr_t);
7917c478bd9Sstevel@tonic-gate extern int strqget(queue_t *, qfields_t, unsigned char, void *);
7927c478bd9Sstevel@tonic-gate extern void unbufcall(bufcall_id_t);
7937c478bd9Sstevel@tonic-gate extern void qprocson(queue_t *);
7947c478bd9Sstevel@tonic-gate extern void qprocsoff(queue_t *);
7957c478bd9Sstevel@tonic-gate extern void freezestr(queue_t *);
7967c478bd9Sstevel@tonic-gate extern void unfreezestr(queue_t *);
7977c478bd9Sstevel@tonic-gate extern void qwait(queue_t *);
7987c478bd9Sstevel@tonic-gate extern int qwait_sig(queue_t *);
7997c478bd9Sstevel@tonic-gate extern boolean_t qwait_rw(queue_t *);
8007c478bd9Sstevel@tonic-gate extern void qwriter(queue_t *, mblk_t *, void (*func)(), int);
8017c478bd9Sstevel@tonic-gate extern timeout_id_t qtimeout(queue_t *, void (*func)(void *), void *, clock_t);
8027c478bd9Sstevel@tonic-gate extern bufcall_id_t qbufcall(queue_t *, size_t, uint_t,
8037c478bd9Sstevel@tonic-gate     void (*)(void *), void *);
8047c478bd9Sstevel@tonic-gate extern clock_t quntimeout(queue_t *, timeout_id_t);
8057c478bd9Sstevel@tonic-gate extern void qunbufcall(queue_t *, bufcall_id_t);
8067c478bd9Sstevel@tonic-gate extern void strwakeq(queue_t *, int);
8077c478bd9Sstevel@tonic-gate extern int struioget(queue_t *, mblk_t *, struiod_t *, int);
8087c478bd9Sstevel@tonic-gate extern int rwnext(queue_t *, struiod_t *);
8097c478bd9Sstevel@tonic-gate extern int infonext(queue_t *, infod_t *);
8107c478bd9Sstevel@tonic-gate extern int isuioq(queue_t *);
8117c478bd9Sstevel@tonic-gate extern void create_putlocks(queue_t *, int);
8127c478bd9Sstevel@tonic-gate 
8137c478bd9Sstevel@tonic-gate /*
8147c478bd9Sstevel@tonic-gate  * shared or externally configured data structures
8157c478bd9Sstevel@tonic-gate  */
8167c478bd9Sstevel@tonic-gate extern int nstrpush;			/* maximum number of pushes allowed */
8177c478bd9Sstevel@tonic-gate 
8187c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
8197c478bd9Sstevel@tonic-gate 
8207c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
8217c478bd9Sstevel@tonic-gate }
8227c478bd9Sstevel@tonic-gate #endif
8237c478bd9Sstevel@tonic-gate 
8247c478bd9Sstevel@tonic-gate #endif	/* _SYS_STREAM_H */
825