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