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