17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 59acbbeafSnn35248 * Common Development and Distribution License (the "License"). 69acbbeafSnn35248 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 227c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 237c478bd9Sstevel@tonic-gate 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate /* 265ba3fab4Sjk115741 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 277c478bd9Sstevel@tonic-gate * Use is subject to license terms. 287c478bd9Sstevel@tonic-gate */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #ifndef _SYS_STRSUBR_H 317c478bd9Sstevel@tonic-gate #define _SYS_STRSUBR_H 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.17 */ 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate /* 367c478bd9Sstevel@tonic-gate * WARNING: 377c478bd9Sstevel@tonic-gate * Everything in this file is private, belonging to the 387c478bd9Sstevel@tonic-gate * STREAMS subsystem. The only guarantee made about the 397c478bd9Sstevel@tonic-gate * contents of this file is that if you include it, your 407c478bd9Sstevel@tonic-gate * code will not port to the next release. 417c478bd9Sstevel@tonic-gate */ 427c478bd9Sstevel@tonic-gate #include <sys/stream.h> 437c478bd9Sstevel@tonic-gate #include <sys/stropts.h> 447c478bd9Sstevel@tonic-gate #include <sys/kstat.h> 457c478bd9Sstevel@tonic-gate #include <sys/uio.h> 467c478bd9Sstevel@tonic-gate #include <sys/proc.h> 47f4b3ec61Sdh155122 #include <sys/netstack.h> 48f4b3ec61Sdh155122 #include <sys/modhash.h> 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate #ifdef __cplusplus 517c478bd9Sstevel@tonic-gate extern "C" { 527c478bd9Sstevel@tonic-gate #endif 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate /* 557c478bd9Sstevel@tonic-gate * In general, the STREAMS locks are disjoint; they are only held 567c478bd9Sstevel@tonic-gate * locally, and not simultaneously by a thread. However, module 577c478bd9Sstevel@tonic-gate * code, including at the stream head, requires some locks to be 587c478bd9Sstevel@tonic-gate * acquired in order for its safety. 597c478bd9Sstevel@tonic-gate * 1. Stream level claim. This prevents the value of q_next 607c478bd9Sstevel@tonic-gate * from changing while module code is executing. 617c478bd9Sstevel@tonic-gate * 2. Queue level claim. This prevents the value of q_ptr 627c478bd9Sstevel@tonic-gate * from changing while put or service code is executing. 637c478bd9Sstevel@tonic-gate * In addition, it provides for queue single-threading 647c478bd9Sstevel@tonic-gate * for QPAIR and PERQ MT-safe modules. 657c478bd9Sstevel@tonic-gate * 3. Stream head lock. May be held by the stream head module 667c478bd9Sstevel@tonic-gate * to implement a read/write/open/close monitor. 677c478bd9Sstevel@tonic-gate * Note: that the only types of twisted stream supported are 687c478bd9Sstevel@tonic-gate * the pipe and transports which have read and write service 697c478bd9Sstevel@tonic-gate * procedures on both sides of the twist. 707c478bd9Sstevel@tonic-gate * 4. Queue lock. May be acquired by utility routines on 717c478bd9Sstevel@tonic-gate * behalf of a module. 727c478bd9Sstevel@tonic-gate */ 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate /* 757c478bd9Sstevel@tonic-gate * In general, sd_lock protects the consistency of the stdata 767c478bd9Sstevel@tonic-gate * structure. Additionally, it is used with sd_monitor 777c478bd9Sstevel@tonic-gate * to implement an open/close monitor. In particular, it protects 787c478bd9Sstevel@tonic-gate * the following fields: 797c478bd9Sstevel@tonic-gate * sd_iocblk 807c478bd9Sstevel@tonic-gate * sd_flag 817c478bd9Sstevel@tonic-gate * sd_copyflag 827c478bd9Sstevel@tonic-gate * sd_iocid 837c478bd9Sstevel@tonic-gate * sd_iocwait 847c478bd9Sstevel@tonic-gate * sd_sidp 857c478bd9Sstevel@tonic-gate * sd_pgidp 867c478bd9Sstevel@tonic-gate * sd_wroff 87c28749e9Skais * sd_tail 887c478bd9Sstevel@tonic-gate * sd_rerror 897c478bd9Sstevel@tonic-gate * sd_werror 907c478bd9Sstevel@tonic-gate * sd_pushcnt 917c478bd9Sstevel@tonic-gate * sd_sigflags 927c478bd9Sstevel@tonic-gate * sd_siglist 937c478bd9Sstevel@tonic-gate * sd_pollist 947c478bd9Sstevel@tonic-gate * sd_mark 957c478bd9Sstevel@tonic-gate * sd_closetime 967c478bd9Sstevel@tonic-gate * sd_wakeq 97c6c65e54Sdm120769 * sd_uiordq 98c6c65e54Sdm120769 * sd_uiowrq 997c478bd9Sstevel@tonic-gate * sd_maxblk 1007c478bd9Sstevel@tonic-gate * 1017c478bd9Sstevel@tonic-gate * The following fields are modified only by the allocator, which 1027c478bd9Sstevel@tonic-gate * has exclusive access to them at that time: 1037c478bd9Sstevel@tonic-gate * sd_wrq 1047c478bd9Sstevel@tonic-gate * sd_strtab 1057c478bd9Sstevel@tonic-gate * 1067c478bd9Sstevel@tonic-gate * The following field is protected by the overlying file system 1077c478bd9Sstevel@tonic-gate * code, guaranteeing single-threading of opens: 1087c478bd9Sstevel@tonic-gate * sd_vnode 1097c478bd9Sstevel@tonic-gate * 1107c478bd9Sstevel@tonic-gate * Stream-level locks should be acquired before any queue-level locks 1117c478bd9Sstevel@tonic-gate * are acquired. 1127c478bd9Sstevel@tonic-gate * 1137c478bd9Sstevel@tonic-gate * The stream head write queue lock(sd_wrq) is used to protect the 1147c478bd9Sstevel@tonic-gate * fields qn_maxpsz and qn_minpsz because freezestr() which is 1157c478bd9Sstevel@tonic-gate * necessary for strqset() only gets the queue lock. 1167c478bd9Sstevel@tonic-gate */ 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate /* 1197c478bd9Sstevel@tonic-gate * Function types for the parameterized stream head. 1207c478bd9Sstevel@tonic-gate * The msgfunc_t takes the parameters: 1217c478bd9Sstevel@tonic-gate * msgfunc(vnode_t *vp, mblk_t *mp, strwakeup_t *wakeups, 1227c478bd9Sstevel@tonic-gate * strsigset_t *firstmsgsigs, strsigset_t *allmsgsigs, 1237c478bd9Sstevel@tonic-gate * strpollset_t *pollwakeups); 1247c478bd9Sstevel@tonic-gate * It returns an optional message to be processed by the stream head. 1257c478bd9Sstevel@tonic-gate * 1267c478bd9Sstevel@tonic-gate * The parameters for errfunc_t are: 1277c478bd9Sstevel@tonic-gate * errfunc(vnode *vp, int ispeek, int *clearerr); 1287c478bd9Sstevel@tonic-gate * It returns an errno and zero if there was no pending error. 1297c478bd9Sstevel@tonic-gate */ 1307c478bd9Sstevel@tonic-gate typedef uint_t strwakeup_t; 1317c478bd9Sstevel@tonic-gate typedef uint_t strsigset_t; 1327c478bd9Sstevel@tonic-gate typedef short strpollset_t; 1337c478bd9Sstevel@tonic-gate typedef uintptr_t callbparams_id_t; 1347c478bd9Sstevel@tonic-gate typedef mblk_t *(*msgfunc_t)(vnode_t *, mblk_t *, strwakeup_t *, 1357c478bd9Sstevel@tonic-gate strsigset_t *, strsigset_t *, strpollset_t *); 1367c478bd9Sstevel@tonic-gate typedef int (*errfunc_t)(vnode_t *, int, int *); 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate /* 1397c478bd9Sstevel@tonic-gate * Per stream sd_lock in putnext may be replaced by per cpu stream_putlocks 1407c478bd9Sstevel@tonic-gate * each living in a separate cache line. putnext/canputnext grabs only one of 1417c478bd9Sstevel@tonic-gate * stream_putlocks while strlock() (called on behalf of insertq()/removeq()) 1427c478bd9Sstevel@tonic-gate * acquires all stream_putlocks. Normally stream_putlocks are only employed 1437c478bd9Sstevel@tonic-gate * for highly contended streams that have SQ_CIPUT queues in the critical path 1447c478bd9Sstevel@tonic-gate * (e.g. NFS/UDP stream). 1457c478bd9Sstevel@tonic-gate * 1467c478bd9Sstevel@tonic-gate * stream_putlocks are dynamically assigned to stdata structure through 1477c478bd9Sstevel@tonic-gate * sd_ciputctrl pointer possibly when a stream is already in use. Since 1487c478bd9Sstevel@tonic-gate * strlock() uses stream_putlocks only under sd_lock acquiring sd_lock when 1497c478bd9Sstevel@tonic-gate * assigning stream_putlocks to the stream ensures synchronization with 1507c478bd9Sstevel@tonic-gate * strlock(). 1517c478bd9Sstevel@tonic-gate * 1527c478bd9Sstevel@tonic-gate * For lock ordering purposes stream_putlocks are treated as the extension of 1537c478bd9Sstevel@tonic-gate * sd_lock and are always grabbed right after grabbing sd_lock and released 1547c478bd9Sstevel@tonic-gate * right before releasing sd_lock except putnext/canputnext where only one of 1557c478bd9Sstevel@tonic-gate * stream_putlocks locks is used and where it is the first lock to grab. 1567c478bd9Sstevel@tonic-gate */ 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate typedef struct ciputctrl_str { 1597c478bd9Sstevel@tonic-gate union _ciput_un { 1607c478bd9Sstevel@tonic-gate uchar_t pad[64]; 1617c478bd9Sstevel@tonic-gate struct _ciput_str { 1627c478bd9Sstevel@tonic-gate kmutex_t ciput_lck; 1637c478bd9Sstevel@tonic-gate ushort_t ciput_cnt; 1647c478bd9Sstevel@tonic-gate } ciput_str; 1657c478bd9Sstevel@tonic-gate } ciput_un; 1667c478bd9Sstevel@tonic-gate } ciputctrl_t; 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate #define ciputctrl_lock ciput_un.ciput_str.ciput_lck 1697c478bd9Sstevel@tonic-gate #define ciputctrl_count ciput_un.ciput_str.ciput_cnt 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate /* 1727c478bd9Sstevel@tonic-gate * Header for a stream: interface to rest of system. 1739aa9fab9Smeem * 1749aa9fab9Smeem * NOTE: While this is a consolidation-private structure, some unbundled and 1759aa9fab9Smeem * third-party products inappropriately make use of some of the fields. 1769aa9fab9Smeem * As such, please take care to not gratuitously change any offsets of 1779aa9fab9Smeem * existing members. 1787c478bd9Sstevel@tonic-gate */ 1797c478bd9Sstevel@tonic-gate typedef struct stdata { 1807c478bd9Sstevel@tonic-gate struct queue *sd_wrq; /* write queue */ 1817c478bd9Sstevel@tonic-gate struct msgb *sd_iocblk; /* return block for ioctl */ 1827c478bd9Sstevel@tonic-gate struct vnode *sd_vnode; /* pointer to associated vnode */ 1837c478bd9Sstevel@tonic-gate struct streamtab *sd_strtab; /* pointer to streamtab for stream */ 1847c478bd9Sstevel@tonic-gate uint_t sd_flag; /* state/flags */ 1857c478bd9Sstevel@tonic-gate uint_t sd_iocid; /* ioctl id */ 1867c478bd9Sstevel@tonic-gate struct pid *sd_sidp; /* controlling session info */ 1877c478bd9Sstevel@tonic-gate struct pid *sd_pgidp; /* controlling process group info */ 188c28749e9Skais ushort_t sd_tail; /* reserved space in written mblks */ 1899aa9fab9Smeem ushort_t sd_wroff; /* write offset */ 1907c478bd9Sstevel@tonic-gate int sd_rerror; /* error to return on read ops */ 1917c478bd9Sstevel@tonic-gate int sd_werror; /* error to return on write ops */ 1927c478bd9Sstevel@tonic-gate int sd_pushcnt; /* number of pushes done on stream */ 1937c478bd9Sstevel@tonic-gate int sd_sigflags; /* logical OR of all siglist events */ 1947c478bd9Sstevel@tonic-gate struct strsig *sd_siglist; /* pid linked list to rcv SIGPOLL sig */ 1957c478bd9Sstevel@tonic-gate struct pollhead sd_pollist; /* list of all pollers to wake up */ 1967c478bd9Sstevel@tonic-gate struct msgb *sd_mark; /* "marked" message on read queue */ 1977c478bd9Sstevel@tonic-gate clock_t sd_closetime; /* time to wait to drain q in close */ 1987c478bd9Sstevel@tonic-gate kmutex_t sd_lock; /* protect head consistency */ 1997c478bd9Sstevel@tonic-gate kcondvar_t sd_monitor; /* open/close/push/pop monitor */ 2007c478bd9Sstevel@tonic-gate kcondvar_t sd_iocmonitor; /* ioctl single-threading */ 2016829c646Sxy158873 kcondvar_t sd_refmonitor; /* sd_refcnt monitor */ 2027c478bd9Sstevel@tonic-gate ssize_t sd_qn_minpsz; /* These two fields are a performance */ 2037c478bd9Sstevel@tonic-gate ssize_t sd_qn_maxpsz; /* enhancements, cache the values in */ 2047c478bd9Sstevel@tonic-gate /* the stream head so we don't have */ 2057c478bd9Sstevel@tonic-gate /* to ask the module below the stream */ 2067c478bd9Sstevel@tonic-gate /* head to get this information. */ 2077c478bd9Sstevel@tonic-gate struct stdata *sd_mate; /* pointer to twisted stream mate */ 2087c478bd9Sstevel@tonic-gate kthread_id_t sd_freezer; /* thread that froze stream */ 2097c478bd9Sstevel@tonic-gate kmutex_t sd_reflock; /* Protects sd_refcnt */ 2107c478bd9Sstevel@tonic-gate int sd_refcnt; /* number of claimstr */ 2117c478bd9Sstevel@tonic-gate uint_t sd_wakeq; /* strwakeq()'s copy of sd_flag */ 2127c478bd9Sstevel@tonic-gate struct queue *sd_struiordq; /* sync barrier struio() read queue */ 2137c478bd9Sstevel@tonic-gate struct queue *sd_struiowrq; /* sync barrier struio() write queue */ 2147c478bd9Sstevel@tonic-gate char sd_struiodnak; /* defer NAK of M_IOCTL by rput() */ 2157c478bd9Sstevel@tonic-gate struct msgb *sd_struionak; /* pointer M_IOCTL mblk(s) to NAK */ 2167c478bd9Sstevel@tonic-gate caddr_t sd_t_audit_data; /* For audit purposes only */ 2177c478bd9Sstevel@tonic-gate ssize_t sd_maxblk; /* maximum message block size */ 2187c478bd9Sstevel@tonic-gate uint_t sd_rput_opt; /* options/flags for strrput */ 2197c478bd9Sstevel@tonic-gate uint_t sd_wput_opt; /* options/flags for write/putmsg */ 2207c478bd9Sstevel@tonic-gate uint_t sd_read_opt; /* options/flags for strread */ 2217c478bd9Sstevel@tonic-gate msgfunc_t sd_rprotofunc; /* rput M_*PROTO routine */ 222c28749e9Skais msgfunc_t sd_rputdatafunc; /* read M_DATA routine */ 2237c478bd9Sstevel@tonic-gate msgfunc_t sd_rmiscfunc; /* rput routine (non-data/proto) */ 224c28749e9Skais msgfunc_t sd_wputdatafunc; /* wput M_DATA routine */ 2257c478bd9Sstevel@tonic-gate errfunc_t sd_rderrfunc; /* read side error callback */ 2267c478bd9Sstevel@tonic-gate errfunc_t sd_wrerrfunc; /* write side error callback */ 2277c478bd9Sstevel@tonic-gate /* 2287c478bd9Sstevel@tonic-gate * support for low contention concurrent putnext. 2297c478bd9Sstevel@tonic-gate */ 2307c478bd9Sstevel@tonic-gate ciputctrl_t *sd_ciputctrl; 2317c478bd9Sstevel@tonic-gate uint_t sd_nciputctrl; 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate int sd_anchor; /* position of anchor in stream */ 2347c478bd9Sstevel@tonic-gate /* 2357c478bd9Sstevel@tonic-gate * Service scheduling at the stream head. 2367c478bd9Sstevel@tonic-gate */ 2377c478bd9Sstevel@tonic-gate kmutex_t sd_qlock; 2387c478bd9Sstevel@tonic-gate struct queue *sd_qhead; /* Head of queues to be serviced. */ 2397c478bd9Sstevel@tonic-gate struct queue *sd_qtail; /* Tail of queues to be serviced. */ 2407c478bd9Sstevel@tonic-gate void *sd_servid; /* Service ID for bckgrnd schedule */ 2417c478bd9Sstevel@tonic-gate ushort_t sd_svcflags; /* Servicing flags */ 2427c478bd9Sstevel@tonic-gate short sd_nqueues; /* Number of queues in the list */ 2437c478bd9Sstevel@tonic-gate kcondvar_t sd_qcv; /* Waiters for qhead to become empty */ 2447c478bd9Sstevel@tonic-gate kcondvar_t sd_zcopy_wait; 2457c478bd9Sstevel@tonic-gate uint_t sd_copyflag; /* copy-related flags */ 246f4b3ec61Sdh155122 zoneid_t sd_anchorzone; /* Allow removal from same zone only */ 247*ca9327a6Smeem struct msgb *sd_cmdblk; /* reply from _I_CMD */ 2487c478bd9Sstevel@tonic-gate } stdata_t; 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate /* 2517c478bd9Sstevel@tonic-gate * stdata servicing flags. 2527c478bd9Sstevel@tonic-gate */ 2537c478bd9Sstevel@tonic-gate #define STRS_WILLSERVICE 0x01 2547c478bd9Sstevel@tonic-gate #define STRS_SCHEDULED 0x02 2557c478bd9Sstevel@tonic-gate 2567c478bd9Sstevel@tonic-gate #define STREAM_NEEDSERVICE(stp) ((stp)->sd_qhead != NULL) 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate /* 2597c478bd9Sstevel@tonic-gate * stdata flag field defines 2607c478bd9Sstevel@tonic-gate */ 2617c478bd9Sstevel@tonic-gate #define IOCWAIT 0x00000001 /* Someone is doing an ioctl */ 2627c478bd9Sstevel@tonic-gate #define RSLEEP 0x00000002 /* Someone wants to read/recv msg */ 2637c478bd9Sstevel@tonic-gate #define WSLEEP 0x00000004 /* Someone wants to write */ 2647c478bd9Sstevel@tonic-gate #define STRPRI 0x00000008 /* An M_PCPROTO is at stream head */ 2657c478bd9Sstevel@tonic-gate #define STRHUP 0x00000010 /* Device has vanished */ 2667c478bd9Sstevel@tonic-gate #define STWOPEN 0x00000020 /* waiting for 1st open */ 2677c478bd9Sstevel@tonic-gate #define STPLEX 0x00000040 /* stream is being multiplexed */ 2687c478bd9Sstevel@tonic-gate #define STRISTTY 0x00000080 /* stream is a terminal */ 2697c478bd9Sstevel@tonic-gate #define STRGETINPROG 0x00000100 /* (k)strgetmsg is running */ 2707c478bd9Sstevel@tonic-gate #define IOCWAITNE 0x00000200 /* STR_NOERROR ioctl running */ 2717c478bd9Sstevel@tonic-gate #define STRDERR 0x00000400 /* fatal read error from M_ERROR */ 2727c478bd9Sstevel@tonic-gate #define STWRERR 0x00000800 /* fatal write error from M_ERROR */ 2737c478bd9Sstevel@tonic-gate #define STRDERRNONPERSIST 0x00001000 /* nonpersistent read errors */ 2747c478bd9Sstevel@tonic-gate #define STWRERRNONPERSIST 0x00002000 /* nonpersistent write errors */ 2757c478bd9Sstevel@tonic-gate #define STRCLOSE 0x00004000 /* wait for a close to complete */ 2767c478bd9Sstevel@tonic-gate #define SNDMREAD 0x00008000 /* used for read notification */ 2777c478bd9Sstevel@tonic-gate #define OLDNDELAY 0x00010000 /* use old TTY semantics for */ 2787c478bd9Sstevel@tonic-gate /* NDELAY reads and writes */ 2797c478bd9Sstevel@tonic-gate /* 0x00020000 unused */ 2807c478bd9Sstevel@tonic-gate /* 0x00040000 unused */ 2817c478bd9Sstevel@tonic-gate #define STRTOSTOP 0x00080000 /* block background writes */ 282*ca9327a6Smeem #define STRCMDWAIT 0x00100000 /* someone is doing an _I_CMD */ 2837c478bd9Sstevel@tonic-gate /* 0x00200000 unused */ 2847c478bd9Sstevel@tonic-gate #define STRMOUNT 0x00400000 /* stream is mounted */ 2857c478bd9Sstevel@tonic-gate #define STRNOTATMARK 0x00800000 /* Not at mark (when empty read q) */ 2867c478bd9Sstevel@tonic-gate #define STRDELIM 0x01000000 /* generate delimited messages */ 2877c478bd9Sstevel@tonic-gate #define STRATMARK 0x02000000 /* At mark (due to MSGMARKNEXT) */ 2887c478bd9Sstevel@tonic-gate #define STZCNOTIFY 0x04000000 /* wait for zerocopy mblk to be acked */ 2897c478bd9Sstevel@tonic-gate #define STRPLUMB 0x08000000 /* push/pop pending */ 2907c478bd9Sstevel@tonic-gate #define STREOF 0x10000000 /* End-of-file indication */ 2917c478bd9Sstevel@tonic-gate #define STREOPENFAIL 0x20000000 /* indicates if re-open has failed */ 2927c478bd9Sstevel@tonic-gate #define STRMATE 0x40000000 /* this stream is a mate */ 2937c478bd9Sstevel@tonic-gate #define STRHASLINKS 0x80000000 /* I_LINKs under this stream */ 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate /* 2967c478bd9Sstevel@tonic-gate * Copy-related flags (sd_copyflag), set by SO_COPYOPT. 2977c478bd9Sstevel@tonic-gate */ 2987c478bd9Sstevel@tonic-gate #define STZCVMSAFE 0x00000001 /* safe to borrow file (segmapped) */ 2997c478bd9Sstevel@tonic-gate /* pages instead of bcopy */ 3007c478bd9Sstevel@tonic-gate #define STZCVMUNSAFE 0x00000002 /* unsafe to borrow file pages */ 3017c478bd9Sstevel@tonic-gate #define STRCOPYCACHED 0x00000004 /* copy should NOT bypass cache */ 3027c478bd9Sstevel@tonic-gate 3037c478bd9Sstevel@tonic-gate /* 3047c478bd9Sstevel@tonic-gate * Options and flags for strrput (sd_rput_opt) 3057c478bd9Sstevel@tonic-gate */ 3067c478bd9Sstevel@tonic-gate #define SR_POLLIN 0x00000001 /* pollwakeup needed for band0 data */ 3077c478bd9Sstevel@tonic-gate #define SR_SIGALLDATA 0x00000002 /* Send SIGPOLL for all M_DATA */ 3087c478bd9Sstevel@tonic-gate #define SR_CONSOL_DATA 0x00000004 /* Consolidate M_DATA onto q_last */ 3097c478bd9Sstevel@tonic-gate #define SR_IGN_ZEROLEN 0x00000008 /* Ignore zero-length M_DATA */ 3107c478bd9Sstevel@tonic-gate 3117c478bd9Sstevel@tonic-gate /* 3127c478bd9Sstevel@tonic-gate * Options and flags for strwrite/strputmsg (sd_wput_opt) 3137c478bd9Sstevel@tonic-gate */ 3147c478bd9Sstevel@tonic-gate #define SW_SIGPIPE 0x00000001 /* Send SIGPIPE for write error */ 3157c478bd9Sstevel@tonic-gate #define SW_RECHECK_ERR 0x00000002 /* Recheck errors in strwrite loop */ 3167c478bd9Sstevel@tonic-gate #define SW_SNDZERO 0x00000004 /* send 0-length msg down pipe/FIFO */ 3177c478bd9Sstevel@tonic-gate 3187c478bd9Sstevel@tonic-gate /* 3197c478bd9Sstevel@tonic-gate * Options and flags for strread (sd_read_opt) 3207c478bd9Sstevel@tonic-gate */ 3217c478bd9Sstevel@tonic-gate #define RD_MSGDIS 0x00000001 /* read msg discard */ 3227c478bd9Sstevel@tonic-gate #define RD_MSGNODIS 0x00000002 /* read msg no discard */ 3237c478bd9Sstevel@tonic-gate #define RD_PROTDAT 0x00000004 /* read M_[PC]PROTO contents as data */ 3247c478bd9Sstevel@tonic-gate #define RD_PROTDIS 0x00000008 /* discard M_[PC]PROTO blocks and */ 3257c478bd9Sstevel@tonic-gate /* retain data blocks */ 3267c478bd9Sstevel@tonic-gate /* 3277c478bd9Sstevel@tonic-gate * Flags parameter for strsetrputhooks() and strsetwputhooks(). 3287c478bd9Sstevel@tonic-gate * These flags define the interface for setting the above internal 3297c478bd9Sstevel@tonic-gate * flags in sd_rput_opt and sd_wput_opt. 3307c478bd9Sstevel@tonic-gate */ 3317c478bd9Sstevel@tonic-gate #define SH_CONSOL_DATA 0x00000001 /* Consolidate M_DATA onto q_last */ 3327c478bd9Sstevel@tonic-gate #define SH_SIGALLDATA 0x00000002 /* Send SIGPOLL for all M_DATA */ 3337c478bd9Sstevel@tonic-gate #define SH_IGN_ZEROLEN 0x00000004 /* Drop zero-length M_DATA */ 3347c478bd9Sstevel@tonic-gate 3357c478bd9Sstevel@tonic-gate #define SH_SIGPIPE 0x00000100 /* Send SIGPIPE for write error */ 3367c478bd9Sstevel@tonic-gate #define SH_RECHECK_ERR 0x00000200 /* Recheck errors in strwrite loop */ 3377c478bd9Sstevel@tonic-gate 3387c478bd9Sstevel@tonic-gate /* 3397c478bd9Sstevel@tonic-gate * Each queue points to a sync queue (the inner perimeter) which keeps 3407c478bd9Sstevel@tonic-gate * track of the number of threads that are inside a given queue (sq_count) 3417c478bd9Sstevel@tonic-gate * and also is used to implement the asynchronous putnext 3427c478bd9Sstevel@tonic-gate * (by queuing messages if the queue can not be entered.) 3437c478bd9Sstevel@tonic-gate * 3447c478bd9Sstevel@tonic-gate * Messages are queued on sq_head/sq_tail including deferred qwriter(INNER) 3457c478bd9Sstevel@tonic-gate * messages. The sq_head/sq_tail list is a singly-linked list with 3467c478bd9Sstevel@tonic-gate * b_queue recording the queue and b_prev recording the function to 3477c478bd9Sstevel@tonic-gate * be called (either the put procedure or a qwriter callback function.) 3487c478bd9Sstevel@tonic-gate * 3497c478bd9Sstevel@tonic-gate * The sq_count counter tracks the number of threads that are 3507c478bd9Sstevel@tonic-gate * executing inside the perimeter or (in the case of outer perimeters) 3517c478bd9Sstevel@tonic-gate * have some work queued for them relating to the perimeter. The sq_rmqcount 3527c478bd9Sstevel@tonic-gate * counter tracks the subset which are in removeq() (usually invoked from 3537c478bd9Sstevel@tonic-gate * qprocsoff(9F)). 3547c478bd9Sstevel@tonic-gate * 3557c478bd9Sstevel@tonic-gate * In addition a module writer can declare that the module has an outer 3567c478bd9Sstevel@tonic-gate * perimeter (by setting D_MTOUTPERIM) in which case all inner perimeter 3577c478bd9Sstevel@tonic-gate * syncq's for the module point (through sq_outer) to an outer perimeter 3587c478bd9Sstevel@tonic-gate * syncq. The outer perimeter consists of the doubly linked list (sq_onext and 3597c478bd9Sstevel@tonic-gate * sq_oprev) linking all the inner perimeter syncq's with out outer perimeter 3607c478bd9Sstevel@tonic-gate * syncq. This is used to implement qwriter(OUTER) (an asynchronous way of 3617c478bd9Sstevel@tonic-gate * getting exclusive access at the outer perimeter) and outer_enter/exit 3627c478bd9Sstevel@tonic-gate * which are used by the framework to acquire exclusive access to the outer 3637c478bd9Sstevel@tonic-gate * perimeter during open and close of modules that have set D_MTOUTPERIM. 3647c478bd9Sstevel@tonic-gate * 3657c478bd9Sstevel@tonic-gate * In the inner perimeter case sq_save is available for use by machine 3667c478bd9Sstevel@tonic-gate * dependent code. sq_head/sq_tail are used to queue deferred messages on 3677c478bd9Sstevel@tonic-gate * the inner perimeter syncqs and to queue become_writer requests on the 3687c478bd9Sstevel@tonic-gate * outer perimeter syncqs. 3697c478bd9Sstevel@tonic-gate * 3707c478bd9Sstevel@tonic-gate * Note: machine dependent optimized versions of putnext may depend 3717c478bd9Sstevel@tonic-gate * on the order of sq_flags and sq_count (so that they can e.g. 3727c478bd9Sstevel@tonic-gate * read these two fields in a single load instruction.) 3737c478bd9Sstevel@tonic-gate * 3747c478bd9Sstevel@tonic-gate * Per perimeter SQLOCK/sq_count in putnext/put may be replaced by per cpu 3757c478bd9Sstevel@tonic-gate * sq_putlocks/sq_putcounts each living in a separate cache line. Obviously 3767c478bd9Sstevel@tonic-gate * sq_putlock[x] protects sq_putcount[x]. putnext/put routine will grab only 1 3777c478bd9Sstevel@tonic-gate * of sq_putlocks and update only 1 of sq_putcounts. strlock() and many 3787c478bd9Sstevel@tonic-gate * other routines in strsubr.c and ddi.c will grab all sq_putlocks (as well as 3797c478bd9Sstevel@tonic-gate * SQLOCK) and figure out the count value as the sum of sq_count and all of 3807c478bd9Sstevel@tonic-gate * sq_putcounts. The idea is to make critical fast path -- putnext -- much 3817c478bd9Sstevel@tonic-gate * faster at the expense of much less often used slower path like 3827c478bd9Sstevel@tonic-gate * strlock(). One known case where entersq/strlock is executed pretty often is 3837c478bd9Sstevel@tonic-gate * SpecWeb but since IP is SQ_CIOC and socket TCP/IP stream is nextless 3847c478bd9Sstevel@tonic-gate * there's no need to grab multiple sq_putlocks and look at sq_putcounts. See 3857c478bd9Sstevel@tonic-gate * strsubr.c for more comments. 3867c478bd9Sstevel@tonic-gate * 3877c478bd9Sstevel@tonic-gate * Note regular SQLOCK and sq_count are still used in many routines 3887c478bd9Sstevel@tonic-gate * (e.g. entersq(), rwnext()) in the same way as before sq_putlocks were 3897c478bd9Sstevel@tonic-gate * introduced. 3907c478bd9Sstevel@tonic-gate * 3917c478bd9Sstevel@tonic-gate * To understand when all sq_putlocks need to be held and all sq_putcounts 3927c478bd9Sstevel@tonic-gate * need to be added up one needs to look closely at putnext code. Basically if 3937c478bd9Sstevel@tonic-gate * a routine like e.g. wait_syncq() needs to be sure that perimeter is empty 3947c478bd9Sstevel@tonic-gate * all sq_putlocks/sq_putcounts need to be held/added up. On the other hand 3957c478bd9Sstevel@tonic-gate * there's no need to hold all sq_putlocks and count all sq_putcounts in 3967c478bd9Sstevel@tonic-gate * routines like leavesq()/dropsq() and etc. since the are usually exit 3977c478bd9Sstevel@tonic-gate * counterparts of entersq/outer_enter() and etc. which have already either 3987c478bd9Sstevel@tonic-gate * prevented put entry poins from executing or did not care about put 3997c478bd9Sstevel@tonic-gate * entrypoints. entersq() doesn't need to care about sq_putlocks/sq_putcounts 4007c478bd9Sstevel@tonic-gate * if the entry point has a shared access since put has the highest degree of 4017c478bd9Sstevel@tonic-gate * concurrency and such entersq() does not intend to block out put 4027c478bd9Sstevel@tonic-gate * entrypoints. 4037c478bd9Sstevel@tonic-gate * 4047c478bd9Sstevel@tonic-gate * Before sq_putcounts were introduced the standard way to wait for perimeter 4057c478bd9Sstevel@tonic-gate * to become empty was: 4067c478bd9Sstevel@tonic-gate * 4077c478bd9Sstevel@tonic-gate * mutex_enter(SQLOCK(sq)); 4087c478bd9Sstevel@tonic-gate * while (sq->sq_count > 0) { 4097c478bd9Sstevel@tonic-gate * sq->sq_flags |= SQ_WANTWAKEUP; 4107c478bd9Sstevel@tonic-gate * cv_wait(&sq->sq_wait, SQLOCK(sq)); 4117c478bd9Sstevel@tonic-gate * } 4127c478bd9Sstevel@tonic-gate * mutex_exit(SQLOCK(sq)); 4137c478bd9Sstevel@tonic-gate * 4147c478bd9Sstevel@tonic-gate * The new way is: 4157c478bd9Sstevel@tonic-gate * 4167c478bd9Sstevel@tonic-gate * mutex_enter(SQLOCK(sq)); 4177c478bd9Sstevel@tonic-gate * count = sq->sq_count; 4187c478bd9Sstevel@tonic-gate * SQ_PUTLOCKS_ENTER(sq); 4197c478bd9Sstevel@tonic-gate * SUM_SQ_PUTCOUNTS(sq, count); 4207c478bd9Sstevel@tonic-gate * while (count != 0) { 4217c478bd9Sstevel@tonic-gate * sq->sq_flags |= SQ_WANTWAKEUP; 4227c478bd9Sstevel@tonic-gate * SQ_PUTLOCKS_EXIT(sq); 4237c478bd9Sstevel@tonic-gate * cv_wait(&sq->sq_wait, SQLOCK(sq)); 4247c478bd9Sstevel@tonic-gate * count = sq->sq_count; 4257c478bd9Sstevel@tonic-gate * SQ_PUTLOCKS_ENTER(sq); 4267c478bd9Sstevel@tonic-gate * SUM_SQ_PUTCOUNTS(sq, count); 4277c478bd9Sstevel@tonic-gate * } 4287c478bd9Sstevel@tonic-gate * SQ_PUTLOCKS_EXIT(sq); 4297c478bd9Sstevel@tonic-gate * mutex_exit(SQLOCK(sq)); 4307c478bd9Sstevel@tonic-gate * 4317c478bd9Sstevel@tonic-gate * Note that SQ_WANTWAKEUP is set before dropping SQ_PUTLOCKS. This makes sure 4327c478bd9Sstevel@tonic-gate * putnext won't skip a wakeup. 4337c478bd9Sstevel@tonic-gate * 4347c478bd9Sstevel@tonic-gate * sq_putlocks are treated as the extension of SQLOCK for lock ordering 4357c478bd9Sstevel@tonic-gate * purposes and are always grabbed right after grabbing SQLOCK and released 4367c478bd9Sstevel@tonic-gate * right before releasing SQLOCK. This also allows dynamic creation of 4377c478bd9Sstevel@tonic-gate * sq_putlocks while holding SQLOCK (by making sq_ciputctrl non null even when 4387c478bd9Sstevel@tonic-gate * the stream is already in use). Only in putnext one of sq_putlocks 4397c478bd9Sstevel@tonic-gate * is grabbed instead of SQLOCK. putnext return path remembers what counter it 4407c478bd9Sstevel@tonic-gate * incremented and decrements the right counter on its way out. 4417c478bd9Sstevel@tonic-gate */ 4427c478bd9Sstevel@tonic-gate 4437c478bd9Sstevel@tonic-gate struct syncq { 4447c478bd9Sstevel@tonic-gate kmutex_t sq_lock; /* atomic access to syncq */ 4457c478bd9Sstevel@tonic-gate uint16_t sq_count; /* # threads inside */ 4467c478bd9Sstevel@tonic-gate uint16_t sq_flags; /* state and some type info */ 4477c478bd9Sstevel@tonic-gate /* 4487c478bd9Sstevel@tonic-gate * Distributed syncq scheduling 4497c478bd9Sstevel@tonic-gate * The list of queue's is handled by sq_head and 4507c478bd9Sstevel@tonic-gate * sq_tail fields. 4517c478bd9Sstevel@tonic-gate * 4527c478bd9Sstevel@tonic-gate * The list of events is handled by the sq_evhead and sq_evtail 4537c478bd9Sstevel@tonic-gate * fields. 4547c478bd9Sstevel@tonic-gate */ 4557c478bd9Sstevel@tonic-gate queue_t *sq_head; /* queue of deferred messages */ 4567c478bd9Sstevel@tonic-gate queue_t *sq_tail; /* queue of deferred messages */ 4577c478bd9Sstevel@tonic-gate mblk_t *sq_evhead; /* Event message on the syncq */ 4587c478bd9Sstevel@tonic-gate mblk_t *sq_evtail; 4597c478bd9Sstevel@tonic-gate uint_t sq_nqueues; /* # of queues on this sq */ 4607c478bd9Sstevel@tonic-gate /* 4617c478bd9Sstevel@tonic-gate * Concurrency and condition variables 4627c478bd9Sstevel@tonic-gate */ 4637c478bd9Sstevel@tonic-gate uint16_t sq_type; /* type (concurrency) of syncq */ 4647c478bd9Sstevel@tonic-gate uint16_t sq_rmqcount; /* # threads inside removeq() */ 4657c478bd9Sstevel@tonic-gate kcondvar_t sq_wait; /* block on this sync queue */ 4667c478bd9Sstevel@tonic-gate kcondvar_t sq_exitwait; /* waiting for thread to leave the */ 4677c478bd9Sstevel@tonic-gate /* inner perimeter */ 4687c478bd9Sstevel@tonic-gate /* 4697c478bd9Sstevel@tonic-gate * Handling synchronous callbacks such as qtimeout and qbufcall 4707c478bd9Sstevel@tonic-gate */ 4717c478bd9Sstevel@tonic-gate ushort_t sq_callbflags; /* flags for callback synchronization */ 4727c478bd9Sstevel@tonic-gate callbparams_id_t sq_cancelid; /* id of callback being cancelled */ 4737c478bd9Sstevel@tonic-gate struct callbparams *sq_callbpend; /* Pending callbacks */ 4747c478bd9Sstevel@tonic-gate 4757c478bd9Sstevel@tonic-gate /* 4767c478bd9Sstevel@tonic-gate * Links forming an outer perimeter from one outer syncq and 4777c478bd9Sstevel@tonic-gate * a set of inner sync queues. 4787c478bd9Sstevel@tonic-gate */ 4797c478bd9Sstevel@tonic-gate struct syncq *sq_outer; /* Pointer to outer perimeter */ 4807c478bd9Sstevel@tonic-gate struct syncq *sq_onext; /* Linked list of syncq's making */ 4817c478bd9Sstevel@tonic-gate struct syncq *sq_oprev; /* up the outer perimeter. */ 4827c478bd9Sstevel@tonic-gate /* 4837c478bd9Sstevel@tonic-gate * support for low contention concurrent putnext. 4847c478bd9Sstevel@tonic-gate */ 4857c478bd9Sstevel@tonic-gate ciputctrl_t *sq_ciputctrl; 4867c478bd9Sstevel@tonic-gate uint_t sq_nciputctrl; 4877c478bd9Sstevel@tonic-gate /* 4887c478bd9Sstevel@tonic-gate * Counter for the number of threads wanting to become exclusive. 4897c478bd9Sstevel@tonic-gate */ 4907c478bd9Sstevel@tonic-gate uint_t sq_needexcl; 4917c478bd9Sstevel@tonic-gate /* 4927c478bd9Sstevel@tonic-gate * These two fields are used for scheduling a syncq for 4937c478bd9Sstevel@tonic-gate * background processing. The sq_svcflag is protected by 4947c478bd9Sstevel@tonic-gate * SQLOCK lock. 4957c478bd9Sstevel@tonic-gate */ 4967c478bd9Sstevel@tonic-gate struct syncq *sq_next; /* for syncq scheduling */ 4977c478bd9Sstevel@tonic-gate void * sq_servid; 4987c478bd9Sstevel@tonic-gate uint_t sq_servcount; /* # pending background threads */ 4997c478bd9Sstevel@tonic-gate uint_t sq_svcflags; /* Scheduling flags */ 5007c478bd9Sstevel@tonic-gate clock_t sq_tstamp; /* Time when was enabled */ 5017c478bd9Sstevel@tonic-gate /* 5027c478bd9Sstevel@tonic-gate * Maximum priority of the queues on this syncq. 5037c478bd9Sstevel@tonic-gate */ 5047c478bd9Sstevel@tonic-gate pri_t sq_pri; 5057c478bd9Sstevel@tonic-gate }; 5067c478bd9Sstevel@tonic-gate typedef struct syncq syncq_t; 5077c478bd9Sstevel@tonic-gate 5087c478bd9Sstevel@tonic-gate /* 5097c478bd9Sstevel@tonic-gate * sync queue scheduling flags (for sq_svcflags). 5107c478bd9Sstevel@tonic-gate */ 5117c478bd9Sstevel@tonic-gate #define SQ_SERVICE 0x1 /* being serviced */ 5127c478bd9Sstevel@tonic-gate #define SQ_BGTHREAD 0x2 /* awaiting service by bg thread */ 5137c478bd9Sstevel@tonic-gate #define SQ_DISABLED 0x4 /* don't put syncq in service list */ 5147c478bd9Sstevel@tonic-gate 5157c478bd9Sstevel@tonic-gate /* 5167c478bd9Sstevel@tonic-gate * FASTPUT bit in sd_count/putcount. 5177c478bd9Sstevel@tonic-gate */ 5187c478bd9Sstevel@tonic-gate #define SQ_FASTPUT 0x8000 5197c478bd9Sstevel@tonic-gate #define SQ_FASTMASK 0x7FFF 5207c478bd9Sstevel@tonic-gate 5217c478bd9Sstevel@tonic-gate /* 5227c478bd9Sstevel@tonic-gate * sync queue state flags 5237c478bd9Sstevel@tonic-gate */ 5247c478bd9Sstevel@tonic-gate #define SQ_EXCL 0x0001 /* exclusive access to inner */ 5257c478bd9Sstevel@tonic-gate /* perimeter */ 5267c478bd9Sstevel@tonic-gate #define SQ_BLOCKED 0x0002 /* qprocsoff */ 5277c478bd9Sstevel@tonic-gate #define SQ_FROZEN 0x0004 /* freezestr */ 5287c478bd9Sstevel@tonic-gate #define SQ_WRITER 0x0008 /* qwriter(OUTER) pending or running */ 5297c478bd9Sstevel@tonic-gate #define SQ_MESSAGES 0x0010 /* messages on syncq */ 5307c478bd9Sstevel@tonic-gate #define SQ_WANTWAKEUP 0x0020 /* do cv_broadcast on sq_wait */ 5317c478bd9Sstevel@tonic-gate #define SQ_WANTEXWAKEUP 0x0040 /* do cv_broadcast on sq_exitwait */ 5327c478bd9Sstevel@tonic-gate #define SQ_EVENTS 0x0080 /* Events pending */ 5337c478bd9Sstevel@tonic-gate #define SQ_QUEUED (SQ_MESSAGES | SQ_EVENTS) 5347c478bd9Sstevel@tonic-gate #define SQ_FLAGMASK 0x00FF 5357c478bd9Sstevel@tonic-gate 5367c478bd9Sstevel@tonic-gate /* 5377c478bd9Sstevel@tonic-gate * Test a queue to see if inner perimeter is exclusive. 5387c478bd9Sstevel@tonic-gate */ 5397c478bd9Sstevel@tonic-gate #define PERIM_EXCL(q) ((q)->q_syncq->sq_flags & SQ_EXCL) 5407c478bd9Sstevel@tonic-gate 5417c478bd9Sstevel@tonic-gate /* 5427c478bd9Sstevel@tonic-gate * If any of these flags are set it is not possible for a thread to 5437c478bd9Sstevel@tonic-gate * enter a put or service procedure. Instead it must either block 5447c478bd9Sstevel@tonic-gate * or put the message on the syncq. 5457c478bd9Sstevel@tonic-gate */ 5467c478bd9Sstevel@tonic-gate #define SQ_GOAWAY (SQ_EXCL|SQ_BLOCKED|SQ_FROZEN|SQ_WRITER|\ 5477c478bd9Sstevel@tonic-gate SQ_QUEUED) 5487c478bd9Sstevel@tonic-gate /* 5497c478bd9Sstevel@tonic-gate * If any of these flags are set it not possible to drain the syncq 5507c478bd9Sstevel@tonic-gate */ 5517c478bd9Sstevel@tonic-gate #define SQ_STAYAWAY (SQ_BLOCKED|SQ_FROZEN|SQ_WRITER) 5527c478bd9Sstevel@tonic-gate 5537c478bd9Sstevel@tonic-gate /* 5547c478bd9Sstevel@tonic-gate * Flags to trigger syncq tail processing. 5557c478bd9Sstevel@tonic-gate */ 5567c478bd9Sstevel@tonic-gate #define SQ_TAIL (SQ_QUEUED|SQ_WANTWAKEUP|SQ_WANTEXWAKEUP) 5577c478bd9Sstevel@tonic-gate 5587c478bd9Sstevel@tonic-gate /* 5597c478bd9Sstevel@tonic-gate * Syncq types (stored in sq_type) 5607c478bd9Sstevel@tonic-gate * The SQ_TYPES_IN_FLAGS (ciput) are also stored in sq_flags 5617c478bd9Sstevel@tonic-gate * for performance reasons. Thus these type values have to be in the low 5627c478bd9Sstevel@tonic-gate * 16 bits and not conflict with the sq_flags values above. 5637c478bd9Sstevel@tonic-gate * 5647c478bd9Sstevel@tonic-gate * Notes: 5657c478bd9Sstevel@tonic-gate * - putnext() and put() assume that the put procedures have the highest 5667c478bd9Sstevel@tonic-gate * degree of concurrency. Thus if any of the SQ_CI* are set then SQ_CIPUT 5677c478bd9Sstevel@tonic-gate * has to be set. This restriction can be lifted by adding code to putnext 5687c478bd9Sstevel@tonic-gate * and put that check that sq_count == 0 like entersq does. 5697c478bd9Sstevel@tonic-gate * - putnext() and put() does currently not handle !SQ_COPUT 5707c478bd9Sstevel@tonic-gate * - In order to implement !SQ_COCB outer_enter has to be fixed so that 5717c478bd9Sstevel@tonic-gate * the callback can be cancelled while cv_waiting in outer_enter. 5727c478bd9Sstevel@tonic-gate * - If SQ_CISVC needs to be implemented, qprocsoff() needs to wait 5737c478bd9Sstevel@tonic-gate * for the currently running services to stop (wait for QINSERVICE 5747c478bd9Sstevel@tonic-gate * to go off). disable_svc called from qprcosoff disables only 5757c478bd9Sstevel@tonic-gate * services that will be run in future. 5767c478bd9Sstevel@tonic-gate * 5777c478bd9Sstevel@tonic-gate * All the SQ_CO flags are set when there is no outer perimeter. 5787c478bd9Sstevel@tonic-gate */ 5797c478bd9Sstevel@tonic-gate #define SQ_CIPUT 0x0100 /* Concurrent inner put proc */ 5807c478bd9Sstevel@tonic-gate #define SQ_CISVC 0x0200 /* Concurrent inner svc proc */ 5817c478bd9Sstevel@tonic-gate #define SQ_CIOC 0x0400 /* Concurrent inner open/close */ 5827c478bd9Sstevel@tonic-gate #define SQ_CICB 0x0800 /* Concurrent inner callback */ 5837c478bd9Sstevel@tonic-gate #define SQ_COPUT 0x1000 /* Concurrent outer put proc */ 5847c478bd9Sstevel@tonic-gate #define SQ_COSVC 0x2000 /* Concurrent outer svc proc */ 5857c478bd9Sstevel@tonic-gate #define SQ_COOC 0x4000 /* Concurrent outer open/close */ 5867c478bd9Sstevel@tonic-gate #define SQ_COCB 0x8000 /* Concurrent outer callback */ 5877c478bd9Sstevel@tonic-gate 5887c478bd9Sstevel@tonic-gate /* Types also kept in sq_flags for performance */ 5897c478bd9Sstevel@tonic-gate #define SQ_TYPES_IN_FLAGS (SQ_CIPUT) 5907c478bd9Sstevel@tonic-gate 5917c478bd9Sstevel@tonic-gate #define SQ_CI (SQ_CIPUT|SQ_CISVC|SQ_CIOC|SQ_CICB) 5927c478bd9Sstevel@tonic-gate #define SQ_CO (SQ_COPUT|SQ_COSVC|SQ_COOC|SQ_COCB) 5937c478bd9Sstevel@tonic-gate #define SQ_TYPEMASK (SQ_CI|SQ_CO) 5947c478bd9Sstevel@tonic-gate 5957c478bd9Sstevel@tonic-gate /* 5967c478bd9Sstevel@tonic-gate * Flag combinations passed to entersq and leavesq to specify the type 5977c478bd9Sstevel@tonic-gate * of entry point. 5987c478bd9Sstevel@tonic-gate */ 5997c478bd9Sstevel@tonic-gate #define SQ_PUT (SQ_CIPUT|SQ_COPUT) 6007c478bd9Sstevel@tonic-gate #define SQ_SVC (SQ_CISVC|SQ_COSVC) 6017c478bd9Sstevel@tonic-gate #define SQ_OPENCLOSE (SQ_CIOC|SQ_COOC) 6027c478bd9Sstevel@tonic-gate #define SQ_CALLBACK (SQ_CICB|SQ_COCB) 6037c478bd9Sstevel@tonic-gate 6047c478bd9Sstevel@tonic-gate /* 6057c478bd9Sstevel@tonic-gate * Other syncq types which are not copied into flags. 6067c478bd9Sstevel@tonic-gate */ 6077c478bd9Sstevel@tonic-gate #define SQ_PERMOD 0x01 /* Syncq is PERMOD */ 6087c478bd9Sstevel@tonic-gate 6097c478bd9Sstevel@tonic-gate /* 6107c478bd9Sstevel@tonic-gate * Asynchronous callback qun*** flag. 6117c478bd9Sstevel@tonic-gate * The mechanism these flags are used in is one where callbacks enter 6127c478bd9Sstevel@tonic-gate * the perimeter thanks to framework support. To use this mechanism 6137c478bd9Sstevel@tonic-gate * the q* and qun* flavors of the callback routines must be used. 6147c478bd9Sstevel@tonic-gate * e.g. qtimeout and quntimeout. The synchronization provided by the flags 6157c478bd9Sstevel@tonic-gate * avoids deadlocks between blocking qun* routines and the perimeter 6167c478bd9Sstevel@tonic-gate * lock. 6177c478bd9Sstevel@tonic-gate */ 6187c478bd9Sstevel@tonic-gate #define SQ_CALLB_BYPASSED 0x01 /* bypassed callback fn */ 6197c478bd9Sstevel@tonic-gate 6207c478bd9Sstevel@tonic-gate /* 6217c478bd9Sstevel@tonic-gate * Cancel callback mask. 6227c478bd9Sstevel@tonic-gate * The mask expands as the number of cancelable callback types grows 6237c478bd9Sstevel@tonic-gate * Note - separate callback flag because different callbacks have 6247c478bd9Sstevel@tonic-gate * overlapping id space. 6257c478bd9Sstevel@tonic-gate */ 6267c478bd9Sstevel@tonic-gate #define SQ_CALLB_CANCEL_MASK (SQ_CANCEL_TOUT|SQ_CANCEL_BUFCALL) 6277c478bd9Sstevel@tonic-gate 6287c478bd9Sstevel@tonic-gate #define SQ_CANCEL_TOUT 0x02 /* cancel timeout request */ 6297c478bd9Sstevel@tonic-gate #define SQ_CANCEL_BUFCALL 0x04 /* cancel bufcall request */ 6307c478bd9Sstevel@tonic-gate 6317c478bd9Sstevel@tonic-gate typedef struct callbparams { 6327c478bd9Sstevel@tonic-gate syncq_t *cbp_sq; 6337c478bd9Sstevel@tonic-gate void (*cbp_func)(void *); 6347c478bd9Sstevel@tonic-gate void *cbp_arg; 6357c478bd9Sstevel@tonic-gate callbparams_id_t cbp_id; 6367c478bd9Sstevel@tonic-gate uint_t cbp_flags; 6377c478bd9Sstevel@tonic-gate struct callbparams *cbp_next; 6387c478bd9Sstevel@tonic-gate size_t cbp_size; 6397c478bd9Sstevel@tonic-gate } callbparams_t; 6407c478bd9Sstevel@tonic-gate 6417c478bd9Sstevel@tonic-gate typedef struct strbufcall { 6427c478bd9Sstevel@tonic-gate void (*bc_func)(void *); 6437c478bd9Sstevel@tonic-gate void *bc_arg; 6447c478bd9Sstevel@tonic-gate size_t bc_size; 6457c478bd9Sstevel@tonic-gate bufcall_id_t bc_id; 6467c478bd9Sstevel@tonic-gate struct strbufcall *bc_next; 6477c478bd9Sstevel@tonic-gate kthread_id_t bc_executor; 6487c478bd9Sstevel@tonic-gate } strbufcall_t; 6497c478bd9Sstevel@tonic-gate 6507c478bd9Sstevel@tonic-gate /* 6517c478bd9Sstevel@tonic-gate * Structure of list of processes to be sent SIGPOLL/SIGURG signal 6527c478bd9Sstevel@tonic-gate * on request. The valid S_* events are defined in stropts.h. 6537c478bd9Sstevel@tonic-gate */ 6547c478bd9Sstevel@tonic-gate typedef struct strsig { 6557c478bd9Sstevel@tonic-gate struct pid *ss_pidp; /* pid/pgrp pointer */ 6567c478bd9Sstevel@tonic-gate pid_t ss_pid; /* positive pid, negative pgrp */ 6577c478bd9Sstevel@tonic-gate int ss_events; /* S_* events */ 6587c478bd9Sstevel@tonic-gate struct strsig *ss_next; 6597c478bd9Sstevel@tonic-gate } strsig_t; 6607c478bd9Sstevel@tonic-gate 6617c478bd9Sstevel@tonic-gate /* 6627c478bd9Sstevel@tonic-gate * bufcall list 6637c478bd9Sstevel@tonic-gate */ 6647c478bd9Sstevel@tonic-gate struct bclist { 6657c478bd9Sstevel@tonic-gate strbufcall_t *bc_head; 6667c478bd9Sstevel@tonic-gate strbufcall_t *bc_tail; 6677c478bd9Sstevel@tonic-gate }; 6687c478bd9Sstevel@tonic-gate 6697c478bd9Sstevel@tonic-gate /* 6707c478bd9Sstevel@tonic-gate * Structure used to track mux links and unlinks. 6717c478bd9Sstevel@tonic-gate */ 6727c478bd9Sstevel@tonic-gate struct mux_node { 6737c478bd9Sstevel@tonic-gate major_t mn_imaj; /* internal major device number */ 6747c478bd9Sstevel@tonic-gate uint16_t mn_indegree; /* number of incoming edges */ 6757c478bd9Sstevel@tonic-gate struct mux_node *mn_originp; /* where we came from during search */ 6767c478bd9Sstevel@tonic-gate struct mux_edge *mn_startp; /* where search left off in mn_outp */ 6777c478bd9Sstevel@tonic-gate struct mux_edge *mn_outp; /* list of outgoing edges */ 6787c478bd9Sstevel@tonic-gate uint_t mn_flags; /* see below */ 6797c478bd9Sstevel@tonic-gate }; 6807c478bd9Sstevel@tonic-gate 6817c478bd9Sstevel@tonic-gate /* 6827c478bd9Sstevel@tonic-gate * Flags for mux_nodes. 6837c478bd9Sstevel@tonic-gate */ 6847c478bd9Sstevel@tonic-gate #define VISITED 1 6857c478bd9Sstevel@tonic-gate 6867c478bd9Sstevel@tonic-gate /* 6877c478bd9Sstevel@tonic-gate * Edge structure - a list of these is hung off the 6887c478bd9Sstevel@tonic-gate * mux_node to represent the outgoing edges. 6897c478bd9Sstevel@tonic-gate */ 6907c478bd9Sstevel@tonic-gate struct mux_edge { 6917c478bd9Sstevel@tonic-gate struct mux_node *me_nodep; /* edge leads to this node */ 6927c478bd9Sstevel@tonic-gate struct mux_edge *me_nextp; /* next edge */ 6937c478bd9Sstevel@tonic-gate int me_muxid; /* id of link */ 694f4b3ec61Sdh155122 dev_t me_dev; /* dev_t - used for kernel PUNLINK */ 6957c478bd9Sstevel@tonic-gate }; 6967c478bd9Sstevel@tonic-gate 6977c478bd9Sstevel@tonic-gate /* 6987c478bd9Sstevel@tonic-gate * Queue info 6997c478bd9Sstevel@tonic-gate * 7007c478bd9Sstevel@tonic-gate * The syncq is included here to reduce memory fragmentation 7017c478bd9Sstevel@tonic-gate * for kernel memory allocators that only allocate in sizes that are 7027c478bd9Sstevel@tonic-gate * powers of two. If the kernel memory allocator changes this should 7037c478bd9Sstevel@tonic-gate * be revisited. 7047c478bd9Sstevel@tonic-gate */ 7057c478bd9Sstevel@tonic-gate typedef struct queinfo { 7067c478bd9Sstevel@tonic-gate struct queue qu_rqueue; /* read queue - must be first */ 7077c478bd9Sstevel@tonic-gate struct queue qu_wqueue; /* write queue - must be second */ 7087c478bd9Sstevel@tonic-gate struct syncq qu_syncq; /* syncq - must be third */ 7097c478bd9Sstevel@tonic-gate } queinfo_t; 7107c478bd9Sstevel@tonic-gate 7117c478bd9Sstevel@tonic-gate /* 7127c478bd9Sstevel@tonic-gate * Multiplexed streams info 7137c478bd9Sstevel@tonic-gate */ 7147c478bd9Sstevel@tonic-gate typedef struct linkinfo { 7157c478bd9Sstevel@tonic-gate struct linkblk li_lblk; /* must be first */ 7167c478bd9Sstevel@tonic-gate struct file *li_fpdown; /* file pointer for lower stream */ 7177c478bd9Sstevel@tonic-gate struct linkinfo *li_next; /* next in list */ 7187c478bd9Sstevel@tonic-gate struct linkinfo *li_prev; /* previous in list */ 7197c478bd9Sstevel@tonic-gate } linkinfo_t; 7207c478bd9Sstevel@tonic-gate 7217c478bd9Sstevel@tonic-gate /* 7227c478bd9Sstevel@tonic-gate * List of syncq's used by freeezestr/unfreezestr 7237c478bd9Sstevel@tonic-gate */ 7247c478bd9Sstevel@tonic-gate typedef struct syncql { 7257c478bd9Sstevel@tonic-gate struct syncql *sql_next; 7267c478bd9Sstevel@tonic-gate syncq_t *sql_sq; 7277c478bd9Sstevel@tonic-gate } syncql_t; 7287c478bd9Sstevel@tonic-gate 7297c478bd9Sstevel@tonic-gate typedef struct sqlist { 7307c478bd9Sstevel@tonic-gate syncql_t *sqlist_head; 7317c478bd9Sstevel@tonic-gate size_t sqlist_size; /* structure size in bytes */ 7327c478bd9Sstevel@tonic-gate size_t sqlist_index; /* next free entry in array */ 7337c478bd9Sstevel@tonic-gate syncql_t sqlist_array[4]; /* 4 or more entries */ 7347c478bd9Sstevel@tonic-gate } sqlist_t; 7357c478bd9Sstevel@tonic-gate 7367c478bd9Sstevel@tonic-gate typedef struct perdm { 7377c478bd9Sstevel@tonic-gate struct perdm *dm_next; 7387c478bd9Sstevel@tonic-gate syncq_t *dm_sq; 7397c478bd9Sstevel@tonic-gate struct streamtab *dm_str; 7407c478bd9Sstevel@tonic-gate uint_t dm_ref; 7417c478bd9Sstevel@tonic-gate } perdm_t; 7427c478bd9Sstevel@tonic-gate 7437c478bd9Sstevel@tonic-gate #define NEED_DM(dmp, qflag) \ 7447c478bd9Sstevel@tonic-gate (dmp == NULL && (qflag & (QPERMOD | QMTOUTPERIM))) 7457c478bd9Sstevel@tonic-gate 7467c478bd9Sstevel@tonic-gate /* 7477c478bd9Sstevel@tonic-gate * fmodsw_impl_t is used within the kernel. fmodsw is used by 7487c478bd9Sstevel@tonic-gate * the modules/drivers. The information is copied from fmodsw 7497c478bd9Sstevel@tonic-gate * defined in the module/driver into the fmodsw_impl_t structure 7507c478bd9Sstevel@tonic-gate * during the module/driver initialization. 7517c478bd9Sstevel@tonic-gate */ 7527c478bd9Sstevel@tonic-gate typedef struct fmodsw_impl fmodsw_impl_t; 7537c478bd9Sstevel@tonic-gate 7547c478bd9Sstevel@tonic-gate struct fmodsw_impl { 7557c478bd9Sstevel@tonic-gate fmodsw_impl_t *f_next; 7567c478bd9Sstevel@tonic-gate char f_name[FMNAMESZ + 1]; 7577c478bd9Sstevel@tonic-gate struct streamtab *f_str; 7587c478bd9Sstevel@tonic-gate uint32_t f_qflag; 7597c478bd9Sstevel@tonic-gate uint32_t f_sqtype; 7607c478bd9Sstevel@tonic-gate perdm_t *f_dmp; 7617c478bd9Sstevel@tonic-gate uint32_t f_ref; 7627c478bd9Sstevel@tonic-gate uint32_t f_hits; 7637c478bd9Sstevel@tonic-gate }; 7647c478bd9Sstevel@tonic-gate 7657c478bd9Sstevel@tonic-gate typedef enum { 7667c478bd9Sstevel@tonic-gate FMODSW_HOLD = 0x00000001, 7677c478bd9Sstevel@tonic-gate FMODSW_LOAD = 0x00000002 7687c478bd9Sstevel@tonic-gate } fmodsw_flags_t; 7697c478bd9Sstevel@tonic-gate 7707c478bd9Sstevel@tonic-gate typedef struct cdevsw_impl { 7717c478bd9Sstevel@tonic-gate struct streamtab *d_str; 7727c478bd9Sstevel@tonic-gate uint32_t d_qflag; 7737c478bd9Sstevel@tonic-gate uint32_t d_sqtype; 7747c478bd9Sstevel@tonic-gate perdm_t *d_dmp; 7757c478bd9Sstevel@tonic-gate } cdevsw_impl_t; 7767c478bd9Sstevel@tonic-gate 7777c478bd9Sstevel@tonic-gate /* 778ad1660d0Smeem * Enumeration of the types of access that can be requested for a 779ad1660d0Smeem * controlling terminal under job control. 780ad1660d0Smeem */ 781ad1660d0Smeem enum jcaccess { 782ad1660d0Smeem JCREAD, /* read data on a ctty */ 783ad1660d0Smeem JCWRITE, /* write data to a ctty */ 784ad1660d0Smeem JCSETP, /* set ctty parameters */ 785ad1660d0Smeem JCGETP /* get ctty parameters */ 786ad1660d0Smeem }; 787ad1660d0Smeem 788f4b3ec61Sdh155122 struct str_stack { 789f4b3ec61Sdh155122 netstack_t *ss_netstack; /* Common netstack */ 790f4b3ec61Sdh155122 791f4b3ec61Sdh155122 kmutex_t ss_sad_lock; /* autopush lock */ 792f4b3ec61Sdh155122 mod_hash_t *ss_sad_hash; 793f4b3ec61Sdh155122 size_t ss_sad_hash_nchains; 794f4b3ec61Sdh155122 struct saddev *ss_saddev; /* sad device array */ 795f4b3ec61Sdh155122 int ss_sadcnt; /* number of sad devices */ 796f4b3ec61Sdh155122 797f4b3ec61Sdh155122 int ss_devcnt; /* number of mux_nodes */ 798f4b3ec61Sdh155122 struct mux_node *ss_mux_nodes; /* mux info for cycle checking */ 799f4b3ec61Sdh155122 }; 800f4b3ec61Sdh155122 typedef struct str_stack str_stack_t; 801f4b3ec61Sdh155122 802ad1660d0Smeem /* 8037c478bd9Sstevel@tonic-gate * Finding related queues 8047c478bd9Sstevel@tonic-gate */ 8057c478bd9Sstevel@tonic-gate #define STREAM(q) ((q)->q_stream) 8067c478bd9Sstevel@tonic-gate #define SQ(rq) ((syncq_t *)((rq) + 2)) 8077c478bd9Sstevel@tonic-gate 8087c478bd9Sstevel@tonic-gate /* 8097c478bd9Sstevel@tonic-gate * Locking macros 8107c478bd9Sstevel@tonic-gate */ 8117c478bd9Sstevel@tonic-gate #define QLOCK(q) (&(q)->q_lock) 8127c478bd9Sstevel@tonic-gate #define SQLOCK(sq) (&(sq)->sq_lock) 8137c478bd9Sstevel@tonic-gate 8147c478bd9Sstevel@tonic-gate #define STREAM_PUTLOCKS_ENTER(stp) { \ 8157c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&(stp)->sd_lock)); \ 8167c478bd9Sstevel@tonic-gate if ((stp)->sd_ciputctrl != NULL) { \ 8177c478bd9Sstevel@tonic-gate int i; \ 8187c478bd9Sstevel@tonic-gate int nlocks = (stp)->sd_nciputctrl; \ 8197c478bd9Sstevel@tonic-gate ciputctrl_t *cip = (stp)->sd_ciputctrl; \ 8207c478bd9Sstevel@tonic-gate for (i = 0; i <= nlocks; i++) { \ 8217c478bd9Sstevel@tonic-gate mutex_enter(&cip[i].ciputctrl_lock); \ 8227c478bd9Sstevel@tonic-gate } \ 8237c478bd9Sstevel@tonic-gate } \ 8247c478bd9Sstevel@tonic-gate } 8257c478bd9Sstevel@tonic-gate 8267c478bd9Sstevel@tonic-gate #define STREAM_PUTLOCKS_EXIT(stp) { \ 8277c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&(stp)->sd_lock)); \ 8287c478bd9Sstevel@tonic-gate if ((stp)->sd_ciputctrl != NULL) { \ 8297c478bd9Sstevel@tonic-gate int i; \ 8307c478bd9Sstevel@tonic-gate int nlocks = (stp)->sd_nciputctrl; \ 8317c478bd9Sstevel@tonic-gate ciputctrl_t *cip = (stp)->sd_ciputctrl; \ 8327c478bd9Sstevel@tonic-gate for (i = 0; i <= nlocks; i++) { \ 8337c478bd9Sstevel@tonic-gate mutex_exit(&cip[i].ciputctrl_lock); \ 8347c478bd9Sstevel@tonic-gate } \ 8357c478bd9Sstevel@tonic-gate } \ 8367c478bd9Sstevel@tonic-gate } 8377c478bd9Sstevel@tonic-gate 8387c478bd9Sstevel@tonic-gate #define SQ_PUTLOCKS_ENTER(sq) { \ 8397c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(SQLOCK(sq))); \ 8407c478bd9Sstevel@tonic-gate if ((sq)->sq_ciputctrl != NULL) { \ 8417c478bd9Sstevel@tonic-gate int i; \ 8427c478bd9Sstevel@tonic-gate int nlocks = (sq)->sq_nciputctrl; \ 8437c478bd9Sstevel@tonic-gate ciputctrl_t *cip = (sq)->sq_ciputctrl; \ 8447c478bd9Sstevel@tonic-gate ASSERT((sq)->sq_type & SQ_CIPUT); \ 8457c478bd9Sstevel@tonic-gate for (i = 0; i <= nlocks; i++) { \ 8467c478bd9Sstevel@tonic-gate mutex_enter(&cip[i].ciputctrl_lock); \ 8477c478bd9Sstevel@tonic-gate } \ 8487c478bd9Sstevel@tonic-gate } \ 8497c478bd9Sstevel@tonic-gate } 8507c478bd9Sstevel@tonic-gate 8517c478bd9Sstevel@tonic-gate #define SQ_PUTLOCKS_EXIT(sq) { \ 8527c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(SQLOCK(sq))); \ 8537c478bd9Sstevel@tonic-gate if ((sq)->sq_ciputctrl != NULL) { \ 8547c478bd9Sstevel@tonic-gate int i; \ 8557c478bd9Sstevel@tonic-gate int nlocks = (sq)->sq_nciputctrl; \ 8567c478bd9Sstevel@tonic-gate ciputctrl_t *cip = (sq)->sq_ciputctrl; \ 8577c478bd9Sstevel@tonic-gate ASSERT((sq)->sq_type & SQ_CIPUT); \ 8587c478bd9Sstevel@tonic-gate for (i = 0; i <= nlocks; i++) { \ 8597c478bd9Sstevel@tonic-gate mutex_exit(&cip[i].ciputctrl_lock); \ 8607c478bd9Sstevel@tonic-gate } \ 8617c478bd9Sstevel@tonic-gate } \ 8627c478bd9Sstevel@tonic-gate } 8637c478bd9Sstevel@tonic-gate 8647c478bd9Sstevel@tonic-gate #define SQ_PUTCOUNT_SETFAST(sq) { \ 8657c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(SQLOCK(sq))); \ 8667c478bd9Sstevel@tonic-gate if ((sq)->sq_ciputctrl != NULL) { \ 8677c478bd9Sstevel@tonic-gate int i; \ 8687c478bd9Sstevel@tonic-gate int nlocks = (sq)->sq_nciputctrl; \ 8697c478bd9Sstevel@tonic-gate ciputctrl_t *cip = (sq)->sq_ciputctrl; \ 8707c478bd9Sstevel@tonic-gate ASSERT((sq)->sq_type & SQ_CIPUT); \ 8717c478bd9Sstevel@tonic-gate for (i = 0; i <= nlocks; i++) { \ 8727c478bd9Sstevel@tonic-gate mutex_enter(&cip[i].ciputctrl_lock); \ 8737c478bd9Sstevel@tonic-gate cip[i].ciputctrl_count |= SQ_FASTPUT; \ 8747c478bd9Sstevel@tonic-gate mutex_exit(&cip[i].ciputctrl_lock); \ 8757c478bd9Sstevel@tonic-gate } \ 8767c478bd9Sstevel@tonic-gate } \ 8777c478bd9Sstevel@tonic-gate } 8787c478bd9Sstevel@tonic-gate 8797c478bd9Sstevel@tonic-gate #define SQ_PUTCOUNT_CLRFAST(sq) { \ 8807c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(SQLOCK(sq))); \ 8817c478bd9Sstevel@tonic-gate if ((sq)->sq_ciputctrl != NULL) { \ 8827c478bd9Sstevel@tonic-gate int i; \ 8837c478bd9Sstevel@tonic-gate int nlocks = (sq)->sq_nciputctrl; \ 8847c478bd9Sstevel@tonic-gate ciputctrl_t *cip = (sq)->sq_ciputctrl; \ 8857c478bd9Sstevel@tonic-gate ASSERT((sq)->sq_type & SQ_CIPUT); \ 8867c478bd9Sstevel@tonic-gate for (i = 0; i <= nlocks; i++) { \ 8877c478bd9Sstevel@tonic-gate mutex_enter(&cip[i].ciputctrl_lock); \ 8887c478bd9Sstevel@tonic-gate cip[i].ciputctrl_count &= ~SQ_FASTPUT; \ 8897c478bd9Sstevel@tonic-gate mutex_exit(&cip[i].ciputctrl_lock); \ 8907c478bd9Sstevel@tonic-gate } \ 8917c478bd9Sstevel@tonic-gate } \ 8927c478bd9Sstevel@tonic-gate } 8937c478bd9Sstevel@tonic-gate 8947c478bd9Sstevel@tonic-gate 8957c478bd9Sstevel@tonic-gate #ifdef DEBUG 8967c478bd9Sstevel@tonic-gate 8977c478bd9Sstevel@tonic-gate #define SQ_PUTLOCKS_HELD(sq) { \ 8987c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(SQLOCK(sq))); \ 8997c478bd9Sstevel@tonic-gate if ((sq)->sq_ciputctrl != NULL) { \ 9007c478bd9Sstevel@tonic-gate int i; \ 9017c478bd9Sstevel@tonic-gate int nlocks = (sq)->sq_nciputctrl; \ 9027c478bd9Sstevel@tonic-gate ciputctrl_t *cip = (sq)->sq_ciputctrl; \ 9037c478bd9Sstevel@tonic-gate ASSERT((sq)->sq_type & SQ_CIPUT); \ 9047c478bd9Sstevel@tonic-gate for (i = 0; i <= nlocks; i++) { \ 9057c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cip[i].ciputctrl_lock)); \ 9067c478bd9Sstevel@tonic-gate } \ 9077c478bd9Sstevel@tonic-gate } \ 9087c478bd9Sstevel@tonic-gate } 9097c478bd9Sstevel@tonic-gate 9107c478bd9Sstevel@tonic-gate #define SUMCHECK_SQ_PUTCOUNTS(sq, countcheck) { \ 9117c478bd9Sstevel@tonic-gate if ((sq)->sq_ciputctrl != NULL) { \ 9127c478bd9Sstevel@tonic-gate int i; \ 9137c478bd9Sstevel@tonic-gate uint_t count = 0; \ 9147c478bd9Sstevel@tonic-gate int ncounts = (sq)->sq_nciputctrl; \ 9157c478bd9Sstevel@tonic-gate ASSERT((sq)->sq_type & SQ_CIPUT); \ 9167c478bd9Sstevel@tonic-gate for (i = 0; i <= ncounts; i++) { \ 9177c478bd9Sstevel@tonic-gate count += \ 9187c478bd9Sstevel@tonic-gate (((sq)->sq_ciputctrl[i].ciputctrl_count) & \ 9197c478bd9Sstevel@tonic-gate SQ_FASTMASK); \ 9207c478bd9Sstevel@tonic-gate } \ 9217c478bd9Sstevel@tonic-gate ASSERT(count == (countcheck)); \ 9227c478bd9Sstevel@tonic-gate } \ 9237c478bd9Sstevel@tonic-gate } 9247c478bd9Sstevel@tonic-gate 9257c478bd9Sstevel@tonic-gate #define SUMCHECK_CIPUTCTRL_COUNTS(ciput, nciput, countcheck) { \ 9267c478bd9Sstevel@tonic-gate int i; \ 9277c478bd9Sstevel@tonic-gate uint_t count = 0; \ 9287c478bd9Sstevel@tonic-gate ASSERT((ciput) != NULL); \ 9297c478bd9Sstevel@tonic-gate for (i = 0; i <= (nciput); i++) { \ 9307c478bd9Sstevel@tonic-gate count += (((ciput)[i].ciputctrl_count) & \ 9317c478bd9Sstevel@tonic-gate SQ_FASTMASK); \ 9327c478bd9Sstevel@tonic-gate } \ 9337c478bd9Sstevel@tonic-gate ASSERT(count == (countcheck)); \ 9347c478bd9Sstevel@tonic-gate } 9357c478bd9Sstevel@tonic-gate 9367c478bd9Sstevel@tonic-gate #else /* DEBUG */ 9377c478bd9Sstevel@tonic-gate 9387c478bd9Sstevel@tonic-gate #define SQ_PUTLOCKS_HELD(sq) 9397c478bd9Sstevel@tonic-gate #define SUMCHECK_SQ_PUTCOUNTS(sq, countcheck) 9407c478bd9Sstevel@tonic-gate #define SUMCHECK_CIPUTCTRL_COUNTS(sq, nciput, countcheck) 9417c478bd9Sstevel@tonic-gate 9427c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 9437c478bd9Sstevel@tonic-gate 9447c478bd9Sstevel@tonic-gate #define SUM_SQ_PUTCOUNTS(sq, count) { \ 9457c478bd9Sstevel@tonic-gate if ((sq)->sq_ciputctrl != NULL) { \ 9467c478bd9Sstevel@tonic-gate int i; \ 9477c478bd9Sstevel@tonic-gate int ncounts = (sq)->sq_nciputctrl; \ 9487c478bd9Sstevel@tonic-gate ciputctrl_t *cip = (sq)->sq_ciputctrl; \ 9497c478bd9Sstevel@tonic-gate ASSERT((sq)->sq_type & SQ_CIPUT); \ 9507c478bd9Sstevel@tonic-gate for (i = 0; i <= ncounts; i++) { \ 9517c478bd9Sstevel@tonic-gate (count) += ((cip[i].ciputctrl_count) & \ 9527c478bd9Sstevel@tonic-gate SQ_FASTMASK); \ 9537c478bd9Sstevel@tonic-gate } \ 9547c478bd9Sstevel@tonic-gate } \ 9557c478bd9Sstevel@tonic-gate } 9567c478bd9Sstevel@tonic-gate 9577c478bd9Sstevel@tonic-gate #define CLAIM_QNEXT_LOCK(stp) mutex_enter(&(stp)->sd_lock) 9587c478bd9Sstevel@tonic-gate #define RELEASE_QNEXT_LOCK(stp) mutex_exit(&(stp)->sd_lock) 9597c478bd9Sstevel@tonic-gate 9607c478bd9Sstevel@tonic-gate /* 9617c478bd9Sstevel@tonic-gate * syncq message manipulation macros. 9627c478bd9Sstevel@tonic-gate */ 9637c478bd9Sstevel@tonic-gate /* 9647c478bd9Sstevel@tonic-gate * Put a message on the queue syncq. 9657c478bd9Sstevel@tonic-gate * Assumes QLOCK held. 9667c478bd9Sstevel@tonic-gate */ 9677c478bd9Sstevel@tonic-gate #define SQPUT_MP(qp, mp) \ 9687c478bd9Sstevel@tonic-gate { \ 9697c478bd9Sstevel@tonic-gate qp->q_syncqmsgs++; \ 9707c478bd9Sstevel@tonic-gate if (qp->q_sqhead == NULL) { \ 9717c478bd9Sstevel@tonic-gate qp->q_sqhead = qp->q_sqtail = mp; \ 9727c478bd9Sstevel@tonic-gate } else { \ 9737c478bd9Sstevel@tonic-gate qp->q_sqtail->b_next = mp; \ 9747c478bd9Sstevel@tonic-gate qp->q_sqtail = mp; \ 9757c478bd9Sstevel@tonic-gate } \ 9765ba3fab4Sjk115741 set_qfull(qp); \ 9777c478bd9Sstevel@tonic-gate } 9787c478bd9Sstevel@tonic-gate 9797c478bd9Sstevel@tonic-gate /* 9807c478bd9Sstevel@tonic-gate * Miscellaneous parameters and flags. 9817c478bd9Sstevel@tonic-gate */ 9827c478bd9Sstevel@tonic-gate 9837c478bd9Sstevel@tonic-gate /* 9847c478bd9Sstevel@tonic-gate * Default timeout in milliseconds for ioctls and close 9857c478bd9Sstevel@tonic-gate */ 9867c478bd9Sstevel@tonic-gate #define STRTIMOUT 15000 9877c478bd9Sstevel@tonic-gate 9887c478bd9Sstevel@tonic-gate /* 9897c478bd9Sstevel@tonic-gate * Flag values for stream io 9907c478bd9Sstevel@tonic-gate */ 9917c478bd9Sstevel@tonic-gate #define WRITEWAIT 0x1 /* waiting for write event */ 9927c478bd9Sstevel@tonic-gate #define READWAIT 0x2 /* waiting for read event */ 9937c478bd9Sstevel@tonic-gate #define NOINTR 0x4 /* error is not to be set for signal */ 9947c478bd9Sstevel@tonic-gate #define GETWAIT 0x8 /* waiting for getmsg event */ 9957c478bd9Sstevel@tonic-gate 9967c478bd9Sstevel@tonic-gate /* 9977c478bd9Sstevel@tonic-gate * These flags need to be unique for stream io name space 9987c478bd9Sstevel@tonic-gate * and copy modes name space. These flags allow strwaitq 9997c478bd9Sstevel@tonic-gate * and strdoioctl to proceed as if signals or errors on the stream 10007c478bd9Sstevel@tonic-gate * head have not occurred; i.e. they will be detected by some other 10017c478bd9Sstevel@tonic-gate * means. 10027c478bd9Sstevel@tonic-gate * STR_NOSIG does not allow signals to interrupt the call 10037c478bd9Sstevel@tonic-gate * STR_NOERROR does not allow stream head read, write or hup errors to 10047c478bd9Sstevel@tonic-gate * affect the call. When used with strdoioctl(), if a previous ioctl 10057c478bd9Sstevel@tonic-gate * is pending and times out, STR_NOERROR will cause strdoioctl() to not 10067c478bd9Sstevel@tonic-gate * return ETIME. If, however, the requested ioctl times out, ETIME 10077c478bd9Sstevel@tonic-gate * will be returned (use ic_timout instead) 10087c478bd9Sstevel@tonic-gate * STR_PEEK is used to inform strwaitq that the reader is peeking at data 10097c478bd9Sstevel@tonic-gate * and that a non-persistent error should not be cleared. 10107c478bd9Sstevel@tonic-gate * STR_DELAYERR is used to inform strwaitq that it should not check errors 10117c478bd9Sstevel@tonic-gate * after being awoken since, in addition to an error, there might also be 10127c478bd9Sstevel@tonic-gate * data queued on the stream head read queue. 10137c478bd9Sstevel@tonic-gate */ 10147c478bd9Sstevel@tonic-gate #define STR_NOSIG 0x10 /* Ignore signals during strdoioctl/strwaitq */ 10157c478bd9Sstevel@tonic-gate #define STR_NOERROR 0x20 /* Ignore errors during strdoioctl/strwaitq */ 10167c478bd9Sstevel@tonic-gate #define STR_PEEK 0x40 /* Peeking behavior on non-persistent errors */ 10177c478bd9Sstevel@tonic-gate #define STR_DELAYERR 0x80 /* Do not check errors on return */ 10187c478bd9Sstevel@tonic-gate 10197c478bd9Sstevel@tonic-gate /* 10207c478bd9Sstevel@tonic-gate * Copy modes for tty and I_STR ioctls 10217c478bd9Sstevel@tonic-gate */ 10227c478bd9Sstevel@tonic-gate #define U_TO_K 01 /* User to Kernel */ 10237c478bd9Sstevel@tonic-gate #define K_TO_K 02 /* Kernel to Kernel */ 10247c478bd9Sstevel@tonic-gate 10257c478bd9Sstevel@tonic-gate /* 10267c478bd9Sstevel@tonic-gate * Mux defines. 10277c478bd9Sstevel@tonic-gate */ 10287c478bd9Sstevel@tonic-gate #define LINKNORMAL 0x01 /* normal mux link */ 10297c478bd9Sstevel@tonic-gate #define LINKPERSIST 0x02 /* persistent mux link */ 10307c478bd9Sstevel@tonic-gate #define LINKTYPEMASK 0x03 /* bitmask of all link types */ 10317c478bd9Sstevel@tonic-gate #define LINKCLOSE 0x04 /* unlink from strclose */ 10327c478bd9Sstevel@tonic-gate 10337c478bd9Sstevel@tonic-gate /* 10347c478bd9Sstevel@tonic-gate * Definitions of Streams macros and function interfaces. 10357c478bd9Sstevel@tonic-gate */ 10367c478bd9Sstevel@tonic-gate 10377c478bd9Sstevel@tonic-gate /* 10387c478bd9Sstevel@tonic-gate * Obsolete queue scheduling macros. They are not used anymore, but still kept 10397c478bd9Sstevel@tonic-gate * here for 3-d party modules and drivers who might still use them. 10407c478bd9Sstevel@tonic-gate */ 10417c478bd9Sstevel@tonic-gate #define setqsched() 10427c478bd9Sstevel@tonic-gate #define qready() 1 10437c478bd9Sstevel@tonic-gate 10447c478bd9Sstevel@tonic-gate #ifdef _KERNEL 10457c478bd9Sstevel@tonic-gate #define runqueues() 10467c478bd9Sstevel@tonic-gate #define queuerun() 10477c478bd9Sstevel@tonic-gate #endif 10487c478bd9Sstevel@tonic-gate 10497c478bd9Sstevel@tonic-gate /* compatibility module for style 2 drivers with DR race condition */ 10507c478bd9Sstevel@tonic-gate #define DRMODNAME "drcompat" 10517c478bd9Sstevel@tonic-gate 10527c478bd9Sstevel@tonic-gate /* 10537c478bd9Sstevel@tonic-gate * Macros dealing with mux_nodes. 10547c478bd9Sstevel@tonic-gate */ 10557c478bd9Sstevel@tonic-gate #define MUX_VISIT(X) ((X)->mn_flags |= VISITED) 10567c478bd9Sstevel@tonic-gate #define MUX_CLEAR(X) ((X)->mn_flags &= (~VISITED)); \ 10577c478bd9Sstevel@tonic-gate ((X)->mn_originp = NULL) 10587c478bd9Sstevel@tonic-gate #define MUX_DIDVISIT(X) ((X)->mn_flags & VISITED) 10597c478bd9Sstevel@tonic-gate 10607c478bd9Sstevel@tonic-gate 10617c478bd9Sstevel@tonic-gate /* 10627c478bd9Sstevel@tonic-gate * Twisted stream macros 10637c478bd9Sstevel@tonic-gate */ 10647c478bd9Sstevel@tonic-gate #define STRMATED(X) ((X)->sd_flag & STRMATE) 10657c478bd9Sstevel@tonic-gate #define STRLOCKMATES(X) if (&((X)->sd_lock) > &(((X)->sd_mate)->sd_lock)) { \ 10667c478bd9Sstevel@tonic-gate mutex_enter(&((X)->sd_lock)); \ 10677c478bd9Sstevel@tonic-gate mutex_enter(&(((X)->sd_mate)->sd_lock)); \ 10687c478bd9Sstevel@tonic-gate } else { \ 10697c478bd9Sstevel@tonic-gate mutex_enter(&(((X)->sd_mate)->sd_lock)); \ 10707c478bd9Sstevel@tonic-gate mutex_enter(&((X)->sd_lock)); \ 10717c478bd9Sstevel@tonic-gate } 10727c478bd9Sstevel@tonic-gate #define STRUNLOCKMATES(X) mutex_exit(&((X)->sd_lock)); \ 10737c478bd9Sstevel@tonic-gate mutex_exit(&(((X)->sd_mate)->sd_lock)) 10747c478bd9Sstevel@tonic-gate 10757c478bd9Sstevel@tonic-gate #ifdef _KERNEL 10767c478bd9Sstevel@tonic-gate 10777c478bd9Sstevel@tonic-gate extern void strinit(void); 10787c478bd9Sstevel@tonic-gate extern int strdoioctl(struct stdata *, struct strioctl *, int, int, 10797c478bd9Sstevel@tonic-gate cred_t *, int *); 10807c478bd9Sstevel@tonic-gate extern void strsendsig(struct strsig *, int, uchar_t, int); 10817c478bd9Sstevel@tonic-gate extern void str_sendsig(vnode_t *, int, uchar_t, int); 10827c478bd9Sstevel@tonic-gate extern void strhup(struct stdata *); 10837c478bd9Sstevel@tonic-gate extern int qattach(queue_t *, dev_t *, int, cred_t *, fmodsw_impl_t *, 10847c478bd9Sstevel@tonic-gate boolean_t); 10857c478bd9Sstevel@tonic-gate extern int qreopen(queue_t *, dev_t *, int, cred_t *); 10867c478bd9Sstevel@tonic-gate extern void qdetach(queue_t *, int, int, cred_t *, boolean_t); 10877c478bd9Sstevel@tonic-gate extern void enterq(queue_t *); 10887c478bd9Sstevel@tonic-gate extern void leaveq(queue_t *); 10897c478bd9Sstevel@tonic-gate extern int putiocd(mblk_t *, caddr_t, int, cred_t *); 10907c478bd9Sstevel@tonic-gate extern int getiocd(mblk_t *, caddr_t, int); 10917c478bd9Sstevel@tonic-gate extern struct linkinfo *alloclink(queue_t *, queue_t *, struct file *); 10927c478bd9Sstevel@tonic-gate extern void lbfree(struct linkinfo *); 1093f4b3ec61Sdh155122 extern int linkcycle(stdata_t *, stdata_t *, str_stack_t *); 1094f4b3ec61Sdh155122 extern struct linkinfo *findlinks(stdata_t *, int, int, str_stack_t *); 10957c478bd9Sstevel@tonic-gate extern queue_t *getendq(queue_t *); 10967c478bd9Sstevel@tonic-gate extern int mlink(vnode_t *, int, int, cred_t *, int *, int); 10977c478bd9Sstevel@tonic-gate extern int mlink_file(vnode_t *, int, struct file *, cred_t *, int *, int); 1098f4b3ec61Sdh155122 extern int munlink(struct stdata *, struct linkinfo *, int, cred_t *, int *, 1099f4b3ec61Sdh155122 str_stack_t *); 1100f4b3ec61Sdh155122 extern int munlinkall(struct stdata *, int, cred_t *, int *, str_stack_t *); 1101f4b3ec61Sdh155122 extern void mux_addedge(stdata_t *, stdata_t *, int, str_stack_t *); 1102f4b3ec61Sdh155122 extern void mux_rmvedge(stdata_t *, int, str_stack_t *); 11037c478bd9Sstevel@tonic-gate extern int devflg_to_qflag(struct streamtab *, uint32_t, uint32_t *, 11047c478bd9Sstevel@tonic-gate uint32_t *); 11057c478bd9Sstevel@tonic-gate extern void setq(queue_t *, struct qinit *, struct qinit *, perdm_t *, 11067c478bd9Sstevel@tonic-gate uint32_t, uint32_t, boolean_t); 11077c478bd9Sstevel@tonic-gate extern perdm_t *hold_dm(struct streamtab *, uint32_t, uint32_t); 11087c478bd9Sstevel@tonic-gate extern void rele_dm(perdm_t *); 11097c478bd9Sstevel@tonic-gate extern int strmakectl(struct strbuf *, int32_t, int32_t, mblk_t **); 11107c478bd9Sstevel@tonic-gate extern int strmakedata(ssize_t *, struct uio *, stdata_t *, int32_t, mblk_t **); 11117c478bd9Sstevel@tonic-gate extern int strmakemsg(struct strbuf *, ssize_t *, struct uio *, 11127c478bd9Sstevel@tonic-gate struct stdata *, int32_t, mblk_t **); 11137c478bd9Sstevel@tonic-gate extern int strgetmsg(vnode_t *, struct strbuf *, struct strbuf *, uchar_t *, 11147c478bd9Sstevel@tonic-gate int *, int, rval_t *); 11157c478bd9Sstevel@tonic-gate extern int strputmsg(vnode_t *, struct strbuf *, struct strbuf *, uchar_t, 11167c478bd9Sstevel@tonic-gate int flag, int fmode); 11177c478bd9Sstevel@tonic-gate extern int strstartplumb(struct stdata *, int, int); 11187c478bd9Sstevel@tonic-gate extern void strendplumb(struct stdata *); 11197c478bd9Sstevel@tonic-gate extern int stropen(struct vnode *, dev_t *, int, cred_t *); 11207c478bd9Sstevel@tonic-gate extern int strclose(struct vnode *, int, cred_t *); 11217c478bd9Sstevel@tonic-gate extern int strpoll(register struct stdata *, short, int, short *, 11227c478bd9Sstevel@tonic-gate struct pollhead **); 11237c478bd9Sstevel@tonic-gate extern void strclean(struct vnode *); 11247c478bd9Sstevel@tonic-gate extern void str_cn_clean(); /* XXX hook for consoles signal cleanup */ 11257c478bd9Sstevel@tonic-gate extern int strwrite(struct vnode *, struct uio *, cred_t *); 1126ff550d0eSmasputra extern int strwrite_common(struct vnode *, struct uio *, cred_t *, int); 1127ff550d0eSmasputra extern int kstrwritemp(struct vnode *, mblk_t *, ushort_t); 11287c478bd9Sstevel@tonic-gate extern int strread(struct vnode *, struct uio *, cred_t *); 11297c478bd9Sstevel@tonic-gate extern int strioctl(struct vnode *, int, intptr_t, int, int, cred_t *, int *); 11307c478bd9Sstevel@tonic-gate extern int strrput(queue_t *, mblk_t *); 11317c478bd9Sstevel@tonic-gate extern int strrput_nondata(queue_t *, mblk_t *); 11327c478bd9Sstevel@tonic-gate extern mblk_t *strrput_proto(vnode_t *, mblk_t *, 11337c478bd9Sstevel@tonic-gate strwakeup_t *, strsigset_t *, strsigset_t *, strpollset_t *); 11347c478bd9Sstevel@tonic-gate extern mblk_t *strrput_misc(vnode_t *, mblk_t *, 11357c478bd9Sstevel@tonic-gate strwakeup_t *, strsigset_t *, strsigset_t *, strpollset_t *); 11367c478bd9Sstevel@tonic-gate extern int getiocseqno(void); 11377c478bd9Sstevel@tonic-gate extern int strwaitbuf(size_t, int); 11387c478bd9Sstevel@tonic-gate extern int strwaitq(stdata_t *, int, ssize_t, int, clock_t, int *); 11397c478bd9Sstevel@tonic-gate extern struct stdata *shalloc(queue_t *); 11407c478bd9Sstevel@tonic-gate extern void shfree(struct stdata *s); 11417c478bd9Sstevel@tonic-gate extern queue_t *allocq(void); 11427c478bd9Sstevel@tonic-gate extern void freeq(queue_t *); 11437c478bd9Sstevel@tonic-gate extern qband_t *allocband(void); 11447c478bd9Sstevel@tonic-gate extern void freeband(qband_t *); 11457c478bd9Sstevel@tonic-gate extern void freebs_enqueue(mblk_t *, dblk_t *); 11467c478bd9Sstevel@tonic-gate extern void setqback(queue_t *, unsigned char); 11477c478bd9Sstevel@tonic-gate extern int strcopyin(void *, void *, size_t, int); 11487c478bd9Sstevel@tonic-gate extern int strcopyout(void *, void *, size_t, int); 11497c478bd9Sstevel@tonic-gate extern void strsignal(struct stdata *, int, int32_t); 11507c478bd9Sstevel@tonic-gate extern clock_t str_cv_wait(kcondvar_t *, kmutex_t *, clock_t, int); 11517c478bd9Sstevel@tonic-gate extern void disable_svc(queue_t *); 11527c478bd9Sstevel@tonic-gate extern void remove_runlist(queue_t *); 11537c478bd9Sstevel@tonic-gate extern void wait_svc(queue_t *); 1154116094b2Smicheng extern void backenable(queue_t *, uchar_t); 11557c478bd9Sstevel@tonic-gate extern void set_qend(queue_t *); 11567c478bd9Sstevel@tonic-gate extern int strgeterr(stdata_t *, int32_t, int); 11577c478bd9Sstevel@tonic-gate extern void qenable_locked(queue_t *); 11587c478bd9Sstevel@tonic-gate extern mblk_t *getq_noenab(queue_t *); 11597c478bd9Sstevel@tonic-gate extern void rmvq_noenab(queue_t *, mblk_t *); 1160116094b2Smicheng extern void qbackenable(queue_t *, uchar_t); 11615ba3fab4Sjk115741 extern void set_qfull(queue_t *); 11627c478bd9Sstevel@tonic-gate 11637c478bd9Sstevel@tonic-gate extern void strblock(queue_t *); 11647c478bd9Sstevel@tonic-gate extern void strunblock(queue_t *); 11657c478bd9Sstevel@tonic-gate extern int qclaimed(queue_t *); 11667c478bd9Sstevel@tonic-gate extern int straccess(struct stdata *, enum jcaccess); 11677c478bd9Sstevel@tonic-gate 11687c478bd9Sstevel@tonic-gate extern void entersq(syncq_t *, int); 11697c478bd9Sstevel@tonic-gate extern void leavesq(syncq_t *, int); 11707c478bd9Sstevel@tonic-gate extern void claimq(queue_t *); 11717c478bd9Sstevel@tonic-gate extern void releaseq(queue_t *); 11727c478bd9Sstevel@tonic-gate extern void claimstr(queue_t *); 11737c478bd9Sstevel@tonic-gate extern void releasestr(queue_t *); 11747c478bd9Sstevel@tonic-gate extern void removeq(queue_t *); 11757c478bd9Sstevel@tonic-gate extern void insertq(struct stdata *, queue_t *); 11767c478bd9Sstevel@tonic-gate extern void drain_syncq(syncq_t *); 11777c478bd9Sstevel@tonic-gate extern void qfill_syncq(syncq_t *, queue_t *, mblk_t *); 11787c478bd9Sstevel@tonic-gate extern void qdrain_syncq(syncq_t *, queue_t *); 11797c478bd9Sstevel@tonic-gate extern int flush_syncq(syncq_t *, queue_t *); 11807c478bd9Sstevel@tonic-gate extern void wait_sq_svc(syncq_t *); 11817c478bd9Sstevel@tonic-gate 11827c478bd9Sstevel@tonic-gate extern void outer_enter(syncq_t *, uint16_t); 11837c478bd9Sstevel@tonic-gate extern void outer_exit(syncq_t *); 11847c478bd9Sstevel@tonic-gate extern void qwriter_inner(queue_t *, mblk_t *, void (*)()); 11857c478bd9Sstevel@tonic-gate extern void qwriter_outer(queue_t *, mblk_t *, void (*)()); 11867c478bd9Sstevel@tonic-gate 11877c478bd9Sstevel@tonic-gate extern callbparams_t *callbparams_alloc(syncq_t *, void (*)(void *), 11887c478bd9Sstevel@tonic-gate void *, int); 11897c478bd9Sstevel@tonic-gate extern void callbparams_free(syncq_t *, callbparams_t *); 11907c478bd9Sstevel@tonic-gate extern void callbparams_free_id(syncq_t *, callbparams_id_t, int32_t); 11917c478bd9Sstevel@tonic-gate extern void qcallbwrapper(void *); 11927c478bd9Sstevel@tonic-gate 1193bd118333Smeem extern mblk_t *esballoc_wait(unsigned char *, size_t, uint_t, frtn_t *); 11947c478bd9Sstevel@tonic-gate extern mblk_t *esballoca(unsigned char *, size_t, uint_t, frtn_t *); 11957c478bd9Sstevel@tonic-gate extern mblk_t *desballoca(unsigned char *, size_t, uint_t, frtn_t *); 11967c478bd9Sstevel@tonic-gate extern int do_sendfp(struct stdata *, struct file *, struct cred *); 11977c478bd9Sstevel@tonic-gate extern int frozenstr(queue_t *); 11987c478bd9Sstevel@tonic-gate extern size_t xmsgsize(mblk_t *); 11997c478bd9Sstevel@tonic-gate 12007c478bd9Sstevel@tonic-gate extern void putnext_tail(syncq_t *, queue_t *, uint32_t); 12017c478bd9Sstevel@tonic-gate extern void stream_willservice(stdata_t *); 12027c478bd9Sstevel@tonic-gate extern void stream_runservice(stdata_t *); 12037c478bd9Sstevel@tonic-gate 12047c478bd9Sstevel@tonic-gate extern void strmate(vnode_t *, vnode_t *); 12057c478bd9Sstevel@tonic-gate extern queue_t *strvp2wq(vnode_t *); 12067c478bd9Sstevel@tonic-gate extern vnode_t *strq2vp(queue_t *); 12077c478bd9Sstevel@tonic-gate extern mblk_t *allocb_wait(size_t, uint_t, uint_t, int *); 12087c478bd9Sstevel@tonic-gate extern mblk_t *allocb_cred(size_t, cred_t *); 12097c478bd9Sstevel@tonic-gate extern mblk_t *allocb_cred_wait(size_t, uint_t, int *, cred_t *); 12107c478bd9Sstevel@tonic-gate extern mblk_t *allocb_tmpl(size_t, const mblk_t *); 1211ff550d0eSmasputra extern mblk_t *allocb_tryhard(size_t); 12127c478bd9Sstevel@tonic-gate extern void mblk_setcred(mblk_t *, cred_t *); 1213ad1660d0Smeem extern void strpollwakeup(vnode_t *, short); 12147c478bd9Sstevel@tonic-gate extern int putnextctl_wait(queue_t *, int); 12157c478bd9Sstevel@tonic-gate 1216ad1660d0Smeem extern int kstrputmsg(struct vnode *, mblk_t *, struct uio *, ssize_t, 12177c478bd9Sstevel@tonic-gate unsigned char, int, int); 1218ad1660d0Smeem extern int kstrgetmsg(struct vnode *, mblk_t **, struct uio *, 12197c478bd9Sstevel@tonic-gate unsigned char *, int *, clock_t, rval_t *); 12207c478bd9Sstevel@tonic-gate 1221ad1660d0Smeem extern void strsetrerror(vnode_t *, int, int, errfunc_t); 1222ad1660d0Smeem extern void strsetwerror(vnode_t *, int, int, errfunc_t); 1223ad1660d0Smeem extern void strseteof(vnode_t *, int); 1224ad1660d0Smeem extern void strflushrq(vnode_t *, int); 1225ad1660d0Smeem extern void strsetrputhooks(vnode_t *, uint_t, msgfunc_t, msgfunc_t); 1226ad1660d0Smeem extern void strsetwputhooks(vnode_t *, uint_t, clock_t); 1227c28749e9Skais extern void strsetrwputdatahooks(vnode_t *, msgfunc_t, msgfunc_t); 1228ad1660d0Smeem extern int strwaitmark(vnode_t *); 12297c478bd9Sstevel@tonic-gate extern void strsignal_nolock(stdata_t *, int, int32_t); 12307c478bd9Sstevel@tonic-gate 12317c478bd9Sstevel@tonic-gate struct multidata_s; 12327c478bd9Sstevel@tonic-gate struct pdesc_s; 12337c478bd9Sstevel@tonic-gate extern int hcksum_assoc(mblk_t *, struct multidata_s *, struct pdesc_s *, 12347c478bd9Sstevel@tonic-gate uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, int); 12357c478bd9Sstevel@tonic-gate extern void hcksum_retrieve(mblk_t *, struct multidata_s *, struct pdesc_s *, 12367c478bd9Sstevel@tonic-gate uint32_t *, uint32_t *, uint32_t *, uint32_t *, uint32_t *); 12377c478bd9Sstevel@tonic-gate extern unsigned int bcksum(uchar_t *, int, unsigned int); 12387c478bd9Sstevel@tonic-gate extern boolean_t is_vmloaned_mblk(mblk_t *, struct multidata_s *, 12397c478bd9Sstevel@tonic-gate struct pdesc_s *); 12407c478bd9Sstevel@tonic-gate 12417c478bd9Sstevel@tonic-gate extern int fmodsw_register(const char *, struct streamtab *, int); 12427c478bd9Sstevel@tonic-gate extern int fmodsw_unregister(const char *); 12437c478bd9Sstevel@tonic-gate extern fmodsw_impl_t *fmodsw_find(const char *, fmodsw_flags_t); 12447c478bd9Sstevel@tonic-gate extern void fmodsw_rele(fmodsw_impl_t *); 12457c478bd9Sstevel@tonic-gate 12467c478bd9Sstevel@tonic-gate extern void freemsgchain(mblk_t *); 12477c478bd9Sstevel@tonic-gate extern mblk_t *copymsgchain(mblk_t *); 12487c478bd9Sstevel@tonic-gate 1249ff550d0eSmasputra extern mblk_t *mcopyinuio(struct stdata *, uio_t *, ssize_t, ssize_t, int *); 1250ff550d0eSmasputra 12517c478bd9Sstevel@tonic-gate /* 12527c478bd9Sstevel@tonic-gate * shared or externally configured data structures 12537c478bd9Sstevel@tonic-gate */ 12547c478bd9Sstevel@tonic-gate extern ssize_t strmsgsz; /* maximum stream message size */ 12557c478bd9Sstevel@tonic-gate extern ssize_t strctlsz; /* maximum size of ctl message */ 12567c478bd9Sstevel@tonic-gate extern int nstrpush; /* maximum number of pushes allowed */ 12577c478bd9Sstevel@tonic-gate 12587c478bd9Sstevel@tonic-gate /* 12597c478bd9Sstevel@tonic-gate * Bufcalls related variables. 12607c478bd9Sstevel@tonic-gate */ 12617c478bd9Sstevel@tonic-gate extern struct bclist strbcalls; /* List of bufcalls */ 12627c478bd9Sstevel@tonic-gate extern kmutex_t strbcall_lock; /* Protects the list of bufcalls */ 12637c478bd9Sstevel@tonic-gate extern kcondvar_t strbcall_cv; /* Signaling when a bufcall is added */ 12647c478bd9Sstevel@tonic-gate extern kcondvar_t bcall_cv; /* wait of executing bufcall completes */ 12657c478bd9Sstevel@tonic-gate 12667c478bd9Sstevel@tonic-gate extern frtn_t frnop; 12677c478bd9Sstevel@tonic-gate 12687c478bd9Sstevel@tonic-gate extern struct kmem_cache *ciputctrl_cache; 12697c478bd9Sstevel@tonic-gate extern int n_ciputctrl; 12707c478bd9Sstevel@tonic-gate extern int max_n_ciputctrl; 12717c478bd9Sstevel@tonic-gate extern int min_n_ciputctrl; 12727c478bd9Sstevel@tonic-gate 12737c478bd9Sstevel@tonic-gate extern cdevsw_impl_t *devimpl; 1274e7d4b76fSss146032 1275e7d4b76fSss146032 /* 1276e7d4b76fSss146032 * esballoc queue for throttling 1277e7d4b76fSss146032 */ 1278e7d4b76fSss146032 typedef struct esb_queue { 1279e7d4b76fSss146032 kmutex_t eq_lock; 1280e7d4b76fSss146032 uint_t eq_len; /* number of queued messages */ 1281e7d4b76fSss146032 mblk_t *eq_head; /* head of queue */ 1282e7d4b76fSss146032 mblk_t *eq_tail; /* tail of queue */ 1283e7d4b76fSss146032 uint_t eq_flags; /* esballoc queue flags */ 1284e7d4b76fSss146032 } esb_queue_t; 1285e7d4b76fSss146032 1286e7d4b76fSss146032 /* 1287e7d4b76fSss146032 * esballoc flags for queue processing. 1288e7d4b76fSss146032 */ 1289e7d4b76fSss146032 #define ESBQ_PROCESSING 0x01 /* queue is being processed */ 1290e7d4b76fSss146032 #define ESBQ_TIMER 0x02 /* timer is active */ 1291e7d4b76fSss146032 1292e7d4b76fSss146032 extern void esballoc_queue_init(void); 1293e7d4b76fSss146032 12947c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 12957c478bd9Sstevel@tonic-gate 12967c478bd9Sstevel@tonic-gate /* 12977c478bd9Sstevel@tonic-gate * Note: Use of these macros are restricted to kernel/unix and 12987c478bd9Sstevel@tonic-gate * intended for the STREAMS framework. 12997c478bd9Sstevel@tonic-gate * All modules/drivers should include sys/ddi.h. 13007c478bd9Sstevel@tonic-gate * 13017c478bd9Sstevel@tonic-gate * Finding related queues 13027c478bd9Sstevel@tonic-gate */ 13037c478bd9Sstevel@tonic-gate #define _OTHERQ(q) ((q)->q_flag&QREADR? (q)+1: (q)-1) 13047c478bd9Sstevel@tonic-gate #define _WR(q) ((q)->q_flag&QREADR? (q)+1: (q)) 13057c478bd9Sstevel@tonic-gate #define _RD(q) ((q)->q_flag&QREADR? (q): (q)-1) 13067c478bd9Sstevel@tonic-gate #define _SAMESTR(q) (!((q)->q_flag & QEND)) 13077c478bd9Sstevel@tonic-gate 13087c478bd9Sstevel@tonic-gate /* 13097c478bd9Sstevel@tonic-gate * These are also declared here for modules/drivers that erroneously 13107c478bd9Sstevel@tonic-gate * include strsubr.h after ddi.h or fail to include ddi.h at all. 13117c478bd9Sstevel@tonic-gate */ 13127c478bd9Sstevel@tonic-gate extern struct queue *OTHERQ(queue_t *); /* stream.h */ 13137c478bd9Sstevel@tonic-gate extern struct queue *RD(queue_t *); 13147c478bd9Sstevel@tonic-gate extern struct queue *WR(queue_t *); 13157c478bd9Sstevel@tonic-gate extern int SAMESTR(queue_t *); 13167c478bd9Sstevel@tonic-gate 1317ff550d0eSmasputra /* 1318ff550d0eSmasputra * The following hardware checksum related macros are private 1319ff550d0eSmasputra * interfaces that are subject to change without notice. 1320ff550d0eSmasputra */ 1321ff550d0eSmasputra #ifdef _KERNEL 1322ff550d0eSmasputra #define DB_CKSUMSTART(mp) ((mp)->b_datap->db_cksumstart) 1323ff550d0eSmasputra #define DB_CKSUMEND(mp) ((mp)->b_datap->db_cksumend) 1324ff550d0eSmasputra #define DB_CKSUMSTUFF(mp) ((mp)->b_datap->db_cksumstuff) 1325ff550d0eSmasputra #define DB_CKSUMFLAGS(mp) ((mp)->b_datap->db_struioun.cksum.flags) 1326ff550d0eSmasputra #define DB_CKSUM16(mp) ((mp)->b_datap->db_cksum16) 1327ff550d0eSmasputra #define DB_CKSUM32(mp) ((mp)->b_datap->db_cksum32) 13288347601bSyl150051 #define DB_LSOFLAGS(mp) ((mp)->b_datap->db_struioun.cksum.flags) 13298347601bSyl150051 #define DB_LSOMSS(mp) ((mp)->b_datap->db_struioun.cksum.pad) 1330ff550d0eSmasputra #endif /* _KERNEL */ 1331ff550d0eSmasputra 13327c478bd9Sstevel@tonic-gate #ifdef __cplusplus 13337c478bd9Sstevel@tonic-gate } 13347c478bd9Sstevel@tonic-gate #endif 13357c478bd9Sstevel@tonic-gate 13367c478bd9Sstevel@tonic-gate 13377c478bd9Sstevel@tonic-gate #endif /* _SYS_STRSUBR_H */ 1338