xref: /titanic_44/usr/src/uts/common/sys/stream.h (revision 32529ec11ac8e93a62985721612a18ee6bb8659a)
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 #define	DBLK_COOKED	0x02		/* message has been processed once */
380 
381 /*
382  * db_struioflag values:
383  */
384 #define	STRUIO_SPEC	0x01	/* struio{get,put}() special mblk */
385 #define	STRUIO_DONE	0x02	/* struio done (could be partial) */
386 #define	STRUIO_IP	0x04	/* IP checksum stored in db_struioun */
387 #define	STRUIO_ZC	0x08	/* mblk eligible for zero-copy */
388 #define	STRUIO_ZCNOTIFY	0x10	/* notify stream head when mblk acked */
389 #define	STRUIO_EAGER	0x20	/* new eager; db_cksumstart has squeue to use */
390 #define	STRUIO_POLICY	0x40	/* new eager when IPsec is enabled */
391 
392 /*
393  * Message flags.  These are interpreted by the stream head.
394  */
395 #define	MSGMARK		0x01	/* last byte of message is "marked" */
396 #define	MSGNOLOOP	0x02	/* don't loop message around to */
397 				/* write side of stream */
398 #define	MSGDELIM	0x04	/* message is delimited */
399 /*	UNUSED		0x08	   was MSGNOGET (can be recycled) */
400 #define	MSGMARKNEXT	0x10	/* Private: first byte of next msg marked */
401 #define	MSGNOTMARKNEXT	0x20	/* Private: ... not marked */
402 #define	MSGHASREF	0x40	/* Private: message has reference to owner */
403 
404 /*
405  * Streams message types.
406  */
407 
408 /*
409  * Data and protocol messages (regular and priority)
410  */
411 #define	M_DATA		0x00		/* regular data */
412 #define	M_PROTO		0x01		/* protocol control */
413 #define	M_MULTIDATA	0x02		/* reserved for Multidata use only */
414 
415 /*
416  * Control messages (regular and priority)
417  */
418 #define	M_BREAK		0x08		/* line break */
419 #define	M_PASSFP	0x09		/* pass file pointer */
420 #define	M_EVENT		0x0a		/* Obsoleted: do not use */
421 #define	M_SIG		0x0b		/* generate process signal */
422 #define	M_DELAY		0x0c		/* real-time xmit delay (1 param) */
423 #define	M_CTL		0x0d		/* device-specific control message */
424 #define	M_IOCTL		0x0e		/* ioctl; set/get params */
425 #define	M_SETOPTS	0x10		/* set various stream head options */
426 #define	M_RSE		0x11		/* reserved for RSE use only */
427 
428 /*
429  * Control messages (high priority; go to head of queue)
430  */
431 #define	M_IOCACK	0x81		/* acknowledge ioctl */
432 #define	M_IOCNAK	0x82		/* negative ioctl acknowledge */
433 #define	M_PCPROTO	0x83		/* priority proto message */
434 #define	M_PCSIG		0x84		/* generate process signal */
435 #define	M_READ		0x85		/* generate read notification */
436 #define	M_FLUSH		0x86		/* flush your queues */
437 #define	M_STOP		0x87		/* stop transmission immediately */
438 #define	M_START		0x88		/* restart transmission after stop */
439 #define	M_HANGUP	0x89		/* line disconnect */
440 #define	M_ERROR		0x8a		/* send error to stream head */
441 #define	M_COPYIN	0x8b		/* request to copyin data */
442 #define	M_COPYOUT	0x8c		/* request to copyout data */
443 #define	M_IOCDATA	0x8d		/* response to M_COPYIN and M_COPYOUT */
444 #define	M_PCRSE		0x8e		/* reserved for RSE use only */
445 #define	M_STOPI		0x8f		/* stop reception immediately */
446 #define	M_STARTI	0x90		/* restart reception after stop */
447 #define	M_PCEVENT	0x91		/* Obsoleted: do not use */
448 #define	M_UNHANGUP	0x92		/* line reconnect, sigh */
449 
450 /*
451  * Queue message class definitions.
452  */
453 #define	QNORM		0x00		/* normal priority messages */
454 #define	QPCTL		0x80		/* high priority cntrl messages */
455 
456 /*
457  *  IOCTL structure - this structure is the format of the M_IOCTL message type.
458  */
459 #if	defined(_LP64)
460 struct iocblk {
461 	int 	ioc_cmd;		/* ioctl command type */
462 	cred_t	*ioc_cr;		/* full credentials */
463 	uint_t	ioc_id;			/* ioctl id */
464 	uint_t	ioc_flag;		/* see below */
465 	size_t	ioc_count;		/* count of bytes in data field */
466 	int	ioc_rval;		/* return value  */
467 	int	ioc_error;		/* error code */
468 };
469 #else
470 struct iocblk {
471 	int 	ioc_cmd;		/* ioctl command type */
472 	cred_t	*ioc_cr;		/* full credentials */
473 	uint_t	ioc_id;			/* ioctl id */
474 	size_t	ioc_count;		/* count of bytes in data field */
475 	int	ioc_error;		/* error code */
476 	int	ioc_rval;		/* return value  */
477 	int	ioc_fill1;
478 	uint_t	ioc_flag;		/* see below */
479 	int	ioc_filler[2];		/* reserved for future use */
480 };
481 #endif	/* _LP64 */
482 
483 typedef	struct iocblk	*IOCP;
484 
485 /* {ioc,cp}_flags values */
486 
487 #define	IOC_MODELS	DATAMODEL_MASK	/* Note: 0x0FF00000 */
488 #define	IOC_ILP32	DATAMODEL_ILP32	/* ioctl origin is ILP32 */
489 #define	IOC_LP64	DATAMODEL_LP64	/* ioctl origin is LP64 */
490 #define	IOC_NATIVE	DATAMODEL_NATIVE
491 #define	IOC_NONE	DATAMODEL_NONE	/* dummy comparison value */
492 
493 /*
494  *	Is the ioctl data formatted for our native model?
495  */
496 #define	IOC_CONVERT_FROM(iocp)	ddi_model_convert_from( \
497 				    ((struct iocblk *)iocp)->ioc_flag)
498 
499 /*
500  * structure for the M_COPYIN and M_COPYOUT message types.
501  */
502 #if	defined(_LP64)
503 struct copyreq {
504 	int	cq_cmd;			/* ioctl command (from ioc_cmd) */
505 	cred_t	*cq_cr;			/* full credentials (from ioc_cmd) */
506 	uint_t	cq_id;			/* ioctl id (from ioc_id) */
507 	uint_t	cq_flag;		/* must be zero */
508 	mblk_t	*cq_private;		/* private state information */
509 	caddr_t	cq_addr;		/* address to copy data to/from */
510 	size_t	cq_size;		/* number of bytes to copy */
511 };
512 #else
513 struct copyreq {
514 	int	cq_cmd;			/* ioctl command (from ioc_cmd) */
515 	cred_t	*cq_cr;			/* full credentials */
516 	uint_t	cq_id;			/* ioctl id (from ioc_id) */
517 	caddr_t	cq_addr;		/* address to copy data to/from */
518 	size_t	cq_size;		/* number of bytes to copy */
519 	uint_t	cq_flag;		/* must be zero */
520 	mblk_t	*cq_private;		/* private state information */
521 	int	cq_filler[4];		/* reserved for future use */
522 };
523 #endif	/* _LP64 */
524 
525 /*
526  * structure for the M_IOCDATA message type.
527  */
528 #if	defined(_LP64)
529 struct copyresp {
530 	int	cp_cmd;			/* ioctl command (from ioc_cmd) */
531 	cred_t	*cp_cr;			/* full credentials (from ioc_cmd) */
532 	uint_t	cp_id;			/* ioctl id (from ioc_id) */
533 	uint_t	cp_flag;		/* datamodel IOC_ flags; see above */
534 	mblk_t *cp_private;		/* private state information */
535 	caddr_t	cp_rval;		/* status of request: 0 -> success */
536 					/* 		non-zero -> failure */
537 };
538 #else
539 struct copyresp {
540 	int	cp_cmd;			/* ioctl command (from ioc_cmd) */
541 	cred_t	*cp_cr;			/* full credentials */
542 	uint_t	cp_id;			/* ioctl id (from ioc_id) */
543 	caddr_t	cp_rval;		/* status of request: 0 -> success */
544 					/* 		non-zero -> failure */
545 	size_t	cp_pad1;
546 	uint_t	cp_pad2;
547 	mblk_t *cp_private;		/* private state information */
548 	uint_t	cp_flag;		/* datamodel IOC_ flags; see above */
549 	int	cp_filler[3];
550 };
551 #endif	/* _LP64 */
552 
553 /*
554  * Since these structures are all intended to travel in the same message
555  * at different stages of a STREAMS ioctl, this union is used to determine
556  * the message size in strdoioctl().
557  */
558 union ioctypes {
559 	struct iocblk	iocblk;
560 	struct copyreq	copyreq;
561 	struct copyresp	copyresp;
562 };
563 
564 /*
565  * Options structure for M_SETOPTS message.  This is sent upstream
566  * by a module or driver to set stream head options.
567  */
568 
569 struct stroptions {
570 	uint_t	so_flags;		/* options to set */
571 	short	so_readopt;		/* read option */
572 	ushort_t so_wroff;		/* write offset */
573 	ssize_t	so_minpsz;		/* minimum read packet size */
574 	ssize_t	so_maxpsz;		/* maximum read packet size */
575 	size_t	so_hiwat;		/* read queue high water mark */
576 	size_t	so_lowat;		/* read queue low water mark */
577 	unsigned char so_band;		/* band for water marks */
578 	ushort_t so_erropt;		/* error option */
579 	ssize_t	so_maxblk;		/* maximum message block size */
580 	ushort_t so_copyopt;		/* copy options (see stropts.h) */
581 	ushort_t so_tail;		/* space available at the end */
582 };
583 
584 /* flags for stream options set message */
585 
586 #define	SO_ALL		0x003f	/* set all old options */
587 #define	SO_READOPT	0x0001	/* set read option */
588 #define	SO_WROFF	0x0002	/* set write offset */
589 #define	SO_MINPSZ	0x0004	/* set min packet size */
590 #define	SO_MAXPSZ	0x0008	/* set max packet size */
591 #define	SO_HIWAT	0x0010	/* set high water mark */
592 #define	SO_LOWAT	0x0020	/* set low water mark */
593 #define	SO_MREADON	0x0040	/* set read notification ON */
594 #define	SO_MREADOFF	0x0080	/* set read notification OFF */
595 #define	SO_NDELON	0x0100	/* old TTY semantics for NDELAY reads/writes */
596 #define	SO_NDELOFF	0x0200	/* STREAMS semantics for NDELAY reads/writes */
597 #define	SO_ISTTY	0x0400	/* the stream is acting as a terminal */
598 #define	SO_ISNTTY	0x0800	/* the stream is not acting as a terminal */
599 #define	SO_TOSTOP	0x1000	/* stop on background writes to this stream */
600 #define	SO_TONSTOP	0x2000	/* do not stop on background writes to stream */
601 #define	SO_BAND		0x4000	/* water marks affect band */
602 #define	SO_DELIM	0x8000	/* messages are delimited */
603 #define	SO_NODELIM	0x010000	/* turn off delimiters */
604 #define	SO_STRHOLD	0x020000	/* No longer implemented */
605 #define	SO_ERROPT	0x040000	/* set error option */
606 #define	SO_COPYOPT	0x080000	/* copy option(s) present */
607 #define	SO_MAXBLK	0x100000	/* set maximum message block size */
608 #define	SO_TAIL		0x200000	/* set the extra allocated space */
609 
610 #ifdef _KERNEL
611 /*
612  * Structure for rw (read/write) procedure calls. A pointer
613  * to a struiod_t is passed as a parameter to the rwnext() call.
614  *
615  * Note: DEF_IOV_MAX is defined and used as it is in "fs/vncalls.c"
616  *	 as there isn't a formal definition of IOV_MAX ???
617  */
618 #define	DEF_IOV_MAX	16
619 
620 typedef struct struiod {
621 	mblk_t		*d_mp;		/* pointer to mblk (chain) */
622 	uio_t		d_uio;		/* uio info */
623 	iovec_t d_iov[DEF_IOV_MAX];	/* iov referenced by uio */
624 } struiod_t;
625 
626 /*
627  * Structure for information procedure calls.
628  */
629 typedef struct infod {
630 	unsigned char	d_cmd;		/* info info request command */
631 	unsigned char	d_res;		/* info info command results */
632 	int		d_bytes;	/* mblk(s) byte count */
633 	int		d_count;	/* count of mblk(s) */
634 	uio_t		*d_uiop;	/* pointer to uio struct */
635 } infod_t;
636 /*
637  * Values for d_cmd & d_res.
638  */
639 #define	INFOD_FIRSTBYTES	0x02	/* return msgbsize() of first mblk */
640 #define	INFOD_BYTES		0x04	/* return msgbsize() of all mblk(s) */
641 #define	INFOD_COUNT		0x08	/* return count of mblk(s) */
642 #define	INFOD_COPYOUT		0x10	/* copyout any M_DATA mblk(s) */
643 
644 #endif /* _KERNEL */
645 
646 /*
647  * Miscellaneous parameters and flags.
648  */
649 
650 /*
651  * Values for stream flag in open to indicate module open, clone open,
652  * and the return value for failure.
653  */
654 #define	MODOPEN 	0x1		/* open as a module */
655 #define	CLONEOPEN	0x2		/* clone open; pick own minor dev */
656 #define	OPENFAIL	-1		/* returned for open failure */
657 
658 /*
659  * Priority definitions for block allocation.
660  */
661 #define	BPRI_LO		1
662 #define	BPRI_MED	2
663 #define	BPRI_HI		3
664 
665 /*
666  * Value for packet size that denotes infinity
667  */
668 #define	INFPSZ		-1
669 
670 /*
671  * Flags for flushq()
672  */
673 #define	FLUSHALL	1	/* flush all messages */
674 #define	FLUSHDATA	0	/* don't flush control messages */
675 
676 /*
677  * Flag for transparent ioctls
678  */
679 #define	TRANSPARENT	(unsigned int)(-1)
680 
681 /*
682  * Stream head default high/low water marks
683  */
684 #define	STRHIGH 5120
685 #define	STRLOW	1024
686 
687 /*
688  * Block allocation parameters
689  */
690 #define	MAXIOCBSZ	1024		/* max ioctl data block size */
691 
692 /*
693  * qwriter perimeter types
694  */
695 #define	PERIM_INNER	1		/* The inner perimeter */
696 #define	PERIM_OUTER	2		/* The outer perimeter */
697 
698 /*
699  * Definitions of Streams macros and function interfaces.
700  */
701 
702 /*
703  * canenable - check if queue can be enabled by putq().
704  */
705 #define	canenable(q)	!((q)->q_flag & QNOENB)
706 
707 /*
708  * Test if data block type is one of the data messages (i.e. not a control
709  * message).
710  */
711 #define	datamsg(type) \
712 		((type) == M_DATA || \
713 		    (type) == M_MULTIDATA || \
714 		    (type) == M_PROTO || \
715 		    (type) == M_PCPROTO || \
716 		    (type) == M_DELAY)
717 
718 /*
719  * Extract queue class of message block.
720  */
721 #define	queclass(bp) (((bp)->b_datap->db_type >= QPCTL) ? QPCTL : QNORM)
722 
723 /*
724  * Align address on next lower word boundary.
725  */
726 #define	straln(a)	(caddr_t)((intptr_t)(a) & -(sizeof (int)-1))
727 
728 /*
729  * Find the max size of data block.
730  */
731 #define	bpsize(bp) ((unsigned int)(bp->b_datap->db_lim - bp->b_datap->db_base))
732 
733 #ifdef _KERNEL
734 
735 /*
736  * For two-byte M_ERROR messages: indication that a side does not have an error
737  */
738 #define	NOERROR	((unsigned char)-1)
739 
740 /*
741  * declarations of common routines
742  */
743 
744 extern mblk_t *allocb(size_t, uint_t);
745 extern mblk_t *desballoc(unsigned char *, size_t, uint_t, frtn_t *);
746 extern mblk_t *esballoc(unsigned char *, size_t, uint_t, frtn_t *);
747 extern bcache_t *bcache_create(char *, size_t, uint_t);
748 extern void bcache_destroy(bcache_t *);
749 extern mblk_t *bcache_allocb(bcache_t *, uint_t);
750 extern mblk_t *mkiocb(uint_t);
751 extern int testb(size_t, uint_t);
752 extern bufcall_id_t bufcall(size_t, uint_t, void (*)(void *), void *);
753 extern bufcall_id_t esbbcall(uint_t, void (*)(void *), void *);
754 extern void freeb(struct msgb *);
755 extern void freemsg(mblk_t *);
756 extern mblk_t *dupb(mblk_t *);
757 extern mblk_t *dupmsg(mblk_t *);
758 extern mblk_t *dupmsg_noloan(mblk_t *);
759 extern mblk_t *copyb(mblk_t *);
760 extern mblk_t *copymsg(mblk_t *);
761 extern void linkb(mblk_t *, mblk_t *);
762 extern mblk_t *unlinkb(mblk_t *);
763 extern mblk_t *reallocb(mblk_t *, size_t, uint_t);	/* private */
764 extern mblk_t *rmvb(mblk_t *, mblk_t *);
765 extern int pullupmsg(struct msgb *, ssize_t);
766 extern mblk_t *msgpullup(struct msgb *, ssize_t);
767 extern int adjmsg(struct msgb *, ssize_t);
768 extern size_t msgdsize(struct msgb *);
769 extern mblk_t *getq(queue_t *);
770 extern void rmvq(queue_t *, mblk_t *);
771 extern void flushq(queue_t *, int);
772 extern void flushq_common(queue_t *, int, int);
773 extern void flushband(queue_t *, unsigned char, int);
774 extern int canput(queue_t *);
775 extern int bcanput(queue_t *, unsigned char);
776 extern int canputnext(queue_t *);
777 extern int bcanputnext(queue_t *, unsigned char);
778 extern int putq(queue_t *, mblk_t *);
779 extern int putbq(queue_t *, mblk_t *);
780 extern int insq(queue_t *, mblk_t *, mblk_t *);
781 extern void put(queue_t *, mblk_t *);
782 extern void putnext(queue_t *, mblk_t *);
783 extern int putctl(queue_t *, int);
784 extern int putctl1(queue_t *, int, int);
785 extern int putnextctl(queue_t *, int);
786 extern int putnextctl1(queue_t *, int, int);
787 extern queue_t *backq(queue_t *);
788 extern void qreply(queue_t *, mblk_t *);
789 extern void qenable(queue_t *);
790 extern int qsize(queue_t *);
791 extern void noenable(queue_t *);
792 extern void enableok(queue_t *);
793 extern int strqset(queue_t *, qfields_t, unsigned char, intptr_t);
794 extern int strqget(queue_t *, qfields_t, unsigned char, void *);
795 extern void unbufcall(bufcall_id_t);
796 extern void qprocson(queue_t *);
797 extern void qprocsoff(queue_t *);
798 extern void freezestr(queue_t *);
799 extern void unfreezestr(queue_t *);
800 extern void qwait(queue_t *);
801 extern int qwait_sig(queue_t *);
802 extern boolean_t qwait_rw(queue_t *);
803 extern void qwriter(queue_t *, mblk_t *, void (*func)(), int);
804 extern timeout_id_t qtimeout(queue_t *, void (*func)(void *), void *, clock_t);
805 extern bufcall_id_t qbufcall(queue_t *, size_t, uint_t,
806     void (*)(void *), void *);
807 extern clock_t quntimeout(queue_t *, timeout_id_t);
808 extern void qunbufcall(queue_t *, bufcall_id_t);
809 extern void strwakeq(queue_t *, int);
810 extern int struioget(queue_t *, mblk_t *, struiod_t *, int);
811 extern int rwnext(queue_t *, struiod_t *);
812 extern int infonext(queue_t *, infod_t *);
813 extern int isuioq(queue_t *);
814 extern void create_putlocks(queue_t *, int);
815 
816 /*
817  * shared or externally configured data structures
818  */
819 extern int nstrpush;			/* maximum number of pushes allowed */
820 
821 #endif /* _KERNEL */
822 
823 #ifdef	__cplusplus
824 }
825 #endif
826 
827 #endif	/* _SYS_STREAM_H */
828