xref: /illumos-gate/usr/src/uts/sun4v/sys/vcc_impl.h (revision 71269a2275bf5a143dad6461eee2710a344e7261)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _VCC_IMPL_H
28 #define	_VCC_IMPL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/types.h>
37 #include <sys/stream.h>
38 #include <sys/ddi.h>
39 #include <sys/sunddi.h>
40 #include <sys/ioctl.h>
41 #include <sys/vcc.h>
42 
43 #define	    VCC_DEV_TO_INST(dev)		(getminor(dev))
44 #define	    VCC_INST_TO_DEV(instance)		(instance)
45 
46 #define	    VCC_DRIVER_NAME			"vcc"
47 #define	    VCC_NAME				VCC_DRIVER_NAME
48 
49 /*
50  * VCC Port States
51  */
52 
53 /*
54  * There is one lock in port structure to protect the states of the port.
55  * States of the port are:
56  * 1. VCC_PORT_AVAIL
57  * 2. VCC_PORT_OPEN
58  * 3. VCC_PORT_USE_READ_LDC  - There is a thread doing vcc_read.
59  * 4. VCC_PORT_USE_WRITE_LDC - There is a thread doing vcc_write.
60  * 6. VCC_PORT_LDC_DATA_READY - Data is ready from ldc.
61  * 5. VCC_PORT_LDC_WRITE_READY - Ldc has space to receive data.
62  * 7. VCC_PORT_LDC_CHANNEL_READY - Ldc channel is up.
63  * 8. VCC_PORT_ADDED		- A new port was added.
64  * 9. VCC_PORT_TERM_RD		- Terminal read is enabled vs suspended
65  * 10. VCC_PORT_TERM_WR		- Terminal write is enabled vc suspended
66  * 11. VCC_PORT_NONBLOCK	- A port was opened with non blocking flag.
67  * 12. VCC_PORT_LDC_LINK_DOWN
68  *
69  *
70  * Code flow for port to transit from one state to another is as the follows:
71  *
72  * 1. VCC_PORT_AVAIL
73  *
74  *	    Transition from unavailable to available
75  *		- obtain port lock
76  *		Transit port to available and added states
77  *		- release port lock
78  *		- obtain softstate lock
79  *		Increase total number of ports
80  *		- release softsate lock
81  *
82  *		after download added port to vntsd
83  *		- obtain port lock
84  *		Transit port to not added state
85  *		- release port lock
86  *
87  *	    Transition from available to unavailable
88  *		- obtain port lock
89  *		- cv_wait read available
90  *		Transit port to read unavailable
91  *		- cv_wait write available
92  *		Transit port to write unavailable
93  *		Transit port to not ready. (close ldc channel)
94  *		Transit port to deleted state
95  *		Transit port to read and write available
96  *		- cv_broadcast
97  *		- release lock
98  *
99  *		vntsd close the deleted port
100  *		- obtained port lock
101  *		Transit port to close and deleted state
102  *		- release port lock
103  *
104  *		after vntsd deletion of the port
105  *		- obtain softstate lock
106  *		- cv_wait port table unlocked
107  *		Transit softstate to port table locked
108  *		- release softstate lock
109  *		- obtain port lock
110  *		Transit port to unavailable
111  *		destroy port lock
112  *		- obtain softstate lock
113  *		Transit softstate to port table unlocked
114  *		- cv_broadcast
115  *		- release softsate lock
116  *
117  * 2. VCC_PORT_OPEN
118  *
119  *	    Transition from close to open
120  *		- obtain port lock
121  *		transit port to open
122  *		- release port lock
123  *
124  *	    Transition from open to close
125  *		- obtain port lock
126  *		- cv_wait read available
127  *		Transit port to read unavailable
128  *		- cv_wait write available
129  *		Transit port to write unavailable
130  *		Transit port to not ready. (close ldc channel)
131  *		Transit port to close state
132  *		Transit port to read and write available
133  *		- cv_broadcast
134  *		- release lock
135  *
136  * 3. VCC_PORT_USE_READ_LDC/VCC_PORT_USE_WRITE_LDC
137  *	    Transition from read availale/write available
138  *	    to read unavailable/write unavailable
139  *		- obtain port lock
140  *		- cv_wait read available
141  *		Transit to read/write unavailable
142  *		- release port lock
143  *
144  *	    Transition from read unavailale/write unavailable
145  *	    to read available/write available
146  *		- obtain port lock
147  *		Transit to read/write available
148  *		- cv_broadcast
149  *		- release port lock
150  *
151  * 4. VCC_PORT_LDC_CHANNEL_READY
152  *	    Transition from data not ready to data ready
153  *		- obtain port lock
154  *		Transit to data ready
155  *		- cv_broadcast
156  *		- release port lock
157  *
158  *	    Transition from data ready to data not ready
159  *		- obtain port lock
160  *		Transit to data not ready
161  *		- release port lock
162  */
163 
164 #define	    VCC_PORT_AVAIL		0x1	/* port is configured */
165 #define	    VCC_PORT_OPEN		0x2	/* port is opened */
166 #define	    VCC_PORT_LDC_CHANNEL_READY	0x4	/* ready for data transfer */
167 #define	    VCC_PORT_USE_READ_LDC	0x8	/* read lock */
168 #define	    VCC_PORT_USE_WRITE_LDC	0x10	/* write lock */
169 #define	    VCC_PORT_LDC_DATA_READY	0x20	/* data ready */
170 #define	    VCC_PORT_LDC_WRITE_READY	0x40	/* ldc ready receive data */
171 #define	    VCC_PORT_ADDED		0x80	/* added, no ack from vntsd */
172 #define	    VCC_PORT_UPDATED		0x100	/* updated, no ack from vntsd */
173 #define	    VCC_PORT_TERM_RD		0x200	/* suspend write */
174 #define	    VCC_PORT_TERM_WR		0x400	/* suspend read */
175 #define	    VCC_PORT_NONBLOCK		0x800	/* open with non block flag */
176 #define	    VCC_PORT_LDC_LINK_DOWN	0x1000	/* ldc link down */
177 
178 /* Poll Flags */
179 #define	    VCC_POLL_CONFIG	    0x1	    /* poll configuration change  */
180 
181 /* Poll evnets */
182 #define	    VCC_POLL_ADD_PORT	    0x10    /* add a console port */
183 #define	    VCC_POLL_UPDATE_PORT    0x20    /* update a console port  */
184 
185 /* softstate port table state */
186 #define	    VCC_LOCK_PORT_TBL		0x1
187 
188 /* VCC limits */
189 #define	    VCC_MAX_PORTS	    0x800	    /* number of domains */
190 #define	    VCC_MAX_MINORS	    VCC_MAX_PORTS   /* number of minors */
191 
192 
193 #define	    VCC_MAX_PORT_MINORS		(VCC_MAX_MINORS - 1)
194 #define	    VCC_CONTROL_MINOR_IDX	(VCC_MAX_MINORS - 1)
195 
196 /* size of vcc message data */
197 #define	    VCC_MTU_SZ		    56
198 
199 /* Default values */
200 #define	    VCC_HDR_SZ		    8	    /* header size */
201 #define	    VCC_BUF_SZ		    (VCC_HDR_SZ + VCC_MTU_SZ)
202 
203 #define	    VCC_CONTROL_PORT	    0x7ff   /* port 2047 is control port  */
204 #define	    VCC_INST_SHIFT	    11
205 #define	    VCC_INVALID_CHANNEL	    -1
206 #define	    VCC_NO_PID_BLOCKING	    -1
207 
208 #define	    VCC_MINOR_NAME_PREFIX   "ldom-" /* device name prefix */
209 
210 /* HV message data type */
211 #define	    LDC_CONSOLE_CTRL	    0x1	    /* ctrl msg */
212 #define	    LDC_CONSOLE_DATA	    0x2	    /* data msg */
213 
214 /* HV control messages */
215 #define	    LDC_CONSOLE_BREAK	    -1	    /* brk */
216 #define	    LDC_CONSOLE_HUP	    -2	    /* hup */
217 
218 /*  minor number to port number */
219 #define	    VCCPORT(p, minor)	    (p->minor_tbl[(minor & \
220     VCC_CONTROL_PORT)].portno)
221 
222 /*  minor number to minor pointer */
223 #define	    VCCMINORP(p, minor)	    (&(p->minor_tbl[(minor & \
224     VCC_CONTROL_PORT)]))
225 
226 /* minor number to instance */
227 #define	    VCCINST(minor)	    ((minor) >> VCC_INST_SHIFT)
228 
229 
230 /* hv console packet format */
231 typedef struct vcc_msg {
232 	uint8_t		type;		    /* type - data or ctrl */
233 	uint8_t		size;		    /* data size */
234 	uint16_t	unused;		    /* not used */
235 	int32_t		ctrl_msg;	    /* data if type is ctrl */
236 	uint8_t		data[VCC_MTU_SZ];   /* data if type is data */
237 } vcc_msg_t;
238 
239 /*
240  *  minor node to port mapping table
241  */
242 typedef struct vcc_minor {
243 	uint_t		portno;			    /* port number */
244 	char		domain_name[MAXPATHLEN];    /* doman name */
245 } vcc_minor_t;
246 
247 /* console port structure */
248 typedef struct vcc_port {
249 
250 	kmutex_t 	lock;		/* protects port */
251 	kcondvar_t	read_cv;	/* cv to sleep for reads */
252 	kcondvar_t	write_cv;	/* cv to sleep for writes */
253 
254 	uint_t		number;		/* port number */
255 	uint32_t	status;		/* port status */
256 
257 	char		group_name[MAXPATHLEN];
258 	uint64_t	tcp_port;	/* tcp port num */
259 
260 	struct	termios	term;		/* terminal emulation */
261 
262 	vcc_minor_t	*minorp;	/* pointer to minor table entry */
263 
264 	uint64_t	ldc_id;		/* Channel number */
265 	ldc_handle_t	ldc_handle;	/* Channel handle */
266 	ldc_status_t	ldc_status;	/* Channel Status */
267 
268 	uint_t		pollflag;	/* indicated poll status */
269 	struct pollhead	poll;
270 	uint32_t	pollevent;
271 	pid_t		valid_pid;	/* pid that allows cb_ops */
272 
273 } vcc_port_t;
274 
275 /*
276  * vcc  driver's soft state structure
277  */
278 typedef struct vcc {
279 
280 	/* protects vcc_t (soft state)  */
281 	kmutex_t		lock;
282 
283 	uint_t			status;
284 
285 	dev_info_t		*dip;			   /* dev_info */
286 
287 	mdeg_node_spec_t	*md_ispecp;		   /* mdeg prop spec */
288 	mdeg_handle_t		mdeg_hdl;		   /* mdeg handle */
289 
290 	vcc_port_t		port[VCC_MAX_PORTS];	   /* port table */
291 	uint_t			num_ports;		   /* avail ports */
292 
293 	vcc_minor_t		minor_tbl[VCC_MAX_PORTS];   /* minor table */
294 	uint_t			minors_assigned;	   /* assigned minors */
295 } vcc_t;
296 
297 #ifdef __cplusplus
298 }
299 #endif
300 
301 #endif	/* _VCC_IMPL_H */
302