xref: /titanic_52/usr/src/uts/common/sys/stream.h (revision bdfc6d18da790deeec2e0eb09c625902defe2498)
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 
175 /* queue sqflags (protected by SQLOCK). */
176 #define	Q_SQQUEUED	0x01		/* Queue is in the syncq list */
177 #define	Q_SQDRAINING	0x02		/* Servicing suncq msgs.	*/
178 					/* This is also noted by the	*/
179 					/* q_draining field, but this one is */
180 					/* protected by SQLOCK */
181 
182 /*
183  * Structure that describes the separate information
184  * for each priority band in the queue.
185  */
186 typedef struct qband {
187 	struct qband	*qb_next;	/* next band's info */
188 	size_t		qb_count;	/* number of bytes in band */
189 	struct msgb	*qb_first;	/* beginning of band's data */
190 	struct msgb	*qb_last;	/* end of band's data */
191 	size_t		qb_hiwat;	/* high water mark for band */
192 	size_t		qb_lowat;	/* low water mark for band */
193 	uint_t		qb_flag;	/* see below */
194 	size_t		qb_mblkcnt;	/* mblk counter for runaway msgs */
195 } qband_t;
196 
197 /*
198  * qband flags
199  */
200 #define	QB_FULL		0x01		/* band is considered full */
201 #define	QB_WANTW	0x02		/* Someone wants to write to band */
202 #define	QB_BACK		0x04		/* queue has been back-enabled */
203 
204 /*
205  * Maximum number of bands.
206  */
207 #define	NBAND	256
208 
209 /*
210  * Fields that can be manipulated through strqset() and strqget().
211  */
212 typedef enum qfields {
213 	QHIWAT	= 0,		/* q_hiwat or qb_hiwat */
214 	QLOWAT	= 1,		/* q_lowat or qb_lowat */
215 	QMAXPSZ	= 2,		/* q_maxpsz */
216 	QMINPSZ	= 3,		/* q_minpsz */
217 	QCOUNT	= 4,		/* q_count or qb_count */
218 	QFIRST	= 5,		/* q_first or qb_first */
219 	QLAST	= 6,		/* q_last or qb_last */
220 	QFLAG	= 7,		/* q_flag or qb_flag */
221 	QSTRUIOT = 8,		/* q_struiot */
222 	QBAD	= 9
223 } qfields_t;
224 
225 /*
226  * Module information structure
227  */
228 struct module_info {
229 	ushort_t mi_idnum;		/* module id number */
230 	char 	*mi_idname;		/* module name */
231 	ssize_t	mi_minpsz;		/* min packet size accepted */
232 	ssize_t	mi_maxpsz;		/* max packet size accepted */
233 	size_t	mi_hiwat;		/* hi-water mark */
234 	size_t 	mi_lowat;		/* lo-water mark */
235 };
236 
237 /*
238  * queue information structure (with Synchronous STREAMS extensions)
239  */
240 struct	qinit {
241 	int	(*qi_putp)();		/* put procedure */
242 	int	(*qi_srvp)();		/* service procedure */
243 	int	(*qi_qopen)();		/* called on startup */
244 	int	(*qi_qclose)();		/* called on finish */
245 	int	(*qi_qadmin)();		/* for future use */
246 	struct module_info *qi_minfo;	/* module information structure */
247 	struct module_stat *qi_mstat;	/* module statistics structure */
248 	int	(*qi_rwp)();		/* r/w procedure */
249 	int	(*qi_infop)();		/* information procedure */
250 	int	qi_struiot;		/* stream uio type for struio() */
251 };
252 
253 /*
254  * Values for qi_struiot and q_struiot:
255  */
256 #define	STRUIOT_NONE		-1	/* doesn't support struio() */
257 #define	STRUIOT_DONTCARE	0	/* use current uiomove() (default) */
258 #define	STRUIOT_STANDARD	1	/* use standard uiomove() */
259 
260 /*
261  * Streamtab (used in cdevsw and fmodsw to point to module or driver)
262  */
263 struct streamtab {
264 	struct qinit *st_rdinit;
265 	struct qinit *st_wrinit;
266 	struct qinit *st_muxrinit;
267 	struct qinit *st_muxwinit;
268 };
269 
270 /*
271  * Structure sent to mux drivers to indicate a link.
272  */
273 struct linkblk {
274 	queue_t *l_qtop;	/* lowest level write queue of upper stream */
275 				/* (set to NULL for persistent links) */
276 	queue_t *l_qbot;	/* highest level write queue of lower stream */
277 	int	l_index;	/* index for lower stream. */
278 };
279 
280 /*
281  * Esballoc data buffer freeing routine
282  */
283 typedef struct free_rtn {
284 	void	(*free_func)();
285 	caddr_t	free_arg;
286 } frtn_t;
287 
288 /*
289  * Data block descriptor
290  *
291  * NOTE: db_base, db_lim, db_ref and db_type are the *only* public fields,
292  * as described in datab(9S).  Everything else is implementation-private.
293  */
294 
295 #define	DBLK_REFMAX	255U
296 
297 typedef struct datab {
298 	frtn_t		*db_frtnp;
299 	unsigned char	*db_base;
300 	unsigned char	*db_lim;
301 	unsigned char	db_ref;
302 	unsigned char	db_type;
303 	unsigned char	db_flags;
304 	unsigned char	db_struioflag;
305 	pid_t		db_cpid;	/* cached pid, needs verification */
306 	void		*db_cache;	/* kmem cache descriptor */
307 	struct msgb	*db_mblk;
308 	void		(*db_free)(struct msgb *, struct datab *);
309 	void		(*db_lastfree)(struct msgb *, struct datab *);
310 	intptr_t	db_cksumstart;
311 	intptr_t	db_cksumend;
312 	intptr_t	db_cksumstuff;
313 	union {
314 		double enforce_alignment;
315 		unsigned char data[8];
316 		struct {
317 			union {
318 				uint32_t u32;
319 				uint16_t u16;
320 			} cksum_val;    /* used to store calculated cksum */
321 			uint16_t flags;
322 			uint16_t pad;
323 		} cksum;
324 		/*
325 		 * Union used for future extensions (pointer to data ?).
326 		 */
327 	} db_struioun;
328 	fthdr_t		*db_fthdr;
329 	cred_t		*db_credp;	/* credential */
330 } dblk_t;
331 
332 #define	db_cksum16	db_struioun.cksum.cksum_val.u16
333 #define	db_cksum32	db_struioun.cksum.cksum_val.u32
334 
335 /*
336  * Accessor macros for private dblk_t fields (the rest are in <sys/strsun.h>).
337  */
338 #define	DB_CPID(mp)		((mp)->b_datap->db_cpid)
339 #define	DB_CRED(mp)		((mp)->b_datap->db_credp)
340 #define	DB_CREDDEF(mp, cr)	(DB_CRED(mp) != NULL ? DB_CRED(mp) : (cr))
341 #define	DB_FTHDR(mp)		((mp)->b_datap->db_fthdr)
342 
343 /*
344  * Message block descriptor
345  */
346 typedef struct	msgb {
347 	struct	msgb	*b_next;
348 	struct  msgb	*b_prev;
349 	struct	msgb	*b_cont;
350 	unsigned char	*b_rptr;
351 	unsigned char	*b_wptr;
352 	struct datab 	*b_datap;
353 	unsigned char	b_band;
354 	unsigned char	b_tag;
355 	unsigned short	b_flag;
356 	queue_t		*b_queue;	/* for sync queues */
357 } mblk_t;
358 
359 /*
360  * bcache descriptor
361  */
362 
363 typedef	struct	bcache {
364 	kmutex_t		mutex;
365 	struct kmem_cache	*buffer_cache;
366 	struct kmem_cache	*dblk_cache;
367 	int			alloc;
368 	int			destroy;
369 	size_t			size;
370 	uint_t			align;
371 } bcache_t;
372 
373 /*
374  * db_flags values (all implementation private!)
375  */
376 #define	DBLK_REFMIN	0x01		/* min refcnt stored in low bit */
377 
378 /*
379  * db_struioflag values:
380  */
381 #define	STRUIO_SPEC	0x01	/* struio{get,put}() special mblk */
382 #define	STRUIO_DONE	0x02	/* struio done (could be partial) */
383 #define	STRUIO_IP	0x04	/* IP checksum stored in db_struioun */
384 #define	STRUIO_ZC	0x08	/* mblk eligible for zero-copy */
385 #define	STRUIO_ZCNOTIFY	0x10	/* notify stream head when mblk acked */
386 #define	STRUIO_EAGER	0x20	/* new eager; db_cksumstart has squeue to use */
387 #define	STRUIO_POLICY	0x40	/* new eager when IPsec is enabled */
388 
389 /*
390  * Message flags.  These are interpreted by the stream head.
391  */
392 #define	MSGMARK		0x01	/* last byte of message is "marked" */
393 #define	MSGNOLOOP	0x02	/* don't loop message around to */
394 				/* write side of stream */
395 #define	MSGDELIM	0x04	/* message is delimited */
396 /*	UNUSED		0x08	   was MSGNOGET (can be recycled) */
397 #define	MSGMARKNEXT	0x10	/* Private: first byte of next msg marked */
398 #define	MSGNOTMARKNEXT	0x20	/* Private: ... not marked */
399 #define	MSGHASREF	0x40	/* Private: message has reference to owner */
400 
401 /*
402  * Streams message types.
403  */
404 
405 /*
406  * Data and protocol messages (regular and priority)
407  */
408 #define	M_DATA		0x00		/* regular data */
409 #define	M_PROTO		0x01		/* protocol control */
410 #define	M_MULTIDATA	0x02		/* reserved for Multidata use only */
411 
412 /*
413  * Control messages (regular and priority)
414  */
415 #define	M_BREAK		0x08		/* line break */
416 #define	M_PASSFP	0x09		/* pass file pointer */
417 #define	M_EVENT		0x0a		/* Obsoleted: do not use */
418 #define	M_SIG		0x0b		/* generate process signal */
419 #define	M_DELAY		0x0c		/* real-time xmit delay (1 param) */
420 #define	M_CTL		0x0d		/* device-specific control message */
421 #define	M_IOCTL		0x0e		/* ioctl; set/get params */
422 #define	M_SETOPTS	0x10		/* set various stream head options */
423 #define	M_RSE		0x11		/* reserved for RSE use only */
424 
425 /*
426  * Control messages (high priority; go to head of queue)
427  */
428 #define	M_IOCACK	0x81		/* acknowledge ioctl */
429 #define	M_IOCNAK	0x82		/* negative ioctl acknowledge */
430 #define	M_PCPROTO	0x83		/* priority proto message */
431 #define	M_PCSIG		0x84		/* generate process signal */
432 #define	M_READ		0x85		/* generate read notification */
433 #define	M_FLUSH		0x86		/* flush your queues */
434 #define	M_STOP		0x87		/* stop transmission immediately */
435 #define	M_START		0x88		/* restart transmission after stop */
436 #define	M_HANGUP	0x89		/* line disconnect */
437 #define	M_ERROR		0x8a		/* send error to stream head */
438 #define	M_COPYIN	0x8b		/* request to copyin data */
439 #define	M_COPYOUT	0x8c		/* request to copyout data */
440 #define	M_IOCDATA	0x8d		/* response to M_COPYIN and M_COPYOUT */
441 #define	M_PCRSE		0x8e		/* reserved for RSE use only */
442 #define	M_STOPI		0x8f		/* stop reception immediately */
443 #define	M_STARTI	0x90		/* restart reception after stop */
444 #define	M_PCEVENT	0x91		/* Obsoleted: do not use */
445 #define	M_UNHANGUP	0x92		/* line reconnect, sigh */
446 
447 /*
448  * Queue message class definitions.
449  */
450 #define	QNORM		0x00		/* normal priority messages */
451 #define	QPCTL		0x80		/* high priority cntrl messages */
452 
453 /*
454  *  IOCTL structure - this structure is the format of the M_IOCTL message type.
455  */
456 #if	defined(_LP64)
457 struct iocblk {
458 	int 	ioc_cmd;		/* ioctl command type */
459 	cred_t	*ioc_cr;		/* full credentials */
460 	uint_t	ioc_id;			/* ioctl id */
461 	uint_t	ioc_flag;		/* see below */
462 	size_t	ioc_count;		/* count of bytes in data field */
463 	int	ioc_rval;		/* return value  */
464 	int	ioc_error;		/* error code */
465 };
466 #else
467 struct iocblk {
468 	int 	ioc_cmd;		/* ioctl command type */
469 	cred_t	*ioc_cr;		/* full credentials */
470 	uint_t	ioc_id;			/* ioctl id */
471 	size_t	ioc_count;		/* count of bytes in data field */
472 	int	ioc_error;		/* error code */
473 	int	ioc_rval;		/* return value  */
474 	int	ioc_fill1;
475 	uint_t	ioc_flag;		/* see below */
476 	int	ioc_filler[2];		/* reserved for future use */
477 };
478 #endif	/* _LP64 */
479 
480 typedef	struct iocblk	*IOCP;
481 
482 /* {ioc,cp}_flags values */
483 
484 #define	IOC_MODELS	DATAMODEL_MASK	/* Note: 0x0FF00000 */
485 #define	IOC_ILP32	DATAMODEL_ILP32	/* ioctl origin is ILP32 */
486 #define	IOC_LP64	DATAMODEL_LP64	/* ioctl origin is LP64 */
487 #define	IOC_NATIVE	DATAMODEL_NATIVE
488 #define	IOC_NONE	DATAMODEL_NONE	/* dummy comparison value */
489 
490 /*
491  *	Is the ioctl data formatted for our native model?
492  */
493 #define	IOC_CONVERT_FROM(iocp)	ddi_model_convert_from( \
494 				    ((struct iocblk *)iocp)->ioc_flag)
495 
496 /*
497  * structure for the M_COPYIN and M_COPYOUT message types.
498  */
499 #if	defined(_LP64)
500 struct copyreq {
501 	int	cq_cmd;			/* ioctl command (from ioc_cmd) */
502 	cred_t	*cq_cr;			/* full credentials (from ioc_cmd) */
503 	uint_t	cq_id;			/* ioctl id (from ioc_id) */
504 	uint_t	cq_flag;		/* must be zero */
505 	mblk_t	*cq_private;		/* private state information */
506 	caddr_t	cq_addr;		/* address to copy data to/from */
507 	size_t	cq_size;		/* number of bytes to copy */
508 };
509 #else
510 struct copyreq {
511 	int	cq_cmd;			/* ioctl command (from ioc_cmd) */
512 	cred_t	*cq_cr;			/* full credentials */
513 	uint_t	cq_id;			/* ioctl id (from ioc_id) */
514 	caddr_t	cq_addr;		/* address to copy data to/from */
515 	size_t	cq_size;		/* number of bytes to copy */
516 	uint_t	cq_flag;		/* must be zero */
517 	mblk_t	*cq_private;		/* private state information */
518 	int	cq_filler[4];		/* reserved for future use */
519 };
520 #endif	/* _LP64 */
521 
522 /*
523  * structure for the M_IOCDATA message type.
524  */
525 #if	defined(_LP64)
526 struct copyresp {
527 	int	cp_cmd;			/* ioctl command (from ioc_cmd) */
528 	cred_t	*cp_cr;			/* full credentials (from ioc_cmd) */
529 	uint_t	cp_id;			/* ioctl id (from ioc_id) */
530 	uint_t	cp_flag;		/* datamodel IOC_ flags; see above */
531 	mblk_t *cp_private;		/* private state information */
532 	caddr_t	cp_rval;		/* status of request: 0 -> success */
533 					/* 		non-zero -> failure */
534 };
535 #else
536 struct copyresp {
537 	int	cp_cmd;			/* ioctl command (from ioc_cmd) */
538 	cred_t	*cp_cr;			/* full credentials */
539 	uint_t	cp_id;			/* ioctl id (from ioc_id) */
540 	caddr_t	cp_rval;		/* status of request: 0 -> success */
541 					/* 		non-zero -> failure */
542 	size_t	cp_pad1;
543 	uint_t	cp_pad2;
544 	mblk_t *cp_private;		/* private state information */
545 	uint_t	cp_flag;		/* datamodel IOC_ flags; see above */
546 	int	cp_filler[3];
547 };
548 #endif	/* _LP64 */
549 
550 /*
551  * Since these structures are all intended to travel in the same message
552  * at different stages of a STREAMS ioctl, this union is used to determine
553  * the message size in strdoioctl().
554  */
555 union ioctypes {
556 	struct iocblk	iocblk;
557 	struct copyreq	copyreq;
558 	struct copyresp	copyresp;
559 };
560 
561 /*
562  * Options structure for M_SETOPTS message.  This is sent upstream
563  * by a module or driver to set stream head options.
564  */
565 
566 struct stroptions {
567 	uint_t	so_flags;		/* options to set */
568 	short	so_readopt;		/* read option */
569 	ushort_t so_wroff;		/* write offset */
570 	ssize_t	so_minpsz;		/* minimum read packet size */
571 	ssize_t	so_maxpsz;		/* maximum read packet size */
572 	size_t	so_hiwat;		/* read queue high water mark */
573 	size_t	so_lowat;		/* read queue low water mark */
574 	unsigned char so_band;		/* band for water marks */
575 	ushort_t so_erropt;		/* error option */
576 	ssize_t	so_maxblk;		/* maximum message block size */
577 	ushort_t so_copyopt;		/* copy options (see stropts.h) */
578 };
579 
580 /* flags for stream options set message */
581 
582 #define	SO_ALL		0x003f	/* set all old options */
583 #define	SO_READOPT	0x0001	/* set read option */
584 #define	SO_WROFF	0x0002	/* set write offset */
585 #define	SO_MINPSZ	0x0004	/* set min packet size */
586 #define	SO_MAXPSZ	0x0008	/* set max packet size */
587 #define	SO_HIWAT	0x0010	/* set high water mark */
588 #define	SO_LOWAT	0x0020	/* set low water mark */
589 #define	SO_MREADON	0x0040	/* set read notification ON */
590 #define	SO_MREADOFF	0x0080	/* set read notification OFF */
591 #define	SO_NDELON	0x0100	/* old TTY semantics for NDELAY reads/writes */
592 #define	SO_NDELOFF	0x0200	/* STREAMS semantics for NDELAY reads/writes */
593 #define	SO_ISTTY	0x0400	/* the stream is acting as a terminal */
594 #define	SO_ISNTTY	0x0800	/* the stream is not acting as a terminal */
595 #define	SO_TOSTOP	0x1000	/* stop on background writes to this stream */
596 #define	SO_TONSTOP	0x2000	/* do not stop on background writes to stream */
597 #define	SO_BAND		0x4000	/* water marks affect band */
598 #define	SO_DELIM	0x8000	/* messages are delimited */
599 #define	SO_NODELIM	0x010000	/* turn off delimiters */
600 #define	SO_STRHOLD	0x020000	/* No longer implemented */
601 #define	SO_ERROPT	0x040000	/* set error option */
602 #define	SO_COPYOPT	0x080000	/* copy option(s) present */
603 #define	SO_MAXBLK	0x100000	/* set maximum message block size */
604 
605 #ifdef _KERNEL
606 /*
607  * Structure for rw (read/write) procedure calls. A pointer
608  * to a struiod_t is passed as a parameter to the rwnext() call.
609  *
610  * Note: DEF_IOV_MAX is defined and used as it is in "fs/vncalls.c"
611  *	 as there isn't a formal definition of IOV_MAX ???
612  */
613 #define	DEF_IOV_MAX	16
614 
615 typedef struct struiod {
616 	mblk_t		*d_mp;		/* pointer to mblk (chain) */
617 	uio_t		d_uio;		/* uio info */
618 	iovec_t d_iov[DEF_IOV_MAX];	/* iov referenced by uio */
619 } struiod_t;
620 
621 /*
622  * Structure for information procedure calls.
623  */
624 typedef struct infod {
625 	unsigned char	d_cmd;		/* info info request command */
626 	unsigned char	d_res;		/* info info command results */
627 	int		d_bytes;	/* mblk(s) byte count */
628 	int		d_count;	/* count of mblk(s) */
629 	uio_t		*d_uiop;	/* pointer to uio struct */
630 } infod_t;
631 /*
632  * Values for d_cmd & d_res.
633  */
634 #define	INFOD_FIRSTBYTES	0x02	/* return msgbsize() of first mblk */
635 #define	INFOD_BYTES		0x04	/* return msgbsize() of all mblk(s) */
636 #define	INFOD_COUNT		0x08	/* return count of mblk(s) */
637 #define	INFOD_COPYOUT		0x10	/* copyout any M_DATA mblk(s) */
638 
639 #endif /* _KERNEL */
640 
641 /*
642  * Miscellaneous parameters and flags.
643  */
644 
645 /*
646  * Values for stream flag in open to indicate module open, clone open,
647  * and the return value for failure.
648  */
649 #define	MODOPEN 	0x1		/* open as a module */
650 #define	CLONEOPEN	0x2		/* clone open; pick own minor dev */
651 #define	OPENFAIL	-1		/* returned for open failure */
652 
653 /*
654  * Priority definitions for block allocation.
655  */
656 #define	BPRI_LO		1
657 #define	BPRI_MED	2
658 #define	BPRI_HI		3
659 
660 /*
661  * Value for packet size that denotes infinity
662  */
663 #define	INFPSZ		-1
664 
665 /*
666  * Flags for flushq()
667  */
668 #define	FLUSHALL	1	/* flush all messages */
669 #define	FLUSHDATA	0	/* don't flush control messages */
670 
671 /*
672  * Flag for transparent ioctls
673  */
674 #define	TRANSPARENT	(unsigned int)(-1)
675 
676 /*
677  * Stream head default high/low water marks
678  */
679 #define	STRHIGH 5120
680 #define	STRLOW	1024
681 
682 /*
683  * Block allocation parameters
684  */
685 #define	MAXIOCBSZ	1024		/* max ioctl data block size */
686 
687 /*
688  * qwriter perimeter types
689  */
690 #define	PERIM_INNER	1		/* The inner perimeter */
691 #define	PERIM_OUTER	2		/* The outer perimeter */
692 
693 /*
694  * Definitions of Streams macros and function interfaces.
695  */
696 
697 /*
698  * canenable - check if queue can be enabled by putq().
699  */
700 #define	canenable(q)	!((q)->q_flag & QNOENB)
701 
702 /*
703  * Test if data block type is one of the data messages (i.e. not a control
704  * message).
705  */
706 #define	datamsg(type) \
707 		((type) == M_DATA || \
708 		    (type) == M_MULTIDATA || \
709 		    (type) == M_PROTO || \
710 		    (type) == M_PCPROTO || \
711 		    (type) == M_DELAY)
712 
713 /*
714  * Extract queue class of message block.
715  */
716 #define	queclass(bp) (((bp)->b_datap->db_type >= QPCTL) ? QPCTL : QNORM)
717 
718 /*
719  * Align address on next lower word boundary.
720  */
721 #define	straln(a)	(caddr_t)((intptr_t)(a) & -(sizeof (int)-1))
722 
723 /*
724  * Find the max size of data block.
725  */
726 #define	bpsize(bp) ((unsigned int)(bp->b_datap->db_lim - bp->b_datap->db_base))
727 
728 #ifdef _KERNEL
729 
730 /*
731  * For two-byte M_ERROR messages: indication that a side does not have an error
732  */
733 #define	NOERROR	((unsigned char)-1)
734 
735 /*
736  * declarations of common routines
737  */
738 
739 extern mblk_t *allocb(size_t, uint_t);
740 extern mblk_t *esballoc(unsigned char *, size_t, uint_t, frtn_t *);
741 extern mblk_t *esballoc_wait(unsigned char *, size_t, uint_t, frtn_t *);
742 extern bcache_t *bcache_create(char *, size_t, uint_t);
743 extern void bcache_destroy(bcache_t *);
744 extern mblk_t *bcache_allocb(bcache_t *, uint_t);
745 extern mblk_t *mkiocb(uint_t);
746 extern int testb(size_t, uint_t);
747 extern bufcall_id_t bufcall(size_t, uint_t, void (*)(void *), void *);
748 extern bufcall_id_t esbbcall(uint_t, void (*)(void *), void *);
749 extern void freeb(struct msgb *);
750 extern void freemsg(mblk_t *);
751 extern mblk_t *dupb(mblk_t *);
752 extern mblk_t *dupmsg(mblk_t *);
753 extern mblk_t *dupmsg_noloan(mblk_t *);
754 extern mblk_t *copyb(mblk_t *);
755 extern mblk_t *copymsg(mblk_t *);
756 extern void linkb(mblk_t *, mblk_t *);
757 extern mblk_t *unlinkb(mblk_t *);
758 extern mblk_t *reallocb(mblk_t *, size_t, uint_t);	/* private */
759 extern mblk_t *rmvb(mblk_t *, mblk_t *);
760 extern int pullupmsg(struct msgb *, ssize_t);
761 extern mblk_t *msgpullup(struct msgb *, ssize_t);
762 extern int adjmsg(struct msgb *, ssize_t);
763 extern size_t msgdsize(struct msgb *);
764 extern mblk_t *getq(queue_t *);
765 extern void rmvq(queue_t *, mblk_t *);
766 extern void flushq(queue_t *, int);
767 extern void flushq_common(queue_t *, int, int);
768 extern void flushband(queue_t *, unsigned char, int);
769 extern int canput(queue_t *);
770 extern int bcanput(queue_t *, unsigned char);
771 extern int canputnext(queue_t *);
772 extern int bcanputnext(queue_t *, unsigned char);
773 extern int putq(queue_t *, mblk_t *);
774 extern int putbq(queue_t *, mblk_t *);
775 extern int insq(queue_t *, mblk_t *, mblk_t *);
776 extern void put(queue_t *, mblk_t *);
777 extern void putnext(queue_t *, mblk_t *);
778 extern int putctl(queue_t *, int);
779 extern int putctl1(queue_t *, int, int);
780 extern int putnextctl(queue_t *, int);
781 extern int putnextctl1(queue_t *, int, int);
782 extern queue_t *backq(queue_t *);
783 extern void qreply(queue_t *, mblk_t *);
784 extern void qenable(queue_t *);
785 extern int qsize(queue_t *);
786 extern void noenable(queue_t *);
787 extern void enableok(queue_t *);
788 extern int strqset(queue_t *, qfields_t, unsigned char, intptr_t);
789 extern int strqget(queue_t *, qfields_t, unsigned char, void *);
790 extern void unbufcall(bufcall_id_t);
791 extern void qprocson(queue_t *);
792 extern void qprocsoff(queue_t *);
793 extern void freezestr(queue_t *);
794 extern void unfreezestr(queue_t *);
795 extern void qwait(queue_t *);
796 extern int qwait_sig(queue_t *);
797 extern boolean_t qwait_rw(queue_t *);
798 extern void qwriter(queue_t *, mblk_t *, void (*func)(), int);
799 extern timeout_id_t qtimeout(queue_t *, void (*func)(void *), void *, clock_t);
800 extern bufcall_id_t qbufcall(queue_t *, size_t, uint_t,
801     void (*)(void *), void *);
802 extern clock_t quntimeout(queue_t *, timeout_id_t);
803 extern void qunbufcall(queue_t *, bufcall_id_t);
804 extern void strwakeq(queue_t *, int);
805 extern int struioget(queue_t *, mblk_t *, struiod_t *, int);
806 extern int rwnext(queue_t *, struiod_t *);
807 extern int infonext(queue_t *, infod_t *);
808 extern int isuioq(queue_t *);
809 extern void create_putlocks(queue_t *, int);
810 
811 /*
812  * shared or externally configured data structures
813  */
814 extern int nstrpush;			/* maximum number of pushes allowed */
815 
816 #endif /* _KERNEL */
817 
818 #ifdef	__cplusplus
819 }
820 #endif
821 
822 #endif	/* _SYS_STREAM_H */
823