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