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