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