xref: /onnv-gate/usr/src/uts/sun4v/sys/vldc_impl.h (revision 3151:9a7f99c63ca3)
11991Sheppo /*
21991Sheppo  * CDDL HEADER START
31991Sheppo  *
41991Sheppo  * The contents of this file are subject to the terms of the
51991Sheppo  * Common Development and Distribution License (the "License").
61991Sheppo  * You may not use this file except in compliance with the License.
71991Sheppo  *
81991Sheppo  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91991Sheppo  * or http://www.opensolaris.org/os/licensing.
101991Sheppo  * See the License for the specific language governing permissions
111991Sheppo  * and limitations under the License.
121991Sheppo  *
131991Sheppo  * When distributing Covered Code, include this CDDL HEADER in each
141991Sheppo  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151991Sheppo  * If applicable, add the following below this CDDL HEADER, with the
161991Sheppo  * fields enclosed by brackets "[]" replaced with your own identifying
171991Sheppo  * information: Portions Copyright [yyyy] [name of copyright owner]
181991Sheppo  *
191991Sheppo  * CDDL HEADER END
201991Sheppo  */
211991Sheppo 
221991Sheppo /*
231991Sheppo  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
241991Sheppo  * Use is subject to license terms.
251991Sheppo  */
261991Sheppo 
271991Sheppo #ifndef _VLDC_IMPL_H
281991Sheppo #define	_VLDC_IMPL_H
291991Sheppo 
301991Sheppo #pragma ident	"%Z%%M%	%I%	%E% SMI"
311991Sheppo 
321991Sheppo #ifdef __cplusplus
331991Sheppo extern "C" {
341991Sheppo #endif
351991Sheppo 
361991Sheppo #include <sys/stream.h>
371991Sheppo #include <sys/ddi.h>
381991Sheppo #include <sys/sunddi.h>
391991Sheppo #include <sys/ldc.h>
401991Sheppo #include <sys/vldc.h>
411991Sheppo 
421991Sheppo /* default values */
432617Sjm22469 #define	VLDC_DEFAULT_MTU	0x1000	/* default mtu size 4K */
441991Sheppo 
451991Sheppo /* VLDC limits */
461991Sheppo #define	VLDC_MAX_COOKIE		0x40000	/* max. size of xfer to/from HV */
471991Sheppo #define	VLDC_MAX_MTU		0x40000	/* 256K */
481991Sheppo #define	VLDC_MAX_PORTS		0x800
491991Sheppo #define	VLDC_MAX_MINORS		VLDC_MAX_PORTS
501991Sheppo 
511991Sheppo #define	VLDC_MINOR_MASK		(VLDC_MAX_PORTS - 1)
521991Sheppo #define	VLDC_INST_SHIFT		11
531991Sheppo 
542336Snarayan #define	VLDC_HVCTL_SVCNAME	"hvctl"
552336Snarayan 
561991Sheppo /* get port number from minor number */
571991Sheppo #define	VLDCPORT(vldcp, minor)	\
581991Sheppo 		((vldcp)->minor_tbl[(minor) & VLDC_MINOR_MASK].portno)
591991Sheppo 
601991Sheppo /* get minor table entry from minor number */
611991Sheppo #define	VLDCMINOR(vldcp, minor)	\
621991Sheppo 		(&((vldcp)->minor_tbl[(minor) & VLDC_MINOR_MASK]))
631991Sheppo 
641991Sheppo /* get instance number from minor number */
651991Sheppo #define	VLDCINST(minor)		((minor) >> VLDC_INST_SHIFT)
661991Sheppo 
671991Sheppo /* indicates an invalid port number */
681991Sheppo #define	VLDC_INVALID_PORTNO	((uint_t)-1)
691991Sheppo 
70*3151Ssg70180 /* delay(in us) used to wait for pending callback to complete */
71*3151Ssg70180 #define	VLDC_CLOSE_DELAY	MICROSEC	/* 1sec */
72*3151Ssg70180 
731991Sheppo /*
741991Sheppo  * Minor node number to port number mapping table.
751991Sheppo  *
761991Sheppo  * The lock field in the vldc_minor structure is used to serialize operations
771991Sheppo  * on the port associated with the minor node. It also protects the minor node
781991Sheppo  * in_use field which is used to track the number of active users of the minor
791991Sheppo  * node.  Driver ops will either hold the lock over the whole operation or
801991Sheppo  * will increment (and then decrement) the in use count if they need to
811991Sheppo  * release and re-acquire the lock, e.g. when copying data in from or out to
821991Sheppo  * userland. When the MDEG framework calls into the driver via the callback to
831991Sheppo  * remove a port, the driver must wait until the in use count for the minor
841991Sheppo  * node associated with the port drops to zero, before it can remove the
851991Sheppo  * port.
861991Sheppo  */
871991Sheppo typedef struct vldc_minor {
881991Sheppo 	kmutex_t 	lock;			/* protects port/in_use count */
891991Sheppo 	kcondvar_t	cv;			/* for waiting on in use */
901991Sheppo 	uint_t		in_use;			/* in use counter */
911991Sheppo 	uint_t		portno;			/* port number */
921991Sheppo 	char		sname[MAXPATHLEN];	/* service name */
931991Sheppo } vldc_minor_t;
941991Sheppo 
951991Sheppo typedef struct vldc_port {
961991Sheppo 	uint_t		number;			/* port number */
971991Sheppo 	uint32_t	status;			/* port status */
982793Slm66018 	uint_t		inst;			/* vldc instance */
991991Sheppo 	vldc_minor_t	*minorp;		/* minor table entry pointer */
1001991Sheppo 	uint32_t	mtu;			/* port mtu */
1011991Sheppo 	caddr_t		send_buf;		/* send buffer */
1021991Sheppo 	caddr_t		recv_buf;		/* receive buffer */
1032336Snarayan 	caddr_t		cookie_buf;		/* rd/wr cookie buffer */
1041991Sheppo 
1051991Sheppo 	uint64_t	ldc_id;			/* Channel number */
1061991Sheppo 	ldc_handle_t	ldc_handle;		/* Channel handle */
1071991Sheppo 	ldc_mode_t	ldc_mode;		/* Channel mode */
1082841Snarayan 	ldc_status_t	ldc_status;		/* Channel status */
1091991Sheppo 
1101991Sheppo 	boolean_t	is_stream;		/* streaming mode */
1111991Sheppo 	boolean_t	hanged_up;		/* port hanged up */
1121991Sheppo 
1131991Sheppo 	struct pollhead	poll;			/* for poll */
1141991Sheppo } vldc_port_t;
1151991Sheppo 
1161991Sheppo /*
1171991Sheppo  * vldc driver's soft state structure
1181991Sheppo  */
1191991Sheppo typedef struct vldc {
1201991Sheppo 	kmutex_t 		lock;		/* serializes detach and MDEG */
1211991Sheppo 	boolean_t		detaching; 	/* true iff busy detaching */
1221991Sheppo 	dev_info_t		*dip;		/* dev_info */
1231991Sheppo 	mdeg_node_spec_t	*inst_spec;	/* vldc instance specifier */
1241991Sheppo 	mdeg_handle_t		mdeg_hdl;	/* MD event handle */
1251991Sheppo 
1261991Sheppo 	uint_t 			num_ports;
1271991Sheppo 	vldc_port_t		port[VLDC_MAX_PORTS];
1281991Sheppo 
1291991Sheppo 	/* table for assigned minors */
1301991Sheppo 	vldc_minor_t		minor_tbl[VLDC_MAX_MINORS];
1311991Sheppo 
1321991Sheppo 	/* number of minors already assigned */
1331991Sheppo 	uint_t			minors_assigned;
1341991Sheppo } vldc_t;
1351991Sheppo 
1361991Sheppo #ifdef __cplusplus
1371991Sheppo }
1381991Sheppo #endif
1391991Sheppo 
1401991Sheppo #endif /* _VLDC_IMPL_H */
141