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