xref: /titanic_51/usr/src/uts/sun4v/sys/vcc_impl.h (revision 355b4669e025ff377602b6fc7caaf30dbc218371)
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 
200 /* Default values */
201 #define	    VCC_HDR_SZ		    8	    /* header size */
202 #define	    VCC_BUF_SZ		    (VCC_HDR_SZ + VCC_MTU_SZ)
203 
204 #define	    VCC_CONTROL_PORT	    0x7ff   /* port 2047 is control port  */
205 #define	    VCC_INST_SHIFT	    11
206 #define	    VCC_INVALID_CHANNEL	    -1
207 #define	    VCC_NO_PID_BLOCKING	    -1
208 
209 #define	    VCC_QUEUE_LEN	    0x80    /* ldc queue size */
210 
211 #define	    VCC_MINOR_NAME_PREFIX   "ldom-" /* device name prefix */
212 
213 /* HV message data type */
214 #define	    LDC_CONSOLE_CTRL	    0x1	    /* ctrl msg */
215 #define	    LDC_CONSOLE_DATA	    0x2	    /* data msg */
216 
217 /* HV control messages */
218 #define	    LDC_CONSOLE_BREAK	    -1	    /* brk */
219 #define	    LDC_CONSOLE_HUP	    -2	    /* hup */
220 
221 /*  minor number to port number */
222 #define	    VCCPORT(p, minor)	    (p->minor_tbl[(minor & \
223     VCC_CONTROL_PORT)].portno)
224 
225 /*  minor number to minor pointer */
226 #define	    VCCMINORP(p, minor)	    (&(p->minor_tbl[(minor & \
227     VCC_CONTROL_PORT)]))
228 
229 /* minor number to instance */
230 #define	    VCCINST(minor)	    ((minor) >> VCC_INST_SHIFT)
231 
232 
233 /* hv console packet format */
234 typedef struct vcc_msg {
235 	uint8_t		type;		    /* type - data or ctrl */
236 	uint8_t		size;		    /* data size */
237 	uint16_t	unused;		    /* not used */
238 	int32_t		ctrl_msg;	    /* data if type is ctrl */
239 	uint8_t		data[VCC_MTU_SZ];   /* data if type is data */
240 } vcc_msg_t;
241 
242 /*
243  *  minor node to port mapping table
244  */
245 typedef struct vcc_minor {
246 	uint_t		portno;			    /* port number */
247 	char		domain_name[MAXPATHLEN];    /* doman name */
248 } vcc_minor_t;
249 
250 /* console port structure */
251 typedef struct vcc_port {
252 
253 	kmutex_t 	lock;		/* protects port */
254 	kcondvar_t	read_cv;	/* cv to sleep for reads */
255 	kcondvar_t	write_cv;	/* cv to sleep for writes */
256 
257 	uint_t		number;		/* port number */
258 	uint32_t	status;		/* port status */
259 
260 	char		group_name[MAXPATHLEN];
261 	uint64_t	tcp_port;	/* tcp port num */
262 
263 	struct	termios	term;		/* terminal emulation */
264 
265 	vcc_minor_t	*minorp;	/* pointer to minor table entry */
266 
267 	uint64_t	ldc_id;		/* Channel number */
268 	ldc_handle_t	ldc_handle;	/* Channel handle */
269 	ldc_status_t	ldc_status;	/* Channel Status */
270 
271 	uint_t		pollflag;	/* indicated poll status */
272 	struct pollhead	poll;
273 	uint32_t	pollevent;
274 	pid_t		valid_pid;	/* pid that allows cb_ops */
275 
276 } vcc_port_t;
277 
278 /*
279  * vcc  driver's soft state structure
280  */
281 typedef struct vcc {
282 
283 	/* protects vcc_t (soft state)  */
284 	kmutex_t		lock;
285 
286 	uint_t			status;
287 
288 	dev_info_t		*dip;			   /* dev_info */
289 
290 	mdeg_node_spec_t	*md_ispecp;		   /* mdeg prop spec */
291 	mdeg_handle_t		mdeg_hdl;		   /* mdeg handle */
292 
293 	vcc_port_t		port[VCC_MAX_PORTS];	   /* port table */
294 	uint_t			num_ports;		   /* avail ports */
295 
296 	vcc_minor_t		minor_tbl[VCC_MAX_PORTS];   /* minor table */
297 	uint_t			minors_assigned;	   /* assigned minors */
298 } vcc_t;
299 
300 #ifdef __cplusplus
301 }
302 #endif
303 
304 #endif	/* _VCC_IMPL_H */
305