xref: /titanic_41/usr/src/uts/sun4v/sys/vldc_impl.h (revision 4d39be2b45b5ac811d28452e6eb629ac64aebfc4)
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 _VLDC_IMPL_H
28 #define	_VLDC_IMPL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/stream.h>
37 #include <sys/ddi.h>
38 #include <sys/sunddi.h>
39 #include <sys/ldc.h>
40 #include <sys/vldc.h>
41 
42 /* default values */
43 #define	VLDC_DEFAULT_MTU	0x1000	/* default mtu size 4K */
44 
45 /* VLDC limits */
46 #define	VLDC_MAX_COOKIE		0x40000	/* max. size of xfer to/from HV */
47 #define	VLDC_MAX_MTU		0x40000	/* 256K */
48 #define	VLDC_MAX_PORTS		0x800
49 #define	VLDC_MAX_MINORS		VLDC_MAX_PORTS
50 
51 #define	VLDC_MINOR_MASK		(VLDC_MAX_PORTS - 1)
52 #define	VLDC_INST_SHIFT		11
53 
54 #define	VLDC_HVCTL_SVCNAME	"hvctl"
55 
56 /* get port number from minor number */
57 #define	VLDCPORT(vldcp, minor)	\
58 		((vldcp)->minor_tbl[(minor) & VLDC_MINOR_MASK].portno)
59 
60 /* get minor table entry from minor number */
61 #define	VLDCMINOR(vldcp, minor)	\
62 		(&((vldcp)->minor_tbl[(minor) & VLDC_MINOR_MASK]))
63 
64 /* get instance number from minor number */
65 #define	VLDCINST(minor)		((minor) >> VLDC_INST_SHIFT)
66 
67 /* indicates an invalid port number */
68 #define	VLDC_INVALID_PORTNO	((uint_t)-1)
69 
70 /* delay(in us) used to wait for pending callback to complete */
71 #define	VLDC_CLOSE_DELAY	MICROSEC	/* 1sec */
72 
73 /*
74  * Minor node number to port number mapping table.
75  *
76  * The lock field in the vldc_minor structure is used to serialize operations
77  * on the port associated with the minor node. It also protects the minor node
78  * in_use field which is used to track the number of active users of the minor
79  * node.  Driver ops will either hold the lock over the whole operation or
80  * will increment (and then decrement) the in use count if they need to
81  * release and re-acquire the lock, e.g. when copying data in from or out to
82  * userland. When the MDEG framework calls into the driver via the callback to
83  * remove a port, the driver must wait until the in use count for the minor
84  * node associated with the port drops to zero, before it can remove the
85  * port.
86  */
87 typedef struct vldc_minor {
88 	kmutex_t 	lock;			/* protects port/in_use count */
89 	kcondvar_t	cv;			/* for waiting on in use */
90 	uint_t		in_use;			/* in use counter */
91 	uint_t		portno;			/* port number */
92 	char		sname[MAXPATHLEN];	/* service name */
93 } vldc_minor_t;
94 
95 typedef struct vldc_port {
96 	uint_t		number;			/* port number */
97 	uint32_t	status;			/* port status */
98 	uint_t		inst;			/* vldc instance */
99 	vldc_minor_t	*minorp;		/* minor table entry pointer */
100 	uint32_t	mtu;			/* port mtu */
101 	caddr_t		send_buf;		/* send buffer */
102 	caddr_t		recv_buf;		/* receive buffer */
103 	caddr_t		cookie_buf;		/* rd/wr cookie buffer */
104 
105 	uint64_t	ldc_id;			/* Channel number */
106 	ldc_handle_t	ldc_handle;		/* Channel handle */
107 	ldc_mode_t	ldc_mode;		/* Channel mode */
108 	ldc_status_t	ldc_status;		/* Channel status */
109 
110 	boolean_t	is_stream;		/* streaming mode */
111 	boolean_t	hanged_up;		/* port hanged up */
112 
113 	struct pollhead	poll;			/* for poll */
114 } vldc_port_t;
115 
116 /*
117  * vldc driver's soft state structure
118  */
119 typedef struct vldc {
120 	kmutex_t 		lock;		/* serializes detach and MDEG */
121 	boolean_t		detaching; 	/* true iff busy detaching */
122 	dev_info_t		*dip;		/* dev_info */
123 	mdeg_node_spec_t	*inst_spec;	/* vldc instance specifier */
124 	mdeg_handle_t		mdeg_hdl;	/* MD event handle */
125 
126 	uint_t 			num_ports;
127 	vldc_port_t		port[VLDC_MAX_PORTS];
128 
129 	/* table for assigned minors */
130 	vldc_minor_t		minor_tbl[VLDC_MAX_MINORS];
131 
132 	/* number of minors already assigned */
133 	uint_t			minors_assigned;
134 } vldc_t;
135 
136 #ifdef __cplusplus
137 }
138 #endif
139 
140 #endif /* _VLDC_IMPL_H */
141