xref: /titanic_50/usr/src/uts/sun4v/sys/vldc_impl.h (revision 77a7fd96f77f04bbd7634db14755686062589eca)
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 /*
71  * Minor node number to port number mapping table.
72  *
73  * The lock field in the vldc_minor structure is used to serialize operations
74  * on the port associated with the minor node. It also protects the minor node
75  * in_use field which is used to track the number of active users of the minor
76  * node.  Driver ops will either hold the lock over the whole operation or
77  * will increment (and then decrement) the in use count if they need to
78  * release and re-acquire the lock, e.g. when copying data in from or out to
79  * userland. When the MDEG framework calls into the driver via the callback to
80  * remove a port, the driver must wait until the in use count for the minor
81  * node associated with the port drops to zero, before it can remove the
82  * port.
83  */
84 typedef struct vldc_minor {
85 	kmutex_t 	lock;			/* protects port/in_use count */
86 	kcondvar_t	cv;			/* for waiting on in use */
87 	uint_t		in_use;			/* in use counter */
88 	uint_t		portno;			/* port number */
89 	char		sname[MAXPATHLEN];	/* service name */
90 } vldc_minor_t;
91 
92 typedef struct vldc_port {
93 	uint_t		number;			/* port number */
94 	uint32_t	status;			/* port status */
95 	vldc_minor_t	*minorp;		/* minor table entry pointer */
96 	uint32_t	mtu;			/* port mtu */
97 	caddr_t		send_buf;		/* send buffer */
98 	caddr_t		recv_buf;		/* receive buffer */
99 	caddr_t		cookie_buf;		/* rd/wr cookie buffer */
100 
101 	uint64_t	ldc_id;			/* Channel number */
102 	ldc_handle_t	ldc_handle;		/* Channel handle */
103 	ldc_mode_t	ldc_mode;		/* Channel mode */
104 
105 	boolean_t	is_stream;		/* streaming mode */
106 	boolean_t	hanged_up;		/* port hanged up */
107 
108 	struct pollhead	poll;			/* for poll */
109 } vldc_port_t;
110 
111 /*
112  * vldc driver's soft state structure
113  */
114 typedef struct vldc {
115 	kmutex_t 		lock;		/* serializes detach and MDEG */
116 	boolean_t		detaching; 	/* true iff busy detaching */
117 	dev_info_t		*dip;		/* dev_info */
118 	mdeg_node_spec_t	*inst_spec;	/* vldc instance specifier */
119 	mdeg_handle_t		mdeg_hdl;	/* MD event handle */
120 
121 	uint_t 			num_ports;
122 	vldc_port_t		port[VLDC_MAX_PORTS];
123 
124 	/* table for assigned minors */
125 	vldc_minor_t		minor_tbl[VLDC_MAX_MINORS];
126 
127 	/* number of minors already assigned */
128 	uint_t			minors_assigned;
129 } vldc_t;
130 
131 #ifdef __cplusplus
132 }
133 #endif
134 
135 #endif /* _VLDC_IMPL_H */
136