xref: /illumos-gate/usr/src/uts/common/sys/logindmux_impl.h (revision 581cede61ac9c14d8d4ea452562a567189eead78)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_LOGINDMUX_IMPL_H
28 #define	_SYS_LOGINDMUX_IMPL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <sys/stream.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 
40 /*
41  * This structure is shared between two logindmux peer instances and
42  * ensures that only one of the peers will be actively processing an
43  * I_UNLINK ioctl at any one time.
44  */
45 typedef struct unlinkinfo {
46 	kmutex_t	state_lock;	/* serialize access to state */
47 	int		state;		/* state of I_UNLINK operation */
48 	mblk_t		*prot_mp;	/* carries protocol messages */
49 } unlinkinfo_t;
50 
51 /*
52  * Logindmux state structure; one per open instance.
53  */
54 struct tmx {
55 	queue_t		*rdq;		/* our mux upper read queue */
56 	queue_t		*muxq;		/* our mux lower write queue */
57 	queue_t		*peerq; 	/* peer mux lower write queue */
58 	minor_t		dev0;		/* our minor device number */
59 	boolean_t	isptm;		/* true if ptm is downstream */
60 	mblk_t		*unlink_mp;	/* mblk used in logdmux_unlink_timer */
61 	unlinkinfo_t	*unlinkinfop;	/* used during I_UNLINK processing */
62 	bufcall_id_t	wbufcid;	/* needed for recovery */
63 	bufcall_id_t	rbufcid;	/* needed for recovery */
64 	timeout_id_t	utimoutid;	/* unlink timer identifier */
65 	timeout_id_t	wtimoutid;	/* needed for recovery */
66 	timeout_id_t	rtimoutid;	/* needed for recovery */
67 };
68 
69 #define	LOGDMX_ID		107	/* module id number */
70 
71 /*
72  * The arguments for calls to qtimeout, in microseconds.
73  */
74 #define	SIMWAIT			100000	/* logdmux_timer */
75 #define	LOGDMUX_POLL_WAIT	10	/* logdmux_unlink_timer */
76 
77 /*
78  * State of peer linkage.
79  */
80 enum {
81 	LOGDMUX_LINKED		= 1,	/* peer instances are in linked state */
82 	LOGDMUX_UNLINK_PENDING	= 2,	/* a peer is actively I_UNLINKing */
83 	LOGDMUX_UNLINKED	= 3	/* a peer has completed its I_UNLINK */
84 };
85 
86 /*
87  * Protocol message magic cookie.
88  */
89 #define	LOGDMUX_MCTL		(LOGDMX_ID << 16)
90 
91 /*
92  * peer to peer protocol messages.
93  */
94 #define	LOGDMUX_UNLINK_REQ	(LOGDMUX_MCTL|1) /* peer wants to unlink */
95 #define	LOGDMUX_UNLINK_RESP	(LOGDMUX_MCTL|2) /* ok for peer to unlink */
96 
97 /*
98  * Macro to determine if an mblk is a logindmux protocol mblk.
99  */
100 #define	LOGDMUX_PROTO_MBLK(mp)						   \
101 	((DB_TYPE(mp) == M_CTL)						&& \
102 	((mp)->b_cont != NULL)						&& \
103 	(DB_TYPE((mp)->b_cont) == M_IOCTL)				&& \
104 	(((struct iocblk *)((mp)->b_cont->b_rptr))->ioc_cmd == I_UNLINK))
105 
106 
107 #ifdef	__cplusplus
108 }
109 #endif
110 
111 #endif	/* _SYS_LOGINDMUX_IMPL_H */
112