xref: /titanic_51/usr/src/uts/common/sys/stream.h (revision fa9e4066f08beec538e775443c5be79dd423fcab)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 
31 #ifndef _SYS_STREAM_H
32 #define	_SYS_STREAM_H
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 11.44	*/
35 
36 /*
37  * For source compatibility
38  */
39 #include <sys/isa_defs.h>
40 #include <sys/vnode.h>
41 #include <sys/poll.h>
42 #include <sys/strmdep.h>
43 #include <sys/cred.h>
44 #include <sys/t_lock.h>
45 #include <sys/model.h>
46 #include <sys/strft.h>
47 
48 #ifdef	__cplusplus
49 extern "C" {
50 #endif
51 
52 /*
53  * Both the queue and the data block structures have embedded
54  * mutexes: q_lock and db_lock.  In general, these mutexes protect
55  * the consistency of the data structure.  In addition, q_lock
56  * is used, with the stream head condition variable, to implement
57  * a monitor at the stream head for blocking reads and writes.
58  * Neither of these locks should be acquired by module or driver code.
59  *
60  * In particular, q_lock protects the following fields:
61  *	q_first
62  *	q_last
63  *	q_link
64  *	q_count
65  *	q_bandp
66  *	q_nband
67  *
68  * q_next is protected by stream head locking; this links the
69  * stream together, and should be thought of as part of the stream
70  * data structure, not the queue.
71  *
72  * The remaining fields are either modified only by the allocator,
73  * which has exclusive access to them at that time, or are not to
74  * be touched by anything but the MT synchronization primitives
75  * (i.e. q_wait).
76  *
77  * q_sqnext and q_sqprev are special - they are protected by
78  * SQLOCK(q->syncq).
79  */
80 
81 /*
82  * Data queue
83  */
84 typedef struct	queue {
85 	struct	qinit	*q_qinfo;	/* procs and limits for queue	*/
86 	struct	msgb	*q_first;	/* first data block		*/
87 	struct	msgb	*q_last;	/* last data block		*/
88 	struct	queue	*q_next;	/* Q of next stream		*/
89 	struct	queue	*q_link;	/* to next Q for scheduling	*/
90 	void		*q_ptr;		/* to private data structure	*/
91 	size_t		q_count;	/* number of bytes on Q		*/
92 	uint_t		q_flag;		/* queue state			*/
93 	ssize_t		q_minpsz;	/* min packet size accepted by	*/
94 					/* this module			*/
95 	ssize_t		q_maxpsz;	/* max packet size accepted by	*/
96 					/* this module			*/
97 	size_t		q_hiwat;	/* queue high water mark	*/
98 	size_t		q_lowat;	/* queue low water mark		*/
99 	struct qband	*q_bandp;	/* separate flow information */
100 	kmutex_t	q_lock;		/* protect data queue		*/
101 	struct stdata 	*q_stream;	/* for head locks		*/
102 	struct	syncq	*q_syncq;	/* sync queue object		*/
103 	unsigned char	q_nband;	/* number of priority bands > 0	*/
104 	kcondvar_t	q_wait;		/* read/write sleeps		*/
105 	struct	queue	*q_nfsrv;	/* next q fwd with service routine */
106 	ushort_t	q_draining;	/* protected by QLOCK - drain_syncq */
107 	short		q_struiot;	/* stream uio type for struio()	*/
108 	uint_t		q_syncqmsgs;	/* messages in syncq for this queue */
109 	size_t		q_mblkcnt;	/* mblk counter for runaway msgs */
110 	/*
111 	 * Syncq scheduling.
112 	 * These fields are initially protected by the SQLOCK,
113 	 * but they will eventually be protected by the QLOCK.
114 	 * The lock ordering is QLOCK then SQLOCK.
115 	 * Note that  q_syncqmsgs can either disappear, or be an additional
116 	 * count of messages instead of bytes (need bytes for QFULL).
117 	 */
118 	struct msgb	*q_sqhead;	/* first syncq message		*/
119 	struct msgb	*q_sqtail;	/* last syncq message		*/
120 	uint_t		q_sqflags;	/* Queue flags, protected by SQLOCK */
121 	size_t		q_rwcnt;	/* Number of threads synchronously */
122 					/* entering Q */
123 
124 	/*
125 	 * These fields need to be protected by the SQLOCK since
126 	 * the corresponding syncq fields are (sq_head/sq_tail).
127 	 */
128 	struct queue	*q_sqnext;	/* Next Q on syncq list		*/
129 	struct queue	*q_sqprev;	/* Previous Q on syncq list	*/
130 	clock_t		q_sqtstamp;	/* Time when Q was scheduled for sq */
131 	clock_t		q_qtstamp;	/* Time when Q was enabled	*/
132 	pri_t		q_spri;		/* Scheduling priority		*/
133 
134 	/*
135 	 * Reference to the queue's module's implementation structure. This
136 	 * will be NULL for queues associated with drivers.
137 	 */
138 	struct fmodsw_impl	*q_fp;
139 } queue_t;
140 
141 /*
142  * Queue flags; unused flags not documented in queue(9S) can be recycled.
143  */
144 #define	QENAB		0x00000001	/* Queue is already enabled to run */
145 #define	QWANTR		0x00000002	/* Someone wants to read Q	*/
146 #define	QWANTW		0x00000004	/* Someone wants to write Q	*/
147 #define	QFULL		0x00000008	/* Q is considered full		*/
148 #define	QREADR		0x00000010	/* This is the reader (first) Q	*/
149 #define	QUSE		0x00000020	/* This queue in use (allocation) */
150 #define	QNOENB		0x00000040	/* Don't enable Q via putq	*/
151 #define	QWANTRMQSYNC	0x00000080	/* Want to remove sync stream Q */
152 #define	QBACK		0x00000100	/* queue has been back-enabled	*/
153 /*	UNUSED		0x00000200	   was QHLIST			*/
154 /* 	UNUSED 		0x00000400	   was QUNSAFE			*/
155 #define	QPAIR		0x00000800	/* per queue-pair syncq		*/
156 #define	QPERQ 		0x00001000	/* per queue-instance syncq	*/
157 #define	QPERMOD		0x00002000	/* per module syncq		*/
158 #define	QMTSAFE		0x00004000	/* stream module is MT-safe	*/
159 #define	QMTOUTPERIM	0x00008000	/* Has outer perimeter		*/
160 #define	QMT_TYPEMASK	(QPAIR|QPERQ|QPERMOD|QMTSAFE|QMTOUTPERIM)
161 					/* all MT type flags		*/
162 #define	QINSERVICE	0x00010000	/* service routine executing	*/
163 #define	QWCLOSE		0x00020000	/* will not be enabled		*/
164 #define	QEND		0x00040000	/* last queue in stream		*/
165 #define	QWANTWSYNC	0x00080000	/* Streamhead wants to write Q	*/
166 #define	QSYNCSTR	0x00100000	/* Q supports Synchronous STREAMS */
167 #define	QISDRV		0x00200000	/* the Queue is attached to a driver */
168 /*	UNUSED		0x00400000	   was QHOT			*/
169 /*	UNUSED		0x00800000	   was QNEXTHOT			*/
170 /* 	UNUSED		0x01000000	   was _QNEXTLESS		*/
171 #define	_QINSERTING	0x04000000	/* Private, module is being inserted */
172 #define	_QREMOVING	0x08000000	/* Private, module is being removed */
173 #define	_QASSOCIATED	0x10000000	/* queue is associated with a device */
174 #define	_QDIRECT	0x20000000	/* Private; transport module uses */
175 					/* direct interface to/from sockfs */
176 
177 /* queue sqflags (protected by SQLOCK). */
178 #define	Q_SQQUEUED	0x01		/* Queue is in the syncq list */
179 #define	Q_SQDRAINING	0x02		/* Servicing suncq msgs.	*/
180 					/* This is also noted by the	*/
181 					/* q_draining field, but this one is */
182 					/* protected by SQLOCK */
183 
184 /*
185  * Structure that describes the separate information
186  * for each priority band in the queue.
187  */
188 typedef struct qband {
189 	struct qband	*qb_next;	/* next band's info */
190 	size_t		qb_count;	/* number of bytes in band */
191 	struct msgb	*qb_first;	/* beginning of band's data */
192 	struct msgb	*qb_last;	/* end of band's data */
193 	size_t		qb_hiwat;	/* high water mark for band */
194 	size_t		qb_lowat;	/* low water mark for band */
195 	uint_t		qb_flag;	/* see below */
196 	size_t		qb_mblkcnt;	/* mblk counter for runaway msgs */
197 } qband_t;
198 
199 /*
200  * qband flags
201  */
202 #define	QB_FULL		0x01		/* band is considered full */
203 #define	QB_WANTW	0x02		/* Someone wants to write to band */
204 #define	QB_BACK		0x04		/* queue has been back-enabled */
205 
206 /*
207  * Maximum number of bands.
208  */
209 #define	NBAND	256
210 
211 /*
212  * Fields that can be manipulated through strqset() and strqget().
213  */
214 typedef enum qfields {
215 	QHIWAT	= 0,		/* q_hiwat or qb_hiwat */
216 	QLOWAT	= 1,		/* q_lowat or qb_lowat */
217 	QMAXPSZ	= 2,		/* q_maxpsz */
218 	QMINPSZ	= 3,		/* q_minpsz */
219 	QCOUNT	= 4,		/* q_count or qb_count */
220 	QFIRST	= 5,		/* q_first or qb_first */
221 	QLAST	= 6,		/* q_last or qb_last */
222 	QFLAG	= 7,		/* q_flag or qb_flag */
223 	QSTRUIOT = 8,		/* q_struiot */
224 	QBAD	= 9
225 } qfields_t;
226 
227 /*
228  * Module information structure
229  */
230 struct module_info {
231 	ushort_t mi_idnum;		/* module id number */
232 	char 	*mi_idname;		/* module name */
233 	ssize_t	mi_minpsz;		/* min packet size accepted */
234 	ssize_t	mi_maxpsz;		/* max packet size accepted */
235 	size_t	mi_hiwat;		/* hi-water mark */
236 	size_t 	mi_lowat;		/* lo-water mark */
237 };
238 
239 /*
240  * queue information structure (with Synchronous STREAMS extensions)
241  */
242 struct	qinit {
243 	int	(*qi_putp)();		/* put procedure */
244 	int	(*qi_srvp)();		/* service procedure */
245 	int	(*qi_qopen)();		/* called on startup */
246 	int	(*qi_qclose)();		/* called on finish */
247 	int	(*qi_qadmin)();		/* for future use */
248 	struct module_info *qi_minfo;	/* module information structure */
249 	struct module_stat *qi_mstat;	/* module statistics structure */
250 	int	(*qi_rwp)();		/* r/w procedure */
251 	int	(*qi_infop)();		/* information procedure */
252 	int	qi_struiot;		/* stream uio type for struio() */
253 };
254 
255 /*
256  * Values for qi_struiot and q_struiot:
257  */
258 #define	STRUIOT_NONE		-1	/* doesn't support struio() */
259 #define	STRUIOT_DONTCARE	0	/* use current uiomove() (default) */
260 #define	STRUIOT_STANDARD	1	/* use standard uiomove() */
261 
262 /*
263  * Streamtab (used in cdevsw and fmodsw to point to module or driver)
264  */
265 struct streamtab {
266 	struct qinit *st_rdinit;
267 	struct qinit *st_wrinit;
268 	struct qinit *st_muxrinit;
269 	struct qinit *st_muxwinit;
270 };
271 
272 /*
273  * Structure sent to mux drivers to indicate a link.
274  */
275 struct linkblk {
276 	queue_t *l_qtop;	/* lowest level write queue of upper stream */
277 				/* (set to NULL for persistent links) */
278 	queue_t *l_qbot;	/* highest level write queue of lower stream */
279 	int	l_index;	/* index for lower stream. */
280 };
281 
282 /*
283  * Esballoc data buffer freeing routine
284  */
285 typedef struct free_rtn {
286 	void	(*free_func)();
287 	caddr_t	free_arg;
288 } frtn_t;
289 
290 /*
291  * Data block descriptor
292  *
293  * NOTE: db_base, db_lim, db_ref and db_type are the *only* public fields,
294  * as described in datab(9S).  Everything else is implementation-private.
295  */
296 
297 #define	DBLK_REFMAX	255U
298 
299 typedef struct datab {
300 	frtn_t		*db_frtnp;
301 	unsigned char	*db_base;
302 	unsigned char	*db_lim;
303 	unsigned char	db_ref;
304 	unsigned char	db_type;
305 	unsigned char	db_flags;
306 	unsigned char	db_struioflag;
307 	pid_t		db_cpid;	/* cached pid, needs verification */
308 	void		*db_cache;	/* kmem cache descriptor */
309 	struct msgb	*db_mblk;
310 	void		(*db_free)(struct msgb *, struct datab *);
311 	void		(*db_lastfree)(struct msgb *, struct datab *);
312 	intptr_t	db_cksumstart;
313 	intptr_t	db_cksumend;
314 	intptr_t	db_cksumstuff;
315 	union {
316 		double enforce_alignment;
317 		unsigned char data[8];
318 		struct {
319 			union {
320 				uint32_t u32;
321 				uint16_t u16;
322 			} cksum_val;    /* used to store calculated cksum */
323 			uint16_t flags;
324 			uint16_t pad;
325 		} cksum;
326 		/*
327 		 * Union used for future extensions (pointer to data ?).
328 		 */
329 	} db_struioun;
330 	fthdr_t		*db_fthdr;
331 	cred_t		*db_credp;	/* credential */
332 } dblk_t;
333 
334 #define	db_cksum16	db_struioun.cksum.cksum_val.u16
335 #define	db_cksum32	db_struioun.cksum.cksum_val.u32
336 
337 /*
338  * Accessor macros for private dblk_t fields (the rest are in <sys/strsun.h>).
339  */
340 #define	DB_CPID(mp)		((mp)->b_datap->db_cpid)
341 #define	DB_CRED(mp)		((mp)->b_datap->db_credp)
342 #define	DB_CREDDEF(mp, cr)	(DB_CRED(mp) != NULL ? DB_CRED(mp) : (cr))
343 #define	DB_FTHDR(mp)		((mp)->b_datap->db_fthdr)
344 
345 /*
346  * Message block descriptor
347  */
348 typedef struct	msgb {
349 	struct	msgb	*b_next;
350 	struct  msgb	*b_prev;
351 	struct	msgb	*b_cont;
352 	unsigned char	*b_rptr;
353 	unsigned char	*b_wptr;
354 	struct datab 	*b_datap;
355 	unsigned char	b_band;
356 	unsigned char	b_tag;
357 	unsigned short	b_flag;
358 	queue_t		*b_queue;	/* for sync queues */
359 } mblk_t;
360 
361 /*
362  * bcache descriptor
363  */
364 
365 typedef	struct	bcache {
366 	kmutex_t		mutex;
367 	struct kmem_cache	*buffer_cache;
368 	struct kmem_cache	*dblk_cache;
369 	int			alloc;
370 	int			destroy;
371 	size_t			size;
372 	uint_t			align;
373 } bcache_t;
374 
375 /*
376  * db_flags values (all implementation private!)
377  */
378 #define	DBLK_REFMIN	0x01		/* min refcnt stored in low bit */
379 
380 /*
381  * db_struioflag values:
382  */
383 #define	STRUIO_SPEC	0x01	/* struio{get,put}() special mblk */
384 #define	STRUIO_DONE	0x02	/* struio done (could be partial) */
385 #define	STRUIO_IP	0x04	/* IP checksum stored in db_struioun */
386 #define	STRUIO_ZC	0x08	/* mblk eligible for zero-copy */
387 #define	STRUIO_ZCNOTIFY	0x10	/* notify stream head when mblk acked */
388 #define	STRUIO_EAGER	0x20	/* new eager; db_cksumstart has squeue to use */
389 #define	STRUIO_POLICY	0x40	/* new eager when IPsec is enabled */
390 
391 /*
392  * Message flags.  These are interpreted by the stream head.
393  */
394 #define	MSGMARK		0x01	/* last byte of message is "marked" */
395 #define	MSGNOLOOP	0x02	/* don't loop message around to */
396 				/* write side of stream */
397 #define	MSGDELIM	0x04	/* message is delimited */
398 /*	UNUSED		0x08	   was MSGNOGET (can be recycled) */
399 #define	MSGMARKNEXT	0x10	/* Private: first byte of next msg marked */
400 #define	MSGNOTMARKNEXT	0x20	/* Private: ... not marked */
401 #define	MSGHASREF	0x40	/* Private: message has reference to owner */
402 
403 /*
404  * Streams message types.
405  */
406 
407 /*
408  * Data and protocol messages (regular and priority)
409  */
410 #define	M_DATA		0x00		/* regular data */
411 #define	M_PROTO		0x01		/* protocol control */
412 #define	M_MULTIDATA	0x02		/* reserved for Multidata use only */
413 
414 /*
415  * Control messages (regular and priority)
416  */
417 #define	M_BREAK		0x08		/* line break */
418 #define	M_PASSFP	0x09		/* pass file pointer */
419 #define	M_EVENT		0x0a		/* Obsoleted: do not use */
420 #define	M_SIG		0x0b		/* generate process signal */
421 #define	M_DELAY		0x0c		/* real-time xmit delay (1 param) */
422 #define	M_CTL		0x0d		/* device-specific control message */
423 #define	M_IOCTL		0x0e		/* ioctl; set/get params */
424 #define	M_SETOPTS	0x10		/* set various stream head options */
425 #define	M_RSE		0x11		/* reserved for RSE use only */
426 
427 /*
428  * Control messages (high priority; go to head of queue)
429  */
430 #define	M_IOCACK	0x81		/* acknowledge ioctl */
431 #define	M_IOCNAK	0x82		/* negative ioctl acknowledge */
432 #define	M_PCPROTO	0x83		/* priority proto message */
433 #define	M_PCSIG		0x84		/* generate process signal */
434 #define	M_READ		0x85		/* generate read notification */
435 #define	M_FLUSH		0x86		/* flush your queues */
436 #define	M_STOP		0x87		/* stop transmission immediately */
437 #define	M_START		0x88		/* restart transmission after stop */
438 #define	M_HANGUP	0x89		/* line disconnect */
439 #define	M_ERROR		0x8a		/* send error to stream head */
440 #define	M_COPYIN	0x8b		/* request to copyin data */
441 #define	M_COPYOUT	0x8c		/* request to copyout data */
442 #define	M_IOCDATA	0x8d		/* response to M_COPYIN and M_COPYOUT */
443 #define	M_PCRSE		0x8e		/* reserved for RSE use only */
444 #define	M_STOPI		0x8f		/* stop reception immediately */
445 #define	M_STARTI	0x90		/* restart reception after stop */
446 #define	M_PCEVENT	0x91		/* Obsoleted: do not use */
447 #define	M_UNHANGUP	0x92		/* line reconnect, sigh */
448 
449 /*
450  * Queue message class definitions.
451  */
452 #define	QNORM		0x00		/* normal priority messages */
453 #define	QPCTL		0x80		/* high priority cntrl messages */
454 
455 /*
456  *  IOCTL structure - this structure is the format of the M_IOCTL message type.
457  */
458 #if	defined(_LP64)
459 struct iocblk {
460 	int 	ioc_cmd;		/* ioctl command type */
461 	cred_t	*ioc_cr;		/* full credentials */
462 	uint_t	ioc_id;			/* ioctl id */
463 	uint_t	ioc_flag;		/* see below */
464 	size_t	ioc_count;		/* count of bytes in data field */
465 	int	ioc_rval;		/* return value  */
466 	int	ioc_error;		/* error code */
467 };
468 #else
469 struct iocblk {
470 	int 	ioc_cmd;		/* ioctl command type */
471 	cred_t	*ioc_cr;		/* full credentials */
472 	uint_t	ioc_id;			/* ioctl id */
473 	size_t	ioc_count;		/* count of bytes in data field */
474 	int	ioc_error;		/* error code */
475 	int	ioc_rval;		/* return value  */
476 	int	ioc_fill1;
477 	uint_t	ioc_flag;		/* see below */
478 	int	ioc_filler[2];		/* reserved for future use */
479 };
480 #endif	/* _LP64 */
481 
482 typedef	struct iocblk	*IOCP;
483 
484 /* {ioc,cp}_flags values */
485 
486 #define	IOC_MODELS	DATAMODEL_MASK	/* Note: 0x0FF00000 */
487 #define	IOC_ILP32	DATAMODEL_ILP32	/* ioctl origin is ILP32 */
488 #define	IOC_LP64	DATAMODEL_LP64	/* ioctl origin is LP64 */
489 #define	IOC_NATIVE	DATAMODEL_NATIVE
490 #define	IOC_NONE	DATAMODEL_NONE	/* dummy comparison value */
491 
492 /*
493  *	Is the ioctl data formatted for our native model?
494  */
495 #define	IOC_CONVERT_FROM(iocp)	ddi_model_convert_from( \
496 				    ((struct iocblk *)iocp)->ioc_flag)
497 
498 /*
499  * structure for the M_COPYIN and M_COPYOUT message types.
500  */
501 #if	defined(_LP64)
502 struct copyreq {
503 	int	cq_cmd;			/* ioctl command (from ioc_cmd) */
504 	cred_t	*cq_cr;			/* full credentials (from ioc_cmd) */
505 	uint_t	cq_id;			/* ioctl id (from ioc_id) */
506 	uint_t	cq_flag;		/* must be zero */
507 	mblk_t	*cq_private;		/* private state information */
508 	caddr_t	cq_addr;		/* address to copy data to/from */
509 	size_t	cq_size;		/* number of bytes to copy */
510 };
511 #else
512 struct copyreq {
513 	int	cq_cmd;			/* ioctl command (from ioc_cmd) */
514 	cred_t	*cq_cr;			/* full credentials */
515 	uint_t	cq_id;			/* ioctl id (from ioc_id) */
516 	caddr_t	cq_addr;		/* address to copy data to/from */
517 	size_t	cq_size;		/* number of bytes to copy */
518 	uint_t	cq_flag;		/* must be zero */
519 	mblk_t	*cq_private;		/* private state information */
520 	int	cq_filler[4];		/* reserved for future use */
521 };
522 #endif	/* _LP64 */
523 
524 /*
525  * structure for the M_IOCDATA message type.
526  */
527 #if	defined(_LP64)
528 struct copyresp {
529 	int	cp_cmd;			/* ioctl command (from ioc_cmd) */
530 	cred_t	*cp_cr;			/* full credentials (from ioc_cmd) */
531 	uint_t	cp_id;			/* ioctl id (from ioc_id) */
532 	uint_t	cp_flag;		/* datamodel IOC_ flags; see above */
533 	mblk_t *cp_private;		/* private state information */
534 	caddr_t	cp_rval;		/* status of request: 0 -> success */
535 					/* 		non-zero -> failure */
536 };
537 #else
538 struct copyresp {
539 	int	cp_cmd;			/* ioctl command (from ioc_cmd) */
540 	cred_t	*cp_cr;			/* full credentials */
541 	uint_t	cp_id;			/* ioctl id (from ioc_id) */
542 	caddr_t	cp_rval;		/* status of request: 0 -> success */
543 					/* 		non-zero -> failure */
544 	size_t	cp_pad1;
545 	uint_t	cp_pad2;
546 	mblk_t *cp_private;		/* private state information */
547 	uint_t	cp_flag;		/* datamodel IOC_ flags; see above */
548 	int	cp_filler[3];
549 };
550 #endif	/* _LP64 */
551 
552 /*
553  * Since these structures are all intended to travel in the same message
554  * at different stages of a STREAMS ioctl, this union is used to determine
555  * the message size in strdoioctl().
556  */
557 union ioctypes {
558 	struct iocblk	iocblk;
559 	struct copyreq	copyreq;
560 	struct copyresp	copyresp;
561 };
562 
563 /*
564  * Options structure for M_SETOPTS message.  This is sent upstream
565  * by a module or driver to set stream head options.
566  */
567 
568 struct stroptions {
569 	uint_t	so_flags;		/* options to set */
570 	short	so_readopt;		/* read option */
571 	ushort_t so_wroff;		/* write offset */
572 	ssize_t	so_minpsz;		/* minimum read packet size */
573 	ssize_t	so_maxpsz;		/* maximum read packet size */
574 	size_t	so_hiwat;		/* read queue high water mark */
575 	size_t	so_lowat;		/* read queue low water mark */
576 	unsigned char so_band;		/* band for water marks */
577 	ushort_t so_erropt;		/* error option */
578 	ssize_t	so_maxblk;		/* maximum message block size */
579 	ushort_t so_copyopt;		/* copy options (see stropts.h) */
580 };
581 
582 /* flags for stream options set message */
583 
584 #define	SO_ALL		0x003f	/* set all old options */
585 #define	SO_READOPT	0x0001	/* set read option */
586 #define	SO_WROFF	0x0002	/* set write offset */
587 #define	SO_MINPSZ	0x0004	/* set min packet size */
588 #define	SO_MAXPSZ	0x0008	/* set max packet size */
589 #define	SO_HIWAT	0x0010	/* set high water mark */
590 #define	SO_LOWAT	0x0020	/* set low water mark */
591 #define	SO_MREADON	0x0040	/* set read notification ON */
592 #define	SO_MREADOFF	0x0080	/* set read notification OFF */
593 #define	SO_NDELON	0x0100	/* old TTY semantics for NDELAY reads/writes */
594 #define	SO_NDELOFF	0x0200	/* STREAMS semantics for NDELAY reads/writes */
595 #define	SO_ISTTY	0x0400	/* the stream is acting as a terminal */
596 #define	SO_ISNTTY	0x0800	/* the stream is not acting as a terminal */
597 #define	SO_TOSTOP	0x1000	/* stop on background writes to this stream */
598 #define	SO_TONSTOP	0x2000	/* do not stop on background writes to stream */
599 #define	SO_BAND		0x4000	/* water marks affect band */
600 #define	SO_DELIM	0x8000	/* messages are delimited */
601 #define	SO_NODELIM	0x010000	/* turn off delimiters */
602 #define	SO_STRHOLD	0x020000	/* No longer implemented */
603 #define	SO_ERROPT	0x040000	/* set error option */
604 #define	SO_COPYOPT	0x080000	/* copy option(s) present */
605 #define	SO_MAXBLK	0x100000	/* set maximum message block size */
606 
607 #ifdef _KERNEL
608 /*
609  * Structure for rw (read/write) procedure calls. A pointer
610  * to a struiod_t is passed as a parameter to the rwnext() call.
611  *
612  * Note: DEF_IOV_MAX is defined and used as it is in "fs/vncalls.c"
613  *	 as there isn't a formal definition of IOV_MAX ???
614  */
615 #define	DEF_IOV_MAX	16
616 
617 typedef struct struiod {
618 	mblk_t		*d_mp;		/* pointer to mblk (chain) */
619 	uio_t		d_uio;		/* uio info */
620 	iovec_t d_iov[DEF_IOV_MAX];	/* iov referenced by uio */
621 } struiod_t;
622 
623 /*
624  * Structure for information procedure calls.
625  */
626 typedef struct infod {
627 	unsigned char	d_cmd;		/* info info request command */
628 	unsigned char	d_res;		/* info info command results */
629 	int		d_bytes;	/* mblk(s) byte count */
630 	int		d_count;	/* count of mblk(s) */
631 	uio_t		*d_uiop;	/* pointer to uio struct */
632 } infod_t;
633 /*
634  * Values for d_cmd & d_res.
635  */
636 #define	INFOD_FIRSTBYTES	0x02	/* return msgbsize() of first mblk */
637 #define	INFOD_BYTES		0x04	/* return msgbsize() of all mblk(s) */
638 #define	INFOD_COUNT		0x08	/* return count of mblk(s) */
639 #define	INFOD_COPYOUT		0x10	/* copyout any M_DATA mblk(s) */
640 
641 #endif /* _KERNEL */
642 
643 /*
644  * Miscellaneous parameters and flags.
645  */
646 
647 /*
648  * Values for stream flag in open to indicate module open, clone open,
649  * and the return value for failure.
650  */
651 #define	MODOPEN 	0x1		/* open as a module */
652 #define	CLONEOPEN	0x2		/* clone open; pick own minor dev */
653 #define	OPENFAIL	-1		/* returned for open failure */
654 
655 /*
656  * Priority definitions for block allocation.
657  */
658 #define	BPRI_LO		1
659 #define	BPRI_MED	2
660 #define	BPRI_HI		3
661 
662 /*
663  * Value for packet size that denotes infinity
664  */
665 #define	INFPSZ		-1
666 
667 /*
668  * Flags for flushq()
669  */
670 #define	FLUSHALL	1	/* flush all messages */
671 #define	FLUSHDATA	0	/* don't flush control messages */
672 
673 /*
674  * Flag for transparent ioctls
675  */
676 #define	TRANSPARENT	(unsigned int)(-1)
677 
678 /*
679  * Stream head default high/low water marks
680  */
681 #define	STRHIGH 5120
682 #define	STRLOW	1024
683 
684 /*
685  * Block allocation parameters
686  */
687 #define	MAXIOCBSZ	1024		/* max ioctl data block size */
688 
689 /*
690  * qwriter perimeter types
691  */
692 #define	PERIM_INNER	1		/* The inner perimeter */
693 #define	PERIM_OUTER	2		/* The outer perimeter */
694 
695 /*
696  * Definitions of Streams macros and function interfaces.
697  */
698 
699 /*
700  * canenable - check if queue can be enabled by putq().
701  */
702 #define	canenable(q)	!((q)->q_flag & QNOENB)
703 
704 /*
705  * Test if data block type is one of the data messages (i.e. not a control
706  * message).
707  */
708 #define	datamsg(type) \
709 		((type) == M_DATA || \
710 		    (type) == M_MULTIDATA || \
711 		    (type) == M_PROTO || \
712 		    (type) == M_PCPROTO || \
713 		    (type) == M_DELAY)
714 
715 /*
716  * Extract queue class of message block.
717  */
718 #define	queclass(bp) (((bp)->b_datap->db_type >= QPCTL) ? QPCTL : QNORM)
719 
720 /*
721  * Align address on next lower word boundary.
722  */
723 #define	straln(a)	(caddr_t)((intptr_t)(a) & -(sizeof (int)-1))
724 
725 /*
726  * Find the max size of data block.
727  */
728 #define	bpsize(bp) ((unsigned int)(bp->b_datap->db_lim - bp->b_datap->db_base))
729 
730 #ifdef _KERNEL
731 
732 /*
733  * For two-byte M_ERROR messages: indication that a side does not have an error
734  */
735 #define	NOERROR	((unsigned char)-1)
736 
737 /*
738  * declarations of common routines
739  */
740 
741 extern mblk_t *allocb(size_t, uint_t);
742 extern mblk_t *desballoc(unsigned char *, size_t, uint_t, frtn_t *);
743 extern mblk_t *esballoc(unsigned char *, size_t, uint_t, frtn_t *);
744 extern bcache_t *bcache_create(char *, size_t, uint_t);
745 extern void bcache_destroy(bcache_t *);
746 extern mblk_t *bcache_allocb(bcache_t *, uint_t);
747 extern mblk_t *mkiocb(uint_t);
748 extern int testb(size_t, uint_t);
749 extern bufcall_id_t bufcall(size_t, uint_t, void (*)(void *), void *);
750 extern bufcall_id_t esbbcall(uint_t, void (*)(void *), void *);
751 extern void freeb(struct msgb *);
752 extern void freemsg(mblk_t *);
753 extern mblk_t *dupb(mblk_t *);
754 extern mblk_t *dupmsg(mblk_t *);
755 extern mblk_t *dupmsg_noloan(mblk_t *);
756 extern mblk_t *copyb(mblk_t *);
757 extern mblk_t *copymsg(mblk_t *);
758 extern void linkb(mblk_t *, mblk_t *);
759 extern mblk_t *unlinkb(mblk_t *);
760 extern mblk_t *reallocb(mblk_t *, size_t, uint_t);	/* private */
761 extern mblk_t *rmvb(mblk_t *, mblk_t *);
762 extern int pullupmsg(struct msgb *, ssize_t);
763 extern mblk_t *msgpullup(struct msgb *, ssize_t);
764 extern int adjmsg(struct msgb *, ssize_t);
765 extern size_t msgdsize(struct msgb *);
766 extern mblk_t *getq(queue_t *);
767 extern void rmvq(queue_t *, mblk_t *);
768 extern void flushq(queue_t *, int);
769 extern void flushq_common(queue_t *, int, int);
770 extern void flushband(queue_t *, unsigned char, int);
771 extern int canput(queue_t *);
772 extern int bcanput(queue_t *, unsigned char);
773 extern int canputnext(queue_t *);
774 extern int bcanputnext(queue_t *, unsigned char);
775 extern int putq(queue_t *, mblk_t *);
776 extern int putbq(queue_t *, mblk_t *);
777 extern int insq(queue_t *, mblk_t *, mblk_t *);
778 extern void put(queue_t *, mblk_t *);
779 extern void putnext(queue_t *, mblk_t *);
780 extern int putctl(queue_t *, int);
781 extern int putctl1(queue_t *, int, int);
782 extern int putnextctl(queue_t *, int);
783 extern int putnextctl1(queue_t *, int, int);
784 extern queue_t *backq(queue_t *);
785 extern void qreply(queue_t *, mblk_t *);
786 extern void qenable(queue_t *);
787 extern int qsize(queue_t *);
788 extern void noenable(queue_t *);
789 extern void enableok(queue_t *);
790 extern int strqset(queue_t *, qfields_t, unsigned char, intptr_t);
791 extern int strqget(queue_t *, qfields_t, unsigned char, void *);
792 extern void unbufcall(bufcall_id_t);
793 extern void qprocson(queue_t *);
794 extern void qprocsoff(queue_t *);
795 extern void freezestr(queue_t *);
796 extern void unfreezestr(queue_t *);
797 extern void qwait(queue_t *);
798 extern int qwait_sig(queue_t *);
799 extern boolean_t qwait_rw(queue_t *);
800 extern void qwriter(queue_t *, mblk_t *, void (*func)(), int);
801 extern timeout_id_t qtimeout(queue_t *, void (*func)(void *), void *, clock_t);
802 extern bufcall_id_t qbufcall(queue_t *, size_t, uint_t,
803     void (*)(void *), void *);
804 extern clock_t quntimeout(queue_t *, timeout_id_t);
805 extern void qunbufcall(queue_t *, bufcall_id_t);
806 extern void strwakeq(queue_t *, int);
807 extern int struioget(queue_t *, mblk_t *, struiod_t *, int);
808 extern int rwnext(queue_t *, struiod_t *);
809 extern int infonext(queue_t *, infod_t *);
810 extern int isuioq(queue_t *);
811 extern void create_putlocks(queue_t *, int);
812 
813 /*
814  * shared or externally configured data structures
815  */
816 extern int nstrpush;			/* maximum number of pushes allowed */
817 
818 #endif /* _KERNEL */
819 
820 #ifdef	__cplusplus
821 }
822 #endif
823 
824 #endif	/* _SYS_STREAM_H */
825