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