xref: /illumos-gate/usr/src/uts/sun4v/sys/vldc_impl.h (revision 4d39be2b)
11ae08745Sheppo /*
21ae08745Sheppo  * CDDL HEADER START
31ae08745Sheppo  *
41ae08745Sheppo  * The contents of this file are subject to the terms of the
51ae08745Sheppo  * Common Development and Distribution License (the "License").
61ae08745Sheppo  * You may not use this file except in compliance with the License.
71ae08745Sheppo  *
81ae08745Sheppo  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91ae08745Sheppo  * or http://www.opensolaris.org/os/licensing.
101ae08745Sheppo  * See the License for the specific language governing permissions
111ae08745Sheppo  * and limitations under the License.
121ae08745Sheppo  *
131ae08745Sheppo  * When distributing Covered Code, include this CDDL HEADER in each
141ae08745Sheppo  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151ae08745Sheppo  * If applicable, add the following below this CDDL HEADER, with the
161ae08745Sheppo  * fields enclosed by brackets "[]" replaced with your own identifying
171ae08745Sheppo  * information: Portions Copyright [yyyy] [name of copyright owner]
181ae08745Sheppo  *
191ae08745Sheppo  * CDDL HEADER END
201ae08745Sheppo  */
211ae08745Sheppo 
221ae08745Sheppo /*
231ae08745Sheppo  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
241ae08745Sheppo  * Use is subject to license terms.
251ae08745Sheppo  */
261ae08745Sheppo 
271ae08745Sheppo #ifndef _VLDC_IMPL_H
281ae08745Sheppo #define	_VLDC_IMPL_H
291ae08745Sheppo 
301ae08745Sheppo #pragma ident	"%Z%%M%	%I%	%E% SMI"
311ae08745Sheppo 
321ae08745Sheppo #ifdef __cplusplus
331ae08745Sheppo extern "C" {
341ae08745Sheppo #endif
351ae08745Sheppo 
361ae08745Sheppo #include <sys/stream.h>
371ae08745Sheppo #include <sys/ddi.h>
381ae08745Sheppo #include <sys/sunddi.h>
391ae08745Sheppo #include <sys/ldc.h>
401ae08745Sheppo #include <sys/vldc.h>
411ae08745Sheppo 
421ae08745Sheppo /* default values */
43592b39e7Sjm #define	VLDC_DEFAULT_MTU	0x1000	/* default mtu size 4K */
441ae08745Sheppo 
451ae08745Sheppo /* VLDC limits */
461ae08745Sheppo #define	VLDC_MAX_COOKIE		0x40000	/* max. size of xfer to/from HV */
471ae08745Sheppo #define	VLDC_MAX_MTU		0x40000	/* 256K */
481ae08745Sheppo #define	VLDC_MAX_PORTS		0x800
491ae08745Sheppo #define	VLDC_MAX_MINORS		VLDC_MAX_PORTS
501ae08745Sheppo 
511ae08745Sheppo #define	VLDC_MINOR_MASK		(VLDC_MAX_PORTS - 1)
521ae08745Sheppo #define	VLDC_INST_SHIFT		11
531ae08745Sheppo 
54d10e4ef2Snarayan #define	VLDC_HVCTL_SVCNAME	"hvctl"
55d10e4ef2Snarayan 
561ae08745Sheppo /* get port number from minor number */
571ae08745Sheppo #define	VLDCPORT(vldcp, minor)	\
581ae08745Sheppo 		((vldcp)->minor_tbl[(minor) & VLDC_MINOR_MASK].portno)
591ae08745Sheppo 
601ae08745Sheppo /* get minor table entry from minor number */
611ae08745Sheppo #define	VLDCMINOR(vldcp, minor)	\
621ae08745Sheppo 		(&((vldcp)->minor_tbl[(minor) & VLDC_MINOR_MASK]))
631ae08745Sheppo 
641ae08745Sheppo /* get instance number from minor number */
651ae08745Sheppo #define	VLDCINST(minor)		((minor) >> VLDC_INST_SHIFT)
661ae08745Sheppo 
671ae08745Sheppo /* indicates an invalid port number */
681ae08745Sheppo #define	VLDC_INVALID_PORTNO	((uint_t)-1)
691ae08745Sheppo 
70*4d39be2bSsg /* delay(in us) used to wait for pending callback to complete */
71*4d39be2bSsg #define	VLDC_CLOSE_DELAY	MICROSEC	/* 1sec */
72*4d39be2bSsg 
731ae08745Sheppo /*
741ae08745Sheppo  * Minor node number to port number mapping table.
751ae08745Sheppo  *
761ae08745Sheppo  * The lock field in the vldc_minor structure is used to serialize operations
771ae08745Sheppo  * on the port associated with the minor node. It also protects the minor node
781ae08745Sheppo  * in_use field which is used to track the number of active users of the minor
791ae08745Sheppo  * node.  Driver ops will either hold the lock over the whole operation or
801ae08745Sheppo  * will increment (and then decrement) the in use count if they need to
811ae08745Sheppo  * release and re-acquire the lock, e.g. when copying data in from or out to
821ae08745Sheppo  * userland. When the MDEG framework calls into the driver via the callback to
831ae08745Sheppo  * remove a port, the driver must wait until the in use count for the minor
841ae08745Sheppo  * node associated with the port drops to zero, before it can remove the
851ae08745Sheppo  * port.
861ae08745Sheppo  */
871ae08745Sheppo typedef struct vldc_minor {
881ae08745Sheppo 	kmutex_t 	lock;			/* protects port/in_use count */
891ae08745Sheppo 	kcondvar_t	cv;			/* for waiting on in use */
901ae08745Sheppo 	uint_t		in_use;			/* in use counter */
911ae08745Sheppo 	uint_t		portno;			/* port number */
921ae08745Sheppo 	char		sname[MAXPATHLEN];	/* service name */
931ae08745Sheppo } vldc_minor_t;
941ae08745Sheppo 
951ae08745Sheppo typedef struct vldc_port {
961ae08745Sheppo 	uint_t		number;			/* port number */
971ae08745Sheppo 	uint32_t	status;			/* port status */
983af08d82Slm 	uint_t		inst;			/* vldc instance */
991ae08745Sheppo 	vldc_minor_t	*minorp;		/* minor table entry pointer */
1001ae08745Sheppo 	uint32_t	mtu;			/* port mtu */
1011ae08745Sheppo 	caddr_t		send_buf;		/* send buffer */
1021ae08745Sheppo 	caddr_t		recv_buf;		/* receive buffer */
103d10e4ef2Snarayan 	caddr_t		cookie_buf;		/* rd/wr cookie buffer */
1041ae08745Sheppo 
1051ae08745Sheppo 	uint64_t	ldc_id;			/* Channel number */
1061ae08745Sheppo 	ldc_handle_t	ldc_handle;		/* Channel handle */
1071ae08745Sheppo 	ldc_mode_t	ldc_mode;		/* Channel mode */
108a8ea4edeSnarayan 	ldc_status_t	ldc_status;		/* Channel status */
1091ae08745Sheppo 
1101ae08745Sheppo 	boolean_t	is_stream;		/* streaming mode */
1111ae08745Sheppo 	boolean_t	hanged_up;		/* port hanged up */
1121ae08745Sheppo 
1131ae08745Sheppo 	struct pollhead	poll;			/* for poll */
1141ae08745Sheppo } vldc_port_t;
1151ae08745Sheppo 
1161ae08745Sheppo /*
1171ae08745Sheppo  * vldc driver's soft state structure
1181ae08745Sheppo  */
1191ae08745Sheppo typedef struct vldc {
1201ae08745Sheppo 	kmutex_t 		lock;		/* serializes detach and MDEG */
1211ae08745Sheppo 	boolean_t		detaching; 	/* true iff busy detaching */
1221ae08745Sheppo 	dev_info_t		*dip;		/* dev_info */
1231ae08745Sheppo 	mdeg_node_spec_t	*inst_spec;	/* vldc instance specifier */
1241ae08745Sheppo 	mdeg_handle_t		mdeg_hdl;	/* MD event handle */
1251ae08745Sheppo 
1261ae08745Sheppo 	uint_t 			num_ports;
1271ae08745Sheppo 	vldc_port_t		port[VLDC_MAX_PORTS];
1281ae08745Sheppo 
1291ae08745Sheppo 	/* table for assigned minors */
1301ae08745Sheppo 	vldc_minor_t		minor_tbl[VLDC_MAX_MINORS];
1311ae08745Sheppo 
1321ae08745Sheppo 	/* number of minors already assigned */
1331ae08745Sheppo 	uint_t			minors_assigned;
1341ae08745Sheppo } vldc_t;
1351ae08745Sheppo 
1361ae08745Sheppo #ifdef __cplusplus
1371ae08745Sheppo }
1381ae08745Sheppo #endif
1391ae08745Sheppo 
1401ae08745Sheppo #endif /* _VLDC_IMPL_H */
141