xref: /onnv-gate/usr/src/uts/common/sys/sad.h (revision 12617:d82a7bcb6fed)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
53042Sedp  * Common Development and Distribution License (the "License").
63042Sedp  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*12617SMarek.Pospisil@Sun.COM  * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
260Sstevel@tonic-gate /*	  All Rights Reserved  	*/
270Sstevel@tonic-gate 
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #ifndef _SYS_SAD_H
300Sstevel@tonic-gate #define	_SYS_SAD_H
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <sys/types.h>
333448Sdh155122 #ifdef	_KERNEL
343448Sdh155122 #include <sys/strsubr.h>
353448Sdh155122 #endif
363042Sedp #include <sys/modhash.h>
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #ifdef	__cplusplus
390Sstevel@tonic-gate extern "C" {
400Sstevel@tonic-gate #endif
410Sstevel@tonic-gate 
420Sstevel@tonic-gate /*
430Sstevel@tonic-gate  * Streams Administrative Driver
440Sstevel@tonic-gate  */
450Sstevel@tonic-gate 
460Sstevel@tonic-gate /*
470Sstevel@tonic-gate  * As time has passed, it has become necessary to add members to some
480Sstevel@tonic-gate  * of the structures passed downstream with these ioctls.  Currently,
490Sstevel@tonic-gate  * only the SAD_GAP/SAD_SAP ioctls are versioned, (which use the
500Sstevel@tonic-gate  * strapush structure), but the versioning mechanism is general enough
510Sstevel@tonic-gate  * to be applied to any SAD ioctls.  This is done by repartitioning
520Sstevel@tonic-gate  * the SAD ioctl namespace to include a version number in addition to
530Sstevel@tonic-gate  * the command (see below).
540Sstevel@tonic-gate  *
550Sstevel@tonic-gate  * In the case of the SAD_GAP/SAD_SAP ioctls, an application can
560Sstevel@tonic-gate  * choose which "version" of the ioctl to use by #defining AP_VERSION
570Sstevel@tonic-gate  * before including this file. Old code implicitly has AP_VERSION set
580Sstevel@tonic-gate  * to 0, and even newly compiled code defaults to an AP_VERSION of 0,
590Sstevel@tonic-gate  * since it may not be aware of the new structure members and
600Sstevel@tonic-gate  * therefore not know to set them to reasonable values.  In order for
610Sstevel@tonic-gate  * programs to make use of a newer version, they must explicitly
620Sstevel@tonic-gate  * #define AP_VERSION to the appropriate value. Note that the kernel
630Sstevel@tonic-gate  * always defaults to the latest version, since it is internally
640Sstevel@tonic-gate  * self-consistent.
650Sstevel@tonic-gate  */
660Sstevel@tonic-gate #ifndef	AP_VERSION
670Sstevel@tonic-gate #ifdef	_KERNEL
680Sstevel@tonic-gate #define	AP_VERSION		1		/* latest version */
690Sstevel@tonic-gate #else
700Sstevel@tonic-gate #define	AP_VERSION		0		/* SVR4 version */
710Sstevel@tonic-gate #endif
720Sstevel@tonic-gate #endif
730Sstevel@tonic-gate 
740Sstevel@tonic-gate /*
750Sstevel@tonic-gate  * ioctl defines
760Sstevel@tonic-gate  *
770Sstevel@tonic-gate  * The layout for the low 16 bits is 01000101VVVVCCCC, where the
780Sstevel@tonic-gate  * first bitpattern is `D' in binary, followed by a 4 bit version
790Sstevel@tonic-gate  * field (limiting the number of versions to 16), followed by a
800Sstevel@tonic-gate  * 4 bit command field (limiting the number of commands to 16).
810Sstevel@tonic-gate  */
820Sstevel@tonic-gate #define	SADIOC		('D' << 8)
830Sstevel@tonic-gate #define	SAD_SAP		(SADIOC|AP_VERSION << 4|01)
840Sstevel@tonic-gate #define	SAD_GAP		(SADIOC|AP_VERSION << 4|02)
850Sstevel@tonic-gate #define	SAD_VML		(SADIOC|03)		/* validate module list */
860Sstevel@tonic-gate 
870Sstevel@tonic-gate /*
880Sstevel@tonic-gate  * Device naming and numbering conventions.
890Sstevel@tonic-gate  */
900Sstevel@tonic-gate #define	USERDEV		"/dev/sad/user"
910Sstevel@tonic-gate #define	ADMINDEV	"/dev/sad/admin"
920Sstevel@tonic-gate 
930Sstevel@tonic-gate #define	USRMIN		0
940Sstevel@tonic-gate #define	ADMMIN		1
950Sstevel@tonic-gate 
960Sstevel@tonic-gate /*
970Sstevel@tonic-gate  * The maximum modules you can push on a stream using the autopush
980Sstevel@tonic-gate  * feature.  This should be less than NSTRPUSH.
990Sstevel@tonic-gate  */
1000Sstevel@tonic-gate #define	MAXAPUSH	8
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate /*
1030Sstevel@tonic-gate  * autopush info common to user and kernel
1040Sstevel@tonic-gate  */
1050Sstevel@tonic-gate struct apcommon {
1060Sstevel@tonic-gate 	uint_t	apc_cmd;		/* command (see below) */
1070Sstevel@tonic-gate 	major_t	apc_major;		/* major # of device */
1080Sstevel@tonic-gate 	minor_t	apc_minor;		/* minor # of device */
1090Sstevel@tonic-gate 	minor_t	apc_lastminor;		/* last minor for range */
1100Sstevel@tonic-gate 	uint_t	apc_npush;		/* number of modules to push */
1110Sstevel@tonic-gate };
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate /*
1140Sstevel@tonic-gate  * New autopush information structure.  This wouldn't be necessary
1150Sstevel@tonic-gate  * except `struct apcommon' wasn't defined last in the `strapush'
1160Sstevel@tonic-gate  * structure, making it difficult to grow the structure without
1170Sstevel@tonic-gate  * breaking binary compatibility.  Note that new members can be added
1180Sstevel@tonic-gate  * to this structure in the future, at which point AP_VERSION should
1190Sstevel@tonic-gate  * be incremented (of course, a new STRAPUSH_Vx_LEN macro should be
1200Sstevel@tonic-gate  * added and sad.c should be changed to handle the new member).
1210Sstevel@tonic-gate  */
1220Sstevel@tonic-gate struct apdata {
1230Sstevel@tonic-gate 	uint_t		apd_anchor;	/* position of anchor in stream */
1240Sstevel@tonic-gate };
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate /*
1270Sstevel@tonic-gate  * ap_cmd: various flavors of autopush
1280Sstevel@tonic-gate  */
1290Sstevel@tonic-gate #define	SAP_CLEAR	0		/* remove configuration list */
1300Sstevel@tonic-gate #define	SAP_ONE		1		/* configure one minor device */
1310Sstevel@tonic-gate #define	SAP_RANGE	2		/* configure range of minor devices */
1320Sstevel@tonic-gate #define	SAP_ALL		3		/* configure all minor devices */
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate /*
1350Sstevel@tonic-gate  * format for autopush ioctls
1360Sstevel@tonic-gate  */
1370Sstevel@tonic-gate struct strapush {
1380Sstevel@tonic-gate 	struct apcommon	sap_common;			  /* see above */
1390Sstevel@tonic-gate 	char		sap_list[MAXAPUSH][FMNAMESZ + 1]; /* module list */
1400Sstevel@tonic-gate #if AP_VERSION > 0
1410Sstevel@tonic-gate 	struct apdata	sap_data;			  /* see above */
1420Sstevel@tonic-gate #endif
1430Sstevel@tonic-gate };
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate #define	sap_cmd		sap_common.apc_cmd
1460Sstevel@tonic-gate #define	sap_major	sap_common.apc_major
1470Sstevel@tonic-gate #define	sap_minor	sap_common.apc_minor
1480Sstevel@tonic-gate #define	sap_lastminor	sap_common.apc_lastminor
1490Sstevel@tonic-gate #define	sap_npush	sap_common.apc_npush
1500Sstevel@tonic-gate #define	sap_anchor	sap_data.apd_anchor
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate #ifdef _KERNEL
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate /*
1550Sstevel@tonic-gate  * state values for ioctls
1560Sstevel@tonic-gate  */
1570Sstevel@tonic-gate #define	GETSTRUCT	1
1580Sstevel@tonic-gate #define	GETRESULT	2
1590Sstevel@tonic-gate #define	GETLIST		3
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate #define	SAD_VER(ioccmd)	(((ioccmd) >> 4) & 0x0f)
1620Sstevel@tonic-gate #define	SAD_CMD(ioccmd)	((ioccmd) & ~0xf0)
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate #define	STRAPUSH_V0_LEN	(size_t)(&((struct strapush *)0)->sap_data)
1650Sstevel@tonic-gate #define	STRAPUSH_V1_LEN	(size_t)(STRAPUSH_V0_LEN + sizeof (uint_t))
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate struct saddev {
1680Sstevel@tonic-gate 	queue_t	*sa_qp;		/* pointer to read queue */
1690Sstevel@tonic-gate 	caddr_t	 sa_addr;	/* saved address for copyout */
1700Sstevel@tonic-gate 	int	 sa_flags;	/* see below */
1713448Sdh155122 	str_stack_t *sa_ss;
1720Sstevel@tonic-gate };
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate /*
1750Sstevel@tonic-gate  * values for saddev flags field.
1760Sstevel@tonic-gate  */
1770Sstevel@tonic-gate #define	SADPRIV		0x01
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate /*
1800Sstevel@tonic-gate  * Module Autopush Cache
1810Sstevel@tonic-gate  */
1820Sstevel@tonic-gate struct autopush {
1830Sstevel@tonic-gate 	struct apcommon  ap_common;		/* see above */
1840Sstevel@tonic-gate 	char		 ap_list[MAXAPUSH][FMNAMESZ + 1];
1850Sstevel@tonic-gate 						/* list of modules to push */
1860Sstevel@tonic-gate 	int		 ap_cnt;		/* in use count */
1870Sstevel@tonic-gate 	struct apdata	 ap_data;		/* see above */
1880Sstevel@tonic-gate };
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate /*
1910Sstevel@tonic-gate  * The command issued by the user ultimately becomes
1920Sstevel@tonic-gate  * the type of the autopush entry.  Therefore, occurrences of
1930Sstevel@tonic-gate  * "type" in the code refer to an existing autopush entry.
1940Sstevel@tonic-gate  * Occurrences of "cmd" in the code refer to the command the
1950Sstevel@tonic-gate  * user is currently trying to complete.  types and cmds take
1960Sstevel@tonic-gate  * on the same values.
1970Sstevel@tonic-gate  */
1980Sstevel@tonic-gate #define	ap_type		ap_common.apc_cmd
1990Sstevel@tonic-gate #define	ap_major	ap_common.apc_major
2000Sstevel@tonic-gate #define	ap_minor	ap_common.apc_minor
2010Sstevel@tonic-gate #define	ap_lastminor	ap_common.apc_lastminor
2020Sstevel@tonic-gate #define	ap_npush	ap_common.apc_npush
2030Sstevel@tonic-gate #define	ap_anchor	ap_data.apd_anchor
2040Sstevel@tonic-gate 
2050Sstevel@tonic-gate /*
2060Sstevel@tonic-gate  * function prototypes
2070Sstevel@tonic-gate  */
2080Sstevel@tonic-gate struct strbuf;
2090Sstevel@tonic-gate void audit_strputmsg(struct vnode *, struct strbuf *, struct strbuf *,
2100Sstevel@tonic-gate 						unsigned char, int, int);
2110Sstevel@tonic-gate void audit_fdsend(int, struct file *, int);
2120Sstevel@tonic-gate void audit_fdrecv(int, struct file *);
2130Sstevel@tonic-gate 
2143448Sdh155122 extern void sad_initspace(str_stack_t *);
2153448Sdh155122 extern void sad_freespace(str_stack_t *);
2160Sstevel@tonic-gate 
2173042Sedp /*
2183448Sdh155122  * The following interfaces do not care about ss_sad_lock.
2193042Sedp  */
2203042Sedp extern struct autopush *sad_ap_alloc(void);
2213042Sedp extern int sad_apc_verify(struct apcommon *);
2223042Sedp extern int sad_ap_verify(struct autopush *);
2233042Sedp 
2243042Sedp /*
2253448Sdh155122  * The following interfaces attempt to acquire ss_sad_lock.
2263042Sedp  */
2273448Sdh155122 extern void sad_ap_rele(struct autopush *, str_stack_t *);
2283448Sdh155122 extern struct autopush *sad_ap_find_by_dev(dev_t, str_stack_t *);
2293042Sedp 
2303042Sedp /*
2313448Sdh155122  * The following interfaces require ss_sad_lock to be held when invoked.
2323042Sedp  */
2333448Sdh155122 extern void sad_ap_insert(struct autopush *, str_stack_t *);
2343448Sdh155122 extern void sad_ap_remove(struct autopush *, str_stack_t *);
2353448Sdh155122 extern struct autopush *sad_ap_find(struct apcommon *, str_stack_t *);
2363042Sedp 
2370Sstevel@tonic-gate #endif /* _KERNEL */
2380Sstevel@tonic-gate 
2390Sstevel@tonic-gate #ifdef	__cplusplus
2400Sstevel@tonic-gate }
2410Sstevel@tonic-gate #endif
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate #endif	/* _SYS_SAD_H */
244