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