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