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