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 #include <sys/types.h>
31 #include <sys/stream.h>
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 
38 /*
39  * This structure is shared between two logindmux peer instances and
40  * ensures that only one of the peers will be actively processing an
41  * I_UNLINK ioctl at any one time.
42  */
43 typedef struct unlinkinfo {
44 	kmutex_t	state_lock;	/* serialize access to state */
45 	int		state;		/* state of I_UNLINK operation */
46 	mblk_t		*prot_mp;	/* carries protocol messages */
47 } unlinkinfo_t;
48 
49 /*
50  * Logindmux state structure; one per open instance.
51  */
52 struct tmx {
53 	queue_t		*rdq;		/* our mux upper read queue */
54 	queue_t		*muxq;		/* our mux lower write queue */
55 	queue_t		*peerq; 	/* peer mux lower write queue */
56 	minor_t		dev0;		/* our minor device number */
57 	boolean_t	isptm;		/* true if ptm is downstream */
58 	mblk_t		*unlink_mp;	/* mblk used in logdmux_unlink_timer */
59 	unlinkinfo_t	*unlinkinfop;	/* used during I_UNLINK processing */
60 	bufcall_id_t	wbufcid;	/* needed for recovery */
61 	bufcall_id_t	rbufcid;	/* needed for recovery */
62 	timeout_id_t	utimoutid;	/* unlink timer identifier */
63 	timeout_id_t	wtimoutid;	/* needed for recovery */
64 	timeout_id_t	rtimoutid;	/* needed for recovery */
65 };
66 
67 #define	LOGDMX_ID		107	/* module id number */
68 
69 /*
70  * The arguments for calls to qtimeout, in microseconds.
71  */
72 #define	SIMWAIT			100000	/* logdmux_timer */
73 #define	LOGDMUX_POLL_WAIT	10	/* logdmux_unlink_timer */
74 
75 /*
76  * State of peer linkage.
77  */
78 enum {
79 	LOGDMUX_LINKED		= 1,	/* peer instances are in linked state */
80 	LOGDMUX_UNLINK_PENDING	= 2,	/* a peer is actively I_UNLINKing */
81 	LOGDMUX_UNLINKED	= 3	/* a peer has completed its I_UNLINK */
82 };
83 
84 /*
85  * Protocol message magic cookie.
86  */
87 #define	LOGDMUX_MCTL		(LOGDMX_ID << 16)
88 
89 /*
90  * peer to peer protocol messages.
91  */
92 #define	LOGDMUX_UNLINK_REQ	(LOGDMUX_MCTL|1) /* peer wants to unlink */
93 #define	LOGDMUX_UNLINK_RESP	(LOGDMUX_MCTL|2) /* ok for peer to unlink */
94 
95 /*
96  * Macro to determine if an mblk is a logindmux protocol mblk.
97  */
98 #define	LOGDMUX_PROTO_MBLK(mp)						   \
99 	((DB_TYPE(mp) == M_CTL)						&& \
100 	((mp)->b_cont != NULL)						&& \
101 	(DB_TYPE((mp)->b_cont) == M_IOCTL)				&& \
102 	(((struct iocblk *)((mp)->b_cont->b_rptr))->ioc_cmd == I_UNLINK))
103 
104 
105 #ifdef	__cplusplus
106 }
107 #endif
108 
109 #endif	/* _SYS_LOGINDMUX_IMPL_H */
110