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