27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
5605445ddg * Common Development and Distribution License (the "License").
6605445ddg * You may not use this file except in compliance with the License.
77c478bdstevel@tonic-gate *
87c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bdstevel@tonic-gate * See the License for the specific language governing permissions
117c478bdstevel@tonic-gate * and limitations under the License.
127c478bdstevel@tonic-gate *
137c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bdstevel@tonic-gate *
197c478bdstevel@tonic-gate * CDDL HEADER END
207c478bdstevel@tonic-gate */
22de8c4a1Erik Nordmark * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bdstevel@tonic-gate * Use is subject to license terms.
246cfa0a7Andy Fiddaman * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
258e93525Bryan Cantrill * Copyright 2015 Joyent, Inc.  All rights reserved.
267c478bdstevel@tonic-gate */
287c478bdstevel@tonic-gate/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
29b4203d7Marcel Telka/*	  All Rights Reserved	*/
327c478bdstevel@tonic-gate#ifndef _SYS_STREAM_H
337c478bdstevel@tonic-gate#define	_SYS_STREAM_H
367c478bdstevel@tonic-gate * For source compatibility
377c478bdstevel@tonic-gate */
387c478bdstevel@tonic-gate#include <sys/isa_defs.h>
398329232Gordon Ross#if defined(_KERNEL) || defined(_FAKE_KERNEL)
40b819ceaGordon Ross#include <sys/kmem.h>
41b819ceaGordon Ross#include <sys/uio.h>
437c478bdstevel@tonic-gate#include <sys/poll.h>
447c478bdstevel@tonic-gate#include <sys/strmdep.h>
457c478bdstevel@tonic-gate#include <sys/cred.h>
467c478bdstevel@tonic-gate#include <sys/t_lock.h>
477c478bdstevel@tonic-gate#include <sys/model.h>
497c478bdstevel@tonic-gate#ifdef	__cplusplus
507c478bdstevel@tonic-gateextern "C" {
54ae35285meem * Data queue.
557c478bdstevel@tonic-gate *
56ae35285meem * NOTE: The *only* public fields are documented in queue(9S).
57ae35285meem *       Everything else is implementation-private.
587c478bdstevel@tonic-gate *
59ae35285meem * The locking rules for the queue_t structure are extremely subtle and vary
60ae35285meem * widely depending on the field in question.  As such, each field is
61ae35285meem * annotated according to the following legend:
627c478bdstevel@tonic-gate *
63ae35285meem *   Q9S: The field is documented in queue(9S) and may be accessed without
64ae35285meem *        locks by a STREAMS module when inside an entry point (e.g., put(9E)).
65ae35285meem *        However, no fields can be directly modified unless q_lock is held
66ae35285meem *        (which is not possible in a DDI compliant STREAMS module), with the
67ae35285meem *        following exceptions:
687c478bdstevel@tonic-gate *
69ae35285meem *	   - q_ptr: can be modified as per the rules of the STREAMS module.
70ae35285meem *		    The STREAMS framework ignores q_ptr and thus imposes *no*
71ae35285meem *		    locking rules on it.
72ae35285meem *         - q_qinfo: can be modified before qprocson().
73ae35285meem *
74ae35285meem *	   - q_minpsz, q_maxpsz, q_hiwat, q_lowat: can be modified as per the
75ae35285meem *		    rules of the STREAMS module.  The STREAMS framework never
76ae35285meem *		    modifies these fields, and is tolerant of temporarily
77ae35285meem *		    stale field values.
78ae35285meem *
79ae35285meem *	  In general, the STREAMS framework employs one of the following
80ae35285meem *	  techniques to ensure STREAMS modules can safely access Q9S fields:
81ae35285meem *
82ae35285meem *	   - The field is only modified by the framework when the stream is
83ae35285meem *	     locked with strlock() (q_next).
84ae35285meem *
85ae35285meem *	   - The field is modified by the framework, but the modifies are
86ae35285meem *	     atomic, and temporarily stale values are harmless (q_count,
87ae35285meem *	     q_first, q_last).
88ae35285meem *
89ae35285meem *	   - The field is modified by the framework, but the field's visible
90ae35285meem *	     values are either constant or directly under the control
91ae35285meem *	     of the STREAMS module itself (q_flag).
92ae35285meem *
93ae35285meem *   QLK: The field must be accessed or modified under q_lock, except when
94ae35285meem *        the stream has been locked with strlock().  If multiple q_locks must
95ae35285meem *        be acquired, q_locks at higher addresses must be taken first.
96ae35285meem *
97ae35285meem *   STR: The field can be accessed without a lock, but must be modified under
98ae35285meem *	  strlock().
99ae35285meem *
100ae35285meem *   SQLK: The field must be accessed or modified under SQLOCK().
101ae35285meem *
102ae35285meem *   NOLK: The field can be accessed without a lock, but can only be modified
103ae35285meem *	   when the queue_t is not known to any other threads.
104ae35285meem *
105ae35285meem *   SVLK: The field must be accessed or modified under the service_queue lock.
106ae35285meem *         Note that service_lock must be taken after any needed q_locks,
107ae35285meem *	   and that no other lock should be taken while service_lock is held.
108ae35285meem *
109ae35285meem * In addition, it is always acceptable to modify a field that is not yet
110ae35285meem * known to any other threads -- and other special case exceptions exist in
111ae35285meem * the code.  Also, q_lock is used with q_wait to implement a stream head
112ae35285meem * monitor for reads and writes.
1137c478bdstevel@tonic-gate */
114ae35285meemtypedef struct queue {
115ae35285meem	struct qinit	*q_qinfo;	/* Q9S: Q processing procedure  */
116ae35285meem	struct msgb	*q_first;	/* Q9S: first message in Q	*/
117ae35285meem	struct msgb	*q_last;	/* Q9S: last message in Q	*/
118ae35285meem	struct queue	*q_next;	/* Q9S: next Q in stream	*/
119ae35285meem	struct queue	*q_link;	/* SVLK: next Q for scheduling	*/
120ae35285meem	void		*q_ptr;		/* Q9S: module-specific data	*/
121ae35285meem	size_t		q_count;	/* Q9S: number of bytes on Q	*/
122ae35285meem	uint_t		q_flag;		/* Q9S: Q state			*/
123ae35285meem	ssize_t		q_minpsz;	/* Q9S: smallest packet OK on Q */
124ae35285meem	ssize_t		q_maxpsz;	/* Q9S: largest packet OK on Q	*/
125ae35285meem	size_t		q_hiwat;	/* Q9S: Q high water mark	*/
126ae35285meem	size_t		q_lowat;	/* Q9S: Q low water mark	*/
127ae35285meem	struct qband	*q_bandp;	/* QLK: band flow information	*/
128ae35285meem	kmutex_t	q_lock;		/* NOLK: structure lock		*/
1295e1743fToomas Soome	struct stdata	*q_stream;	/* NOLK: stream backpointer	*/
1305e1743fToomas Soome	struct syncq	*q_syncq;	/* NOLK: associated syncq	*/
131ae35285meem	unsigned char	q_nband;	/* QLK: number of bands		*/
132ae35285meem	kcondvar_t	q_wait;		/* NOLK: read/write sleep CV	*/
133ae35285meem	struct queue	*q_nfsrv;	/* STR: next Q with svc routine */
134ae35285meem	ushort_t	q_draining;	/* QLK: Q is draining		*/
135ae35285meem	short		q_struiot;	/* QLK: sync streams Q UIO mode	*/
136ae35285meem	clock_t		q_qtstamp;	/* QLK: when Q was enabled	*/
137ae35285meem	size_t		q_mblkcnt;	/* QLK: mblk count		*/
138ae35285meem	uint_t		q_syncqmsgs;	/* QLK: syncq message count	*/
139ae35285meem	size_t		q_rwcnt;	/* QLK: # threads in rwnext()	*/
140ae35285meem	pri_t		q_spri;		/* QLK: Q scheduling priority	*/
1427c478bdstevel@tonic-gate	/*
143ae35285meem	 * Syncq scheduling
1447c478bdstevel@tonic-gate	 */
145ae35285meem	struct msgb	*q_sqhead;	/* QLK: first syncq message	*/
1465e1743fToomas Soome	struct msgb	*q_sqtail;	/* QLK: last syncq message	*/
147ae35285meem	struct queue	*q_sqnext;	/* SQLK: next Q on syncq list	*/
1485e1743fToomas Soome	struct queue	*q_sqprev;	/* SQLK: prev Q on syncq list	*/
149ae35285meem	uint_t		q_sqflags;	/* SQLK: syncq flags		*/
150ae35285meem	clock_t		q_sqtstamp;	/* SQLK: when Q was scheduled for sq */
1527c478bdstevel@tonic-gate	/*
153ae35285meem	 * NOLK: Reference to the queue's module's implementation
154ae35285meem	 * structure. This will be NULL for queues associated with drivers.
1557c478bdstevel@tonic-gate	 */
1567c478bdstevel@tonic-gate	struct fmodsw_impl	*q_fp;
1577c478bdstevel@tonic-gate} queue_t;
1607c478bdstevel@tonic-gate * Queue flags; unused flags not documented in queue(9S) can be recycled.
1617c478bdstevel@tonic-gate */
1627c478bdstevel@tonic-gate#define	QENAB		0x00000001	/* Queue is already enabled to run */
1637c478bdstevel@tonic-gate#define	QWANTR		0x00000002	/* Someone wants to read Q	*/
1647c478bdstevel@tonic-gate#define	QWANTW		0x00000004	/* Someone wants to write Q	*/
1657c478bdstevel@tonic-gate#define	QFULL		0x00000008	/* Q is considered full		*/
1667c478bdstevel@tonic-gate#define	QREADR		0x00000010	/* This is the reader (first) Q	*/
1677c478bdstevel@tonic-gate#define	QUSE		0x00000020	/* This queue in use (allocation) */
1687c478bdstevel@tonic-gate#define	QNOENB		0x00000040	/* Don't enable Q via putq	*/
1697c478bdstevel@tonic-gate#define	QWANTRMQSYNC	0x00000080	/* Want to remove sync stream Q */
1707c478bdstevel@tonic-gate#define	QBACK		0x00000100	/* queue has been back-enabled	*/
1717c478bdstevel@tonic-gate/*	UNUSED		0x00000200	   was QHLIST			*/
1725e1743fToomas Soome/*	UNUSED		0x00000400	   was QUNSAFE			*/
1737c478bdstevel@tonic-gate#define	QPAIR		0x00000800	/* per queue-pair syncq		*/
1745e1743fToomas Soome#define	QPERQ		0x00001000	/* per queue-instance syncq	*/
1757c478bdstevel@tonic-gate#define	QPERMOD		0x00002000	/* per module syncq		*/
1767c478bdstevel@tonic-gate#define	QMTSAFE		0x00004000	/* stream module is MT-safe	*/
1777c478bdstevel@tonic-gate#define	QMTOUTPERIM	0x00008000	/* Has outer perimeter		*/
1797c478bdstevel@tonic-gate					/* all MT type flags		*/
1807c478bdstevel@tonic-gate#define	QINSERVICE	0x00010000	/* service routine executing	*/
1817c478bdstevel@tonic-gate#define	QWCLOSE		0x00020000	/* will not be enabled		*/
1827c478bdstevel@tonic-gate#define	QEND		0x00040000	/* last queue in stream		*/
1837c478bdstevel@tonic-gate#define	QWANTWSYNC	0x00080000	/* Streamhead wants to write Q	*/
1847c478bdstevel@tonic-gate#define	QSYNCSTR	0x00100000	/* Q supports Synchronous STREAMS */
1857c478bdstevel@tonic-gate#define	QISDRV		0x00200000	/* the Queue is attached to a driver */
1867c478bdstevel@tonic-gate/*	UNUSED		0x00400000	   was QHOT			*/
1877c478bdstevel@tonic-gate/*	UNUSED		0x00800000	   was QNEXTHOT			*/
1885e1743fToomas Soome/*	UNUSED		0x01000000	   was _QNEXTLESS		*/
1897c478bdstevel@tonic-gate#define	_QINSERTING	0x04000000	/* Private, module is being inserted */
1907c478bdstevel@tonic-gate#define	_QREMOVING	0x08000000	/* Private, module is being removed */
1917c478bdstevel@tonic-gate#define	_QASSOCIATED	0x10000000	/* queue is associated with a device */
192ff550d0masputra#define	_QDIRECT	0x20000000	/* Private; transport module uses */
193ff550d0masputra					/* direct interface to/from sockfs */
1946cfa0a7Andy Fiddaman#define	_QSINGLE_INSTANCE	0x40000000	/* Private; module may only */
1956cfa0a7Andy Fiddaman						/* be pushed once */
1977c478bdstevel@tonic-gate/* queue sqflags (protected by SQLOCK). */
1987c478bdstevel@tonic-gate#define	Q_SQQUEUED	0x01		/* Queue is in the syncq list */
199ae35285meem#define	Q_SQDRAINING	0x02		/* Servicing syncq msgs.	*/
2007c478bdstevel@tonic-gate					/* This is also noted by the	*/
2017c478bdstevel@tonic-gate					/* q_draining field, but this one is */
2027c478bdstevel@tonic-gate					/* protected by SQLOCK */
2057c478bdstevel@tonic-gate * Structure that describes the separate information
2067c478bdstevel@tonic-gate * for each priority band in the queue.
2077c478bdstevel@tonic-gate */
2087c478bdstevel@tonic-gatetypedef struct qband {
2097c478bdstevel@tonic-gate	struct qband	*qb_next;	/* next band's info */
2107c478bdstevel@tonic-gate	size_t		qb_count;	/* number of bytes in band */
2117c478bdstevel@tonic-gate	struct msgb	*qb_first;	/* beginning of band's data */
2127c478bdstevel@tonic-gate	struct msgb	*qb_last;	/* end of band's data */
2137c478bdstevel@tonic-gate	size_t		qb_hiwat;	/* high water mark for band */
2147c478bdstevel@tonic-gate	size_t		qb_lowat;	/* low water mark for band */
2157c478bdstevel@tonic-gate	uint_t		qb_flag;	/* see below */
2167c478bdstevel@tonic-gate	size_t		qb_mblkcnt;	/* mblk counter for runaway msgs */
2177c478bdstevel@tonic-gate} qband_t;
2207c478bdstevel@tonic-gate * qband flags
2217c478bdstevel@tonic-gate */
2227c478bdstevel@tonic-gate#define	QB_FULL		0x01		/* band is considered full */
2237c478bdstevel@tonic-gate#define	QB_WANTW	0x02		/* Someone wants to write to band */
2247c478bdstevel@tonic-gate#define	QB_BACK		0x04		/* queue has been back-enabled */
2277c478bdstevel@tonic-gate * Maximum number of bands.
2287c478bdstevel@tonic-gate */
2297c478bdstevel@tonic-gate#define	NBAND	256
2327c478bdstevel@tonic-gate * Fields that can be manipulated through strqset() and strqget().
2337c478bdstevel@tonic-gate */
2347c478bdstevel@tonic-gatetypedef enum qfields {
2357c478bdstevel@tonic-gate	QHIWAT	= 0,		/* q_hiwat or qb_hiwat */
2367c478bdstevel@tonic-gate	QLOWAT	= 1,		/* q_lowat or qb_lowat */
2377c478bdstevel@tonic-gate	QMAXPSZ	= 2,		/* q_maxpsz */
2387c478bdstevel@tonic-gate	QMINPSZ	= 3,		/* q_minpsz */
2397c478bdstevel@tonic-gate	QCOUNT	= 4,		/* q_count or qb_count */
2407c478bdstevel@tonic-gate	QFIRST	= 5,		/* q_first or qb_first */
2417c478bdstevel@tonic-gate	QLAST	= 6,		/* q_last or qb_last */
2427c478bdstevel@tonic-gate	QFLAG	= 7,		/* q_flag or qb_flag */
2437c478bdstevel@tonic-gate	QSTRUIOT = 8,		/* q_struiot */
2447c478bdstevel@tonic-gate	QBAD	= 9
2457c478bdstevel@tonic-gate} qfields_t;
2487c478bdstevel@tonic-gate * Module information structure
2497c478bdstevel@tonic-gate */
2507c478bdstevel@tonic-gatestruct module_info {
2517c478bdstevel@tonic-gate	ushort_t mi_idnum;		/* module id number */
2525e1743fToomas Soome	char	*mi_idname;		/* module name */
2537c478bdstevel@tonic-gate	ssize_t	mi_minpsz;		/* min packet size accepted */
2547c478bdstevel@tonic-gate	ssize_t	mi_maxpsz;		/* max packet size accepted */
2557c478bdstevel@tonic-gate	size_t	mi_hiwat;		/* hi-water mark */
2565e1743fToomas Soome	size_t	mi_lowat;		/* lo-water mark */
2607c478bdstevel@tonic-gate * queue information structure (with Synchronous STREAMS extensions)
2617c478bdstevel@tonic-gate */
2625e1743fToomas Soome
2635e1743fToomas Soometypedef struct msgb mblk_t;
2645e1743fToomas Soometypedef struct struiod struiod_t;
2655e1743fToomas Soometypedef struct infod infod_t;
2665e1743fToomas Soome
2675e1743fToomas Soometypedef	int (*qi_putp_t)(queue_t *, mblk_t *);
2685e1743fToomas Soometypedef	int (*qi_srvp_t)(queue_t *);
2695e1743fToomas Soometypedef	int (*qi_qopen_t)(queue_t *, dev_t *, int, int, cred_t *);
2705e1743fToomas Soometypedef	int (*qi_qclose_t)(queue_t *, int, cred_t *);
2715e1743fToomas Soometypedef	int (*qi_qadmin_t)(void);
2725e1743fToomas Soometypedef	int (*qi_rwp_t)(queue_t *, struiod_t *);
2735e1743fToomas Soometypedef	int (*qi_infop_t)(queue_t *, infod_t *);
2745e1743fToomas Soome
2757c478bdstevel@tonic-gatestruct	qinit {
2765e1743fToomas Soome	qi_putp_t	qi_putp;	/* put procedure */
2775e1743fToomas Soome	qi_srvp_t	qi_srvp;	/* service procedure */
2785e1743fToomas Soome	qi_qopen_t	qi_qopen;	/* called on startup */
2795e1743fToomas Soome	qi_qclose_t	qi_qclose;	/* called on finish */
2805e1743fToomas Soome	qi_qadmin_t	qi_qadmin;	/* for future use */
2817c478bdstevel@tonic-gate	struct module_info *qi_minfo;	/* module information structure */
2827c478bdstevel@tonic-gate	struct module_stat *qi_mstat;	/* module statistics structure */
2835e1743fToomas Soome	qi_rwp_t	qi_rwp;		/* r/w procedure */
2845e1743fToomas Soome	qi_infop_t	qi_infop;	/* information procedure */
2855e1743fToomas Soome	int		qi_struiot;	/* stream uio type for struio() */
2897c478bdstevel@tonic-gate * Values for qi_struiot and q_struiot:
2907c478bdstevel@tonic-gate */
2917c478bdstevel@tonic-gate#define	STRUIOT_NONE		-1	/* doesn't support struio() */
2927c478bdstevel@tonic-gate#define	STRUIOT_DONTCARE	0	/* use current uiomove() (default) */
2937c478bdstevel@tonic-gate#define	STRUIOT_STANDARD	1	/* use standard uiomove() */
2967c478bdstevel@tonic-gate * Streamtab (used in cdevsw and fmodsw to point to module or driver)
2977c478bdstevel@tonic-gate */
2987c478bdstevel@tonic-gatestruct streamtab {
2997c478bdstevel@tonic-gate	struct qinit *st_rdinit;
3007c478bdstevel@tonic-gate	struct qinit *st_wrinit;
3017c478bdstevel@tonic-gate	struct qinit *st_muxrinit;
3027c478bdstevel@tonic-gate	struct qinit *st_muxwinit;
3067c478bdstevel@tonic-gate * Structure sent to mux drivers to indicate a link.
3077c478bdstevel@tonic-gate */
3087c478bdstevel@tonic-gatestruct linkblk {
3097c478bdstevel@tonic-gate	queue_t *l_qtop;	/* lowest level write queue of upper stream */
3107c478bdstevel@tonic-gate				/* (set to NULL for persistent links) */
3117c478bdstevel@tonic-gate	queue_t *l_qbot;	/* highest level write queue of lower stream */
3127c478bdstevel@tonic-gate	int	l_index;	/* index for lower stream. */
3167c478bdstevel@tonic-gate * Esballoc data buffer freeing routine
3177c478bdstevel@tonic-gate */
3187c478bdstevel@tonic-gatetypedef struct free_rtn {
3197c478bdstevel@tonic-gate	void	(*free_func)();
3207c478bdstevel@tonic-gate	caddr_t	free_arg;
3217c478bdstevel@tonic-gate} frtn_t;
3247c478bdstevel@tonic-gate * Data block descriptor
3257c478bdstevel@tonic-gate *
3267c478bdstevel@tonic-gate * NOTE: db_base, db_lim, db_ref and db_type are the *only* public fields,
3277c478bdstevel@tonic-gate * as described in datab(9S).  Everything else is implementation-private.
3287c478bdstevel@tonic-gate */
3307c478bdstevel@tonic-gate#define	DBLK_REFMAX	255U
3327c478bdstevel@tonic-gatetypedef struct datab {
3337c478bdstevel@tonic-gate	frtn_t		*db_frtnp;
3347c478bdstevel@tonic-gate	unsigned char	*db_base;
3357c478bdstevel@tonic-gate	unsigned char	*db_lim;
3367c478bdstevel@tonic-gate	unsigned char	db_ref;
3377c478bdstevel@tonic-gate	unsigned char	db_type;
3387c478bdstevel@tonic-gate	unsigned char	db_flags;
3397c478bdstevel@tonic-gate	unsigned char	db_struioflag;
3407c478bdstevel@tonic-gate	pid_t		db_cpid;	/* cached pid, needs verification */
3417c478bdstevel@tonic-gate	void		*db_cache;	/* kmem cache descriptor */
3427c478bdstevel@tonic-gate	struct msgb	*db_mblk;
3437c478bdstevel@tonic-gate	void		(*db_free)(struct msgb *, struct datab *);
3447c478bdstevel@tonic-gate	void		(*db_lastfree)(struct msgb *, struct datab *);
3457c478bdstevel@tonic-gate	intptr_t	db_cksumstart;
3467c478bdstevel@tonic-gate	intptr_t	db_cksumend;
3477c478bdstevel@tonic-gate	intptr_t	db_cksumstuff;
3487c478bdstevel@tonic-gate	union {
3497c478bdstevel@tonic-gate		double enforce_alignment;
3507c478bdstevel@tonic-gate		unsigned char data[8];
3517c478bdstevel@tonic-gate		struct {
3527c478bdstevel@tonic-gate			union {
3537c478bdstevel@tonic-gate				uint32_t u32;
3547c478bdstevel@tonic-gate				uint16_t u16;
3557c478bdstevel@tonic-gate			} cksum_val;    /* used to store calculated cksum */
3567c478bdstevel@tonic-gate			uint16_t flags;
3577c478bdstevel@tonic-gate			uint16_t pad;
3587c478bdstevel@tonic-gate		} cksum;
3597c478bdstevel@tonic-gate		/*
3607c478bdstevel@tonic-gate		 * Union used for future extensions (pointer to data ?).
3617c478bdstevel@tonic-gate		 */
3627c478bdstevel@tonic-gate	} db_struioun;
363ae35285meem	struct fthdr	*db_fthdr;
3647c478bdstevel@tonic-gate	cred_t		*db_credp;	/* credential */
3657c478bdstevel@tonic-gate} dblk_t;
3677c478bdstevel@tonic-gate#define	db_cksum16	db_struioun.cksum.cksum_val.u16
3687c478bdstevel@tonic-gate#define	db_cksum32	db_struioun.cksum.cksum_val.u32
3717c478bdstevel@tonic-gate * Accessor macros for private dblk_t fields (the rest are in <sys/strsun.h>).
3727c478bdstevel@tonic-gate */
3737c478bdstevel@tonic-gate#define	DB_CPID(mp)		((mp)->b_datap->db_cpid)
3747c478bdstevel@tonic-gate#define	DB_CRED(mp)		((mp)->b_datap->db_credp)
3757c478bdstevel@tonic-gate#define	DB_FTHDR(mp)		((mp)->b_datap->db_fthdr)
377605445ddg * Used by GLDv2 to store the TCI information.
378605445ddg */
379605445ddg#define	DB_TCI(mp)		((mp)->b_datap->db_struioun.cksum.pad)
3827c478bdstevel@tonic-gate * Message block descriptor
3837c478bdstevel@tonic-gate */
3845e1743fToomas Soomestruct	msgb {
3857c478bdstevel@tonic-gate	struct	msgb	*b_next;
3867c478bdstevel@tonic-gate	struct  msgb	*b_prev;
3877c478bdstevel@tonic-gate	struct	msgb	*b_cont;
3887c478bdstevel@tonic-gate	unsigned char	*b_rptr;
3897c478bdstevel@tonic-gate	unsigned char	*b_wptr;
3905e1743fToomas Soome	struct datab	*b_datap;
3917c478bdstevel@tonic-gate	unsigned char	b_band;
3927c478bdstevel@tonic-gate	unsigned char	b_tag;
3937c478bdstevel@tonic-gate	unsigned short	b_flag;
3947c478bdstevel@tonic-gate	queue_t		*b_queue;	/* for sync queues */
3955e1743fToomas Soome};
3987c478bdstevel@tonic-gate * bcache descriptor
3997c478bdstevel@tonic-gate */
4007c478bdstevel@tonic-gatetypedef	struct	bcache {
4017c478bdstevel@tonic-gate	kmutex_t		mutex;
4027c478bdstevel@tonic-gate	struct kmem_cache	*buffer_cache;
4037c478bdstevel@tonic-gate	struct kmem_cache	*dblk_cache;
4047c478bdstevel@tonic-gate	int			alloc;
4057c478bdstevel@tonic-gate	int			destroy;
4067c478bdstevel@tonic-gate	size_t			size;
4077c478bdstevel@tonic-gate	uint_t			align;
4087c478bdstevel@tonic-gate} bcache_t;
4117c478bdstevel@tonic-gate * db_flags values (all implementation private!)
4127c478bdstevel@tonic-gate */
413381a2a9dr#define	DBLK_REFMIN		0x01	/* min refcnt stored in low bit */
414381a2a9dr#define	DBLK_COOKED		0x02	/* message has been processed once */
4151716904brutus#define	DBLK_UIOA		0x04	/* uioamove() is pending */
4187c478bdstevel@tonic-gate * db_struioflag values:
4197c478bdstevel@tonic-gate */
4207c478bdstevel@tonic-gate#define	STRUIO_SPEC	0x01	/* struio{get,put}() special mblk */
4217c478bdstevel@tonic-gate#define	STRUIO_DONE	0x02	/* struio done (could be partial) */
4227c478bdstevel@tonic-gate#define	STRUIO_IP	0x04	/* IP checksum stored in db_struioun */
4237c478bdstevel@tonic-gate#define	STRUIO_ZC	0x08	/* mblk eligible for zero-copy */
4247c478bdstevel@tonic-gate#define	STRUIO_ZCNOTIFY	0x10	/* notify stream head when mblk acked */
4277c478bdstevel@tonic-gate * Message flags.  These are interpreted by the stream head.
4287c478bdstevel@tonic-gate */
4297c478bdstevel@tonic-gate#define	MSGMARK		0x01	/* last byte of message is "marked" */
4307c478bdstevel@tonic-gate#define	MSGNOLOOP	0x02	/* don't loop message around to */
4317c478bdstevel@tonic-gate				/* write side of stream */
4327c478bdstevel@tonic-gate#define	MSGDELIM	0x04	/* message is delimited */
4337c478bdstevel@tonic-gate/*	UNUSED		0x08	   was MSGNOGET (can be recycled) */
4347c478bdstevel@tonic-gate#define	MSGMARKNEXT	0x10	/* Private: first byte of next msg marked */
4357c478bdstevel@tonic-gate#define	MSGNOTMARKNEXT	0x20	/* Private: ... not marked */
436bd670b3Erik Nordmark#define	MSGWAITSYNC	0x40	/* Private: waiting for sync squeue enter */
4397c478bdstevel@tonic-gate * Streams message types.
4407c478bdstevel@tonic-gate */
4437c478bdstevel@tonic-gate * Data and protocol messages (regular and priority)
4447c478bdstevel@tonic-gate */
4457c478bdstevel@tonic-gate#define	M_DATA		0x00		/* regular data */
4467c478bdstevel@tonic-gate#define	M_PROTO		0x01		/* protocol control */
4477c478bdstevel@tonic-gate#define	M_MULTIDATA	0x02		/* reserved for Multidata use only */
4507c478bdstevel@tonic-gate * Control messages (regular and priority)
4517c478bdstevel@tonic-gate */
4527c478bdstevel@tonic-gate#define	M_BREAK		0x08		/* line break */
4537c478bdstevel@tonic-gate#define	M_PASSFP	0x09		/* pass file pointer */
4547c478bdstevel@tonic-gate#define	M_EVENT		0x0a		/* Obsoleted: do not use */
4557c478bdstevel@tonic-gate#define	M_SIG		0x0b		/* generate process signal */
4567c478bdstevel@tonic-gate#define	M_DELAY		0x0c		/* real-time xmit delay (1 param) */
4577c478bdstevel@tonic-gate#define	M_CTL		0x0d		/* device-specific control message */
4587c478bdstevel@tonic-gate#define	M_IOCTL		0x0e		/* ioctl; set/get params */
4597c478bdstevel@tonic-gate#define	M_SETOPTS	0x10		/* set various stream head options */
4607c478bdstevel@tonic-gate#define	M_RSE		0x11		/* reserved for RSE use only */
4637c478bdstevel@tonic-gate * Control messages (high priority; go to head of queue)
4647c478bdstevel@tonic-gate */
4657c478bdstevel@tonic-gate#define	M_IOCACK	0x81		/* acknowledge ioctl */
4667c478bdstevel@tonic-gate#define	M_IOCNAK	0x82		/* negative ioctl acknowledge */
4677c478bdstevel@tonic-gate#define	M_PCPROTO	0x83		/* priority proto message */
4687c478bdstevel@tonic-gate#define	M_PCSIG		0x84		/* generate process signal */
4697c478bdstevel@tonic-gate#define	M_READ		0x85		/* generate read notification */
4707c478bdstevel@tonic-gate#define	M_FLUSH		0x86		/* flush your queues */
4717c478bdstevel@tonic-gate#define	M_STOP		0x87		/* stop transmission immediately */
4727c478bdstevel@tonic-gate#define	M_START		0x88		/* restart transmission after stop */
4737c478bdstevel@tonic-gate#define	M_HANGUP	0x89		/* line disconnect */
4747c478bdstevel@tonic-gate#define	M_ERROR		0x8a		/* send error to stream head */
4757c478bdstevel@tonic-gate#define	M_COPYIN	0x8b		/* request to copyin data */
4767c478bdstevel@tonic-gate#define	M_COPYOUT	0x8c		/* request to copyout data */
4777c478bdstevel@tonic-gate#define	M_IOCDATA	0x8d		/* response to M_COPYIN and M_COPYOUT */
4787c478bdstevel@tonic-gate#define	M_PCRSE		0x8e		/* reserved for RSE use only */
4797c478bdstevel@tonic-gate#define	M_STOPI		0x8f		/* stop reception immediately */
4807c478bdstevel@tonic-gate#define	M_STARTI	0x90		/* restart reception after stop */
4817c478bdstevel@tonic-gate#define	M_PCEVENT	0x91		/* Obsoleted: do not use */
4827c478bdstevel@tonic-gate#define	M_UNHANGUP	0x92		/* line reconnect, sigh */
483ca9327ameem#define	M_CMD		0x93		/* out-of-band ioctl command */
4867c478bdstevel@tonic-gate * Queue message class definitions.
4877c478bdstevel@tonic-gate */
4887c478bdstevel@tonic-gate#define	QNORM		0x00		/* normal priority messages */
4897c478bdstevel@tonic-gate#define	QPCTL		0x80		/* high priority cntrl messages */
4927c478bdstevel@tonic-gate *  IOCTL structure - this structure is the format of the M_IOCTL message type.
4937c478bdstevel@tonic-gate */
4947c478bdstevel@tonic-gate#if	defined(_LP64)
4957c478bdstevel@tonic-gatestruct iocblk {
4965e1743fToomas Soome	int	ioc_cmd;		/* ioctl command type */
4977c478bdstevel@tonic-gate	cred_t	*ioc_cr;		/* full credentials */
4987c478bdstevel@tonic-gate	uint_t	ioc_id;			/* ioctl id */
4997c478bdstevel@tonic-gate	uint_t	ioc_flag;		/* see below */
5007c478bdstevel@tonic-gate	size_t	ioc_count;		/* count of bytes in data field */
5017c478bdstevel@tonic-gate	int	ioc_rval;		/* return value  */
5027c478bdstevel@tonic-gate	int	ioc_error;		/* error code */
5057c478bdstevel@tonic-gatestruct iocblk {
5065e1743fToomas Soome	int	ioc_cmd;		/* ioctl command type */
5077c478bdstevel@tonic-gate	cred_t	*ioc_cr;		/* full credentials */
5087c478bdstevel@tonic-gate	uint_t	ioc_id;			/* ioctl id */
5097c478bdstevel@tonic-gate	size_t	ioc_count;		/* count of bytes in data field */
5107c478bdstevel@tonic-gate	int	ioc_error;		/* error code */
5117c478bdstevel@tonic-gate	int	ioc_rval;		/* return value  */
5127c478bdstevel@tonic-gate	int	ioc_fill1;
5137c478bdstevel@tonic-gate	uint_t	ioc_flag;		/* see below */
5147c478bdstevel@tonic-gate	int	ioc_filler[2];		/* reserved for future use */
5167c478bdstevel@tonic-gate#endif	/* _LP64 */
5187c478bdstevel@tonic-gatetypedef	struct iocblk	*IOCP;
5207c478bdstevel@tonic-gate/* {ioc,cp}_flags values */
5227c478bdstevel@tonic-gate#define	IOC_MODELS	DATAMODEL_MASK	/* Note: 0x0FF00000 */
5237c478bdstevel@tonic-gate#define	IOC_ILP32	DATAMODEL_ILP32	/* ioctl origin is ILP32 */
5247c478bdstevel@tonic-gate#define	IOC_LP64	DATAMODEL_LP64	/* ioctl origin is LP64 */
5257c478bdstevel@tonic-gate#define	IOC_NATIVE	DATAMODEL_NATIVE
5267c478bdstevel@tonic-gate#define	IOC_NONE	DATAMODEL_NONE	/* dummy comparison value */
5297c478bdstevel@tonic-gate *	Is the ioctl data formatted for our native model?
5307c478bdstevel@tonic-gate */
5317c478bdstevel@tonic-gate#define	IOC_CONVERT_FROM(iocp)	ddi_model_convert_from( \
5327c478bdstevel@tonic-gate				    ((struct iocblk *)iocp)->ioc_flag)
5357c478bdstevel@tonic-gate * structure for the M_COPYIN and M_COPYOUT message types.
5367c478bdstevel@tonic-gate */
5377c478bdstevel@tonic-gate#if	defined(_LP64)
5387c478bdstevel@tonic-gatestruct copyreq {
5397c478bdstevel@tonic-gate	int	cq_cmd;			/* ioctl command (from ioc_cmd) */
5407c478bdstevel@tonic-gate	cred_t	*cq_cr;			/* full credentials (from ioc_cmd) */
5417c478bdstevel@tonic-gate	uint_t	cq_id;			/* ioctl id (from ioc_id) */
5427c478bdstevel@tonic-gate	uint_t	cq_flag;		/* must be zero */
5437c478bdstevel@tonic-gate	mblk_t	*cq_private;		/* private state information */
5447c478bdstevel@tonic-gate	caddr_t	cq_addr;		/* address to copy data to/from */
5457c478bdstevel@tonic-gate	size_t	cq_size;		/* number of bytes to copy */
5487c478bdstevel@tonic-gatestruct copyreq {
5497c478bdstevel@tonic-gate	int	cq_cmd;			/* ioctl command (from ioc_cmd) */
5507c478bdstevel@tonic-gate	cred_t	*cq_cr;			/* full credentials */
5517c478bdstevel@tonic-gate	uint_t	cq_id;			/* ioctl id (from ioc_id) */
5527c478bdstevel@tonic-gate	caddr_t	cq_addr;		/* address to copy data to/from */
5537c478bdstevel@tonic-gate	size_t	cq_size;		/* number of bytes to copy */
5547c478bdstevel@tonic-gate	uint_t	cq_flag;		/* must be zero */
5557c478bdstevel@tonic-gate	mblk_t	*cq_private;		/* private state information */
5567c478bdstevel@tonic-gate	int	cq_filler[4];		/* reserved for future use */
5587c478bdstevel@tonic-gate#endif	/* _LP64 */
5617c478bdstevel@tonic-gate * structure for the M_IOCDATA message type.
5627c478bdstevel@tonic-gate */
5637c478bdstevel@tonic-gate#if	defined(_LP64)
5647c478bdstevel@tonic-gatestruct copyresp {
5657c478bdstevel@tonic-gate	int	cp_cmd;			/* ioctl command (from ioc_cmd) */
5667c478bdstevel@tonic-gate	cred_t	*cp_cr;			/* full credentials (from ioc_cmd) */
5677c478bdstevel@tonic-gate	uint_t	cp_id;			/* ioctl id (from ioc_id) */
5687c478bdstevel@tonic-gate	uint_t	cp_flag;		/* datamodel IOC_ flags; see above */
5697c478bdstevel@tonic-gate	mblk_t *cp_private;		/* private state information */
5707c478bdstevel@tonic-gate	caddr_t	cp_rval;		/* status of request: 0 -> success */
5715e1743fToomas Soome					/*		non-zero -> failure */
5747c478bdstevel@tonic-gatestruct copyresp {
5757c478bdstevel@tonic-gate	int	cp_cmd;			/* ioctl command (from ioc_cmd) */
5767c478bdstevel@tonic-gate	cred_t	*cp_cr;			/* full credentials */
5777c478bdstevel@tonic-gate	uint_t	cp_id;			/* ioctl id (from ioc_id) */
5787c478bdstevel@tonic-gate	caddr_t	cp_rval;		/* status of request: 0 -> success */
5795e1743fToomas Soome					/*		non-zero -> failure */
5807c478bdstevel@tonic-gate	size_t	cp_pad1;
5817c478bdstevel@tonic-gate	uint_t	cp_pad2;
5827c478bdstevel@tonic-gate	mblk_t *cp_private;		/* private state information */
5837c478bdstevel@tonic-gate	uint_t	cp_flag;		/* datamodel IOC_ flags; see above */
5847c478bdstevel@tonic-gate	int	cp_filler[3];
5867c478bdstevel@tonic-gate#endif	/* _LP64 */
5897c478bdstevel@tonic-gate * Since these structures are all intended to travel in the same message
5907c478bdstevel@tonic-gate * at different stages of a STREAMS ioctl, this union is used to determine
5917c478bdstevel@tonic-gate * the message size in strdoioctl().
5927c478bdstevel@tonic-gate */
5937c478bdstevel@tonic-gateunion ioctypes {
5947c478bdstevel@tonic-gate	struct iocblk	iocblk;
5957c478bdstevel@tonic-gate	struct copyreq	copyreq;
5967c478bdstevel@tonic-gate	struct copyresp	copyresp;
6007c478bdstevel@tonic-gate * Options structure for M_SETOPTS message.  This is sent upstream
6017c478bdstevel@tonic-gate * by a module or driver to set stream head options.
6027c478bdstevel@tonic-gate */
6037c478bdstevel@tonic-gatestruct stroptions {
6047c478bdstevel@tonic-gate	uint_t	so_flags;		/* options to set */
6057c478bdstevel@tonic-gate	short	so_readopt;		/* read option */
6067c478bdstevel@tonic-gate	ushort_t so_wroff;		/* write offset */
6077c478bdstevel@tonic-gate	ssize_t	so_minpsz;		/* minimum read packet size */
6087c478bdstevel@tonic-gate	ssize_t	so_maxpsz;		/* maximum read packet size */
6097c478bdstevel@tonic-gate	size_t	so_hiwat;		/* read queue high water mark */
6107c478bdstevel@tonic-gate	size_t	so_lowat;		/* read queue low water mark */
6117c478bdstevel@tonic-gate	unsigned char so_band;		/* band for water marks */
6127c478bdstevel@tonic-gate	ushort_t so_erropt;		/* error option */
6137c478bdstevel@tonic-gate	ssize_t	so_maxblk;		/* maximum message block size */
6147c478bdstevel@tonic-gate	ushort_t so_copyopt;		/* copy options (see stropts.h) */
615c28749ekais	ushort_t so_tail;		/* space available at the end */
6187c478bdstevel@tonic-gate/* flags for stream options set message */
6207c478bdstevel@tonic-gate#define	SO_ALL		0x003f	/* set all old options */
6217c478bdstevel@tonic-gate#define	SO_READOPT	0x0001	/* set read option */
6227c478bdstevel@tonic-gate#define	SO_WROFF	0x0002	/* set write offset */
6237c478bdstevel@tonic-gate#define	SO_MINPSZ	0x0004	/* set min packet size */
6247c478bdstevel@tonic-gate#define	SO_MAXPSZ	0x0008	/* set max packet size */
6257c478bdstevel@tonic-gate#define	SO_HIWAT	0x0010	/* set high water mark */
6267c478bdstevel@tonic-gate#define	SO_LOWAT	0x0020	/* set low water mark */
6277c478bdstevel@tonic-gate#define	SO_MREADON	0x0040	/* set read notification ON */
6287c478bdstevel@tonic-gate#define	SO_MREADOFF	0x0080	/* set read notification OFF */
6297c478bdstevel@tonic-gate#define	SO_NDELON	0x0100	/* old TTY semantics for NDELAY reads/writes */
6307c478bdstevel@tonic-gate#define	SO_NDELOFF	0x0200	/* STREAMS semantics for NDELAY reads/writes */
6317c478bdstevel@tonic-gate#define	SO_ISTTY	0x0400	/* the stream is acting as a terminal */
6327c478bdstevel@tonic-gate#define	SO_ISNTTY	0x0800	/* the stream is not acting as a terminal */
6337c478bdstevel@tonic-gate#define	SO_TOSTOP	0x1000	/* stop on background writes to this stream */
6347c478bdstevel@tonic-gate#define	SO_TONSTOP	0x2000	/* do not stop on background writes to stream */
6357c478bdstevel@tonic-gate#define	SO_BAND		0x4000	/* water marks affect band */
6367c478bdstevel@tonic-gate#define	SO_DELIM	0x8000	/* messages are delimited */
6377c478bdstevel@tonic-gate#define	SO_NODELIM	0x010000	/* turn off delimiters */
6387c478bdstevel@tonic-gate#define	SO_STRHOLD	0x020000	/* No longer implemented */
6397c478bdstevel@tonic-gate#define	SO_ERROPT	0x040000	/* set error option */
6407c478bdstevel@tonic-gate#define	SO_COPYOPT	0x080000	/* copy option(s) present */
6417c478bdstevel@tonic-gate#define	SO_MAXBLK	0x100000	/* set maximum message block size */
642c28749ekais#define	SO_TAIL		0x200000	/* set the extra allocated space */
6448329232Gordon Ross#if defined(_KERNEL) || defined(_FAKE_KERNEL)
6467c478bdstevel@tonic-gate * Structure for rw (read/write) procedure calls. A pointer
6477c478bdstevel@tonic-gate * to a struiod_t is passed as a parameter to the rwnext() call.
6487c478bdstevel@tonic-gate */
6495e1743fToomas Soomestruct struiod {
6507c478bdstevel@tonic-gate	mblk_t		*d_mp;		/* pointer to mblk (chain) */
6517c478bdstevel@tonic-gate	uio_t		d_uio;		/* uio info */
6528e93525Bryan Cantrill	iovec_t		*d_iov;		/* iov referenced by uio */
6535e1743fToomas Soome};
6567c478bdstevel@tonic-gate * Structure for information procedure calls.
6577c478bdstevel@tonic-gate */
6585e1743fToomas Soomestruct infod {
6597c478bdstevel@tonic-gate	unsigned char	d_cmd;		/* info info request command */
6607c478bdstevel@tonic-gate	unsigned char	d_res;		/* info info command results */
6617c478bdstevel@tonic-gate	int		d_bytes;	/* mblk(s) byte count */
6627c478bdstevel@tonic-gate	int		d_count;	/* count of mblk(s) */
6637c478bdstevel@tonic-gate	uio_t		*d_uiop;	/* pointer to uio struct */
6645e1743fToomas Soome};
6667c478bdstevel@tonic-gate * Values for d_cmd & d_res.
6677c478bdstevel@tonic-gate */
6687c478bdstevel@tonic-gate#define	INFOD_FIRSTBYTES	0x02	/* return msgbsize() of first mblk */
6697c478bdstevel@tonic-gate#define	INFOD_BYTES		0x04	/* return msgbsize() of all mblk(s) */
6707c478bdstevel@tonic-gate#define	INFOD_COUNT		0x08	/* return count of mblk(s) */
6717c478bdstevel@tonic-gate#define	INFOD_COPYOUT		0x10	/* copyout any M_DATA mblk(s) */
674ca9327ameem * Structure used by _I_CMD mechanism, similar in spirit to iocblk.
675ca9327ameem */
676ca9327ameemtypedef struct cmdblk {
677ca9327ameem	int		cb_cmd;		/* ioctl command type */
678ca9327ameem	cred_t		*cb_cr;		/* full credentials */
679ca9327ameem	uint_t		cb_len;		/* payload size */
680ca9327ameem	int		cb_error;	/* error code */
681ca9327ameem} cmdblk_t;
6837c478bdstevel@tonic-gate#endif /* _KERNEL */
6867c478bdstevel@tonic-gate * Miscellaneous parameters and flags.
6877c478bdstevel@tonic-gate */
6907c478bdstevel@tonic-gate * Values for stream flag in open to indicate module open, clone open,
6917c478bdstevel@tonic-gate * and the return value for failure.
6927c478bdstevel@tonic-gate */
6935e1743fToomas Soome#define	MODOPEN		0x1		/* open as a module */
6947c478bdstevel@tonic-gate#define	CLONEOPEN	0x2		/* clone open; pick own minor dev */
6957c478bdstevel@tonic-gate#define	OPENFAIL	-1		/* returned for open failure */
6987c478bdstevel@tonic-gate * Priority definitions for block allocation.
6997c478bdstevel@tonic-gate */
7007c478bdstevel@tonic-gate#define	BPRI_LO		1
7017c478bdstevel@tonic-gate#define	BPRI_MED	2
7027c478bdstevel@tonic-gate#define	BPRI_HI		3
7057c478bdstevel@tonic-gate * Value for packet size that denotes infinity
7067c478bdstevel@tonic-gate */
7077c478bdstevel@tonic-gate#define	INFPSZ		-1
7107c478bdstevel@tonic-gate * Flags for flushq()
7117c478bdstevel@tonic-gate */
7127c478bdstevel@tonic-gate#define	FLUSHALL	1	/* flush all messages */
7137c478bdstevel@tonic-gate#define	FLUSHDATA	0	/* don't flush control messages */
7167c478bdstevel@tonic-gate * Flag for transparent ioctls
7177c478bdstevel@tonic-gate */
7187c478bdstevel@tonic-gate#define	TRANSPARENT	(unsigned int)(-1)
7217c478bdstevel@tonic-gate * Stream head default high/low water marks
7227c478bdstevel@tonic-gate */
7237c478bdstevel@tonic-gate#define	STRHIGH 5120
7247c478bdstevel@tonic-gate#define	STRLOW	1024
7277c478bdstevel@tonic-gate * qwriter perimeter types
7287c478bdstevel@tonic-gate */
7297c478bdstevel@tonic-gate#define	PERIM_INNER	1		/* The inner perimeter */
7307c478bdstevel@tonic-gate#define	PERIM_OUTER	2		/* The outer perimeter */
7337c478bdstevel@tonic-gate * Definitions of Streams macros and function interfaces.
7347c478bdstevel@tonic-gate */
7377c478bdstevel@tonic-gate * canenable - check if queue can be enabled by putq().
7387c478bdstevel@tonic-gate */
7397c478bdstevel@tonic-gate#define	canenable(q)	!((q)->q_flag & QNOENB)
7427c478bdstevel@tonic-gate * Test if data block type is one of the data messages (i.e. not a control
7437c478bdstevel@tonic-gate * message).
7447c478bdstevel@tonic-gate */
7457c478bdstevel@tonic-gate#define	datamsg(type) \
7467c478bdstevel@tonic-gate		((type) == M_DATA || \
7477c478bdstevel@tonic-gate		    (type) == M_MULTIDATA || \
7487c478bdstevel@tonic-gate		    (type) == M_PROTO || \
7497c478bdstevel@tonic-gate		    (type) == M_PCPROTO || \
7507c478bdstevel@tonic-gate		    (type) == M_DELAY)
7537c478bdstevel@tonic-gate * Extract queue class of message block.
7547c478bdstevel@tonic-gate */
7557c478bdstevel@tonic-gate#define	queclass(bp) (((bp)->b_datap->db_type >= QPCTL) ? QPCTL : QNORM)
7587c478bdstevel@tonic-gate * Align address on next lower word boundary.
7597c478bdstevel@tonic-gate */
7607c478bdstevel@tonic-gate#define	straln(a)	(caddr_t)((intptr_t)(a) & -(sizeof (int)-1))
7637c478bdstevel@tonic-gate * Find the max size of data block.
7647c478bdstevel@tonic-gate */
7657c478bdstevel@tonic-gate#define	bpsize(bp) ((unsigned int)(bp->b_datap->db_lim - bp->b_datap->db_base))
7678329232Gordon Ross#if defined(_KERNEL) || defined(_FAKE_KERNEL)
7707c478bdstevel@tonic-gate * For two-byte M_ERROR messages: indication that a side does not have an error
7717c478bdstevel@tonic-gate */
7727c478bdstevel@tonic-gate#define	NOERROR	((unsigned char)-1)
7757c478bdstevel@tonic-gate * declarations of common routines
7767c478bdstevel@tonic-gate */
7787c478bdstevel@tonic-gateextern mblk_t *allocb(size_t, uint_t);
779bd11833meemextern mblk_t *desballoc(unsigned char *, size_t, uint_t, frtn_t *);
7807c478bdstevel@tonic-gateextern mblk_t *esballoc(unsigned char *, size_t, uint_t, frtn_t *);
7817c478bdstevel@tonic-gateextern bcache_t *bcache_create(char *, size_t, uint_t);
7827c478bdstevel@tonic-gateextern void bcache_destroy(bcache_t *);
7837c478bdstevel@tonic-gateextern mblk_t *bcache_allocb(bcache_t *, uint_t);
7847c478bdstevel@tonic-gateextern mblk_t *mkiocb(uint_t);
7857c478bdstevel@tonic-gateextern int testb(size_t, uint_t);
7867c478bdstevel@tonic-gateextern bufcall_id_t bufcall(size_t, uint_t, void (*)(void *), void *);
7877c478bdstevel@tonic-gateextern bufcall_id_t esbbcall(uint_t, void (*)(void *), void *);
7887c478bdstevel@tonic-gateextern void freeb(struct msgb *);
7897c478bdstevel@tonic-gateextern void freemsg(mblk_t *);
7907c478bdstevel@tonic-gateextern mblk_t *dupb(mblk_t *);
7917c478bdstevel@tonic-gateextern mblk_t *dupmsg(mblk_t *);
7927c478bdstevel@tonic-gateextern mblk_t *dupmsg_noloan(mblk_t *);
7937c478bdstevel@tonic-gateextern mblk_t *copyb(mblk_t *);
7947c478bdstevel@tonic-gateextern mblk_t *copymsg(mblk_t *);
7957c478bdstevel@tonic-gateextern void linkb(mblk_t *, mblk_t *);
7967c478bdstevel@tonic-gateextern mblk_t *unlinkb(mblk_t *);
7977c478bdstevel@tonic-gateextern mblk_t *reallocb(mblk_t *, size_t, uint_t);	/* private */
7987c478bdstevel@tonic-gateextern mblk_t *rmvb(mblk_t *, mblk_t *);
7997c478bdstevel@tonic-gateextern int pullupmsg(struct msgb *, ssize_t);
8007c478bdstevel@tonic-gateextern mblk_t *msgpullup(struct msgb *, ssize_t);
8017c478bdstevel@tonic-gateextern int adjmsg(struct msgb *, ssize_t);
8027c478bdstevel@tonic-gateextern size_t msgdsize(struct msgb *);
8037c478bdstevel@tonic-gateextern mblk_t *getq(queue_t *);
8047c478bdstevel@tonic-gateextern void rmvq(queue_t *, mblk_t *);
8057c478bdstevel@tonic-gateextern void flushq(queue_t *, int);
8067c478bdstevel@tonic-gateextern void flushq_common(queue_t *, int, int);
8077c478bdstevel@tonic-gateextern void flushband(queue_t *, unsigned char, int);
8087c478bdstevel@tonic-gateextern int canput(queue_t *);
8097c478bdstevel@tonic-gateextern int bcanput(queue_t *, unsigned char);
8107c478bdstevel@tonic-gateextern int canputnext(queue_t *);
8117c478bdstevel@tonic-gateextern int bcanputnext(queue_t *, unsigned char);
8127c478bdstevel@tonic-gateextern int putq(queue_t *, mblk_t *);
8137c478bdstevel@tonic-gateextern int putbq(queue_t *, mblk_t *);
8147c478bdstevel@tonic-gateextern int insq(queue_t *, mblk_t *, mblk_t *);
8157c478bdstevel@tonic-gateextern void put(queue_t *, mblk_t *);
8167c478bdstevel@tonic-gateextern void putnext(queue_t *, mblk_t *);
8177c478bdstevel@tonic-gateextern int putctl(queue_t *, int);
8187c478bdstevel@tonic-gateextern int putctl1(queue_t *, int, int);
8197c478bdstevel@tonic-gateextern int putnextctl(queue_t *, int);
8207c478bdstevel@tonic-gateextern int putnextctl1(queue_t *, int, int);
8217c478bdstevel@tonic-gateextern queue_t *backq(queue_t *);
8227c478bdstevel@tonic-gateextern void qreply(queue_t *, mblk_t *);
8237c478bdstevel@tonic-gateextern void qenable(queue_t *);
8247c478bdstevel@tonic-gateextern int qsize(queue_t *);
8257c478bdstevel@tonic-gateextern void noenable(queue_t *);
8267c478bdstevel@tonic-gateextern void enableok(queue_t *);
8277c478bdstevel@tonic-gateextern int strqset(queue_t *, qfields_t, unsigned char, intptr_t);
8287c478bdstevel@tonic-gateextern int strqget(queue_t *, qfields_t, unsigned char, void *);
8297c478bdstevel@tonic-gateextern void unbufcall(bufcall_id_t);
8307c478bdstevel@tonic-gateextern void qprocson(queue_t *);
8317c478bdstevel@tonic-gateextern void qprocsoff(queue_t *);
8327c478bdstevel@tonic-gateextern void freezestr(queue_t *);
8337c478bdstevel@tonic-gateextern void unfreezestr(queue_t *);
8347c478bdstevel@tonic-gateextern void qwait(queue_t *);
8357c478bdstevel@tonic-gateextern int qwait_sig(queue_t *);
8367c478bdstevel@tonic-gateextern boolean_t qwait_rw(queue_t *);
8377c478bdstevel@tonic-gateextern void qwriter(queue_t *, mblk_t *, void (*func)(), int);
8387c478bdstevel@tonic-gateextern timeout_id_t qtimeout(queue_t *, void (*func)(void *), void *, clock_t);
8397c478bdstevel@tonic-gateextern bufcall_id_t qbufcall(queue_t *, size_t, uint_t,
8407c478bdstevel@tonic-gate    void (*)(void *), void *);
8417c478bdstevel@tonic-gateextern clock_t quntimeout(queue_t *, timeout_id_t);
8427c478bdstevel@tonic-gateextern void qunbufcall(queue_t *, bufcall_id_t);
8437c478bdstevel@tonic-gateextern void strwakeq(queue_t *, int);
8447c478bdstevel@tonic-gateextern int struioget(queue_t *, mblk_t *, struiod_t *, int);
8457c478bdstevel@tonic-gateextern int rwnext(queue_t *, struiod_t *);
8467c478bdstevel@tonic-gateextern int infonext(queue_t *, infod_t *);
8477c478bdstevel@tonic-gateextern int isuioq(queue_t *);
8487c478bdstevel@tonic-gateextern void create_putlocks(queue_t *, int);
849301ce41jaextern int mp_cont_len(mblk_t *, int *);
8527c478bdstevel@tonic-gate * shared or externally configured data structures
8537c478bdstevel@tonic-gate */
8547c478bdstevel@tonic-gateextern int nstrpush;			/* maximum number of pushes allowed */
8567c478bdstevel@tonic-gate#endif /* _KERNEL */
8587c478bdstevel@tonic-gate#ifdef	__cplusplus
8627c478bdstevel@tonic-gate#endif	/* _SYS_STREAM_H */