xref: /onnv-gate/usr/src/uts/common/sys/devid_cache.h (revision 2797:3782a13773c1)
1*2797Sjg /*
2*2797Sjg  * CDDL HEADER START
3*2797Sjg  *
4*2797Sjg  * The contents of this file are subject to the terms of the
5*2797Sjg  * Common Development and Distribution License (the "License").
6*2797Sjg  * You may not use this file except in compliance with the License.
7*2797Sjg  *
8*2797Sjg  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*2797Sjg  * or http://www.opensolaris.org/os/licensing.
10*2797Sjg  * See the License for the specific language governing permissions
11*2797Sjg  * and limitations under the License.
12*2797Sjg  *
13*2797Sjg  * When distributing Covered Code, include this CDDL HEADER in each
14*2797Sjg  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*2797Sjg  * If applicable, add the following below this CDDL HEADER, with the
16*2797Sjg  * fields enclosed by brackets "[]" replaced with your own identifying
17*2797Sjg  * information: Portions Copyright [yyyy] [name of copyright owner]
18*2797Sjg  *
19*2797Sjg  * CDDL HEADER END
20*2797Sjg  */
21*2797Sjg /*
22*2797Sjg  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23*2797Sjg  * Use is subject to license terms.
24*2797Sjg  */
25*2797Sjg 
26*2797Sjg #ifndef	_SYS_DEVID_CACHE_H
27*2797Sjg #define	_SYS_DEVID_CACHE_H
28*2797Sjg 
29*2797Sjg #pragma ident	"%Z%%M%	%I%	%E% SMI"
30*2797Sjg 
31*2797Sjg #ifdef	__cplusplus
32*2797Sjg extern "C" {
33*2797Sjg #endif
34*2797Sjg 
35*2797Sjg #include <sys/list.h>
36*2797Sjg 
37*2797Sjg /*
38*2797Sjg  * The top-level nvpair identifiers in the
39*2797Sjg  * /etc/devices/devid_cache nvlist format
40*2797Sjg  */
41*2797Sjg #define	DP_DEVID_ID			"devid"
42*2797Sjg 
43*2797Sjg #ifdef	_KERNEL
44*2797Sjg 
45*2797Sjg /* devid-specific list element */
46*2797Sjg typedef struct nvp_devid {
47*2797Sjg 	int			nvp_flags;
48*2797Sjg 	char			*nvp_devpath;
49*2797Sjg 	dev_info_t		*nvp_dip;
50*2797Sjg 	ddi_devid_t		nvp_devid;
51*2797Sjg 	list_node_t		nvp_link;	/* link to next element */
52*2797Sjg } nvp_devid_t;
53*2797Sjg 
54*2797Sjg 
55*2797Sjg /*
56*2797Sjg  * nvp_flags - devid
57*2797Sjg  */
58*2797Sjg #define	NVP_DEVID_REGISTERED	0x01	/* devid registered on this boot */
59*2797Sjg #define	NVP_DEVID_DIP		0x02	/* devinfo valid for this devid */
60*2797Sjg 
61*2797Sjg /*
62*2797Sjg  * tunables - see devid_cache.c for more details
63*2797Sjg  */
64*2797Sjg extern int devid_discovery_boot;
65*2797Sjg extern int devid_discovery_postboot;
66*2797Sjg extern int devid_discovery_postboot_always;
67*2797Sjg extern int devid_discovery_secs;
68*2797Sjg 
69*2797Sjg extern int devid_cache_read_disable;
70*2797Sjg extern int devid_cache_write_disable;
71*2797Sjg 
72*2797Sjg /*
73*2797Sjg  * More thorough error reporting available both debug &
74*2797Sjg  * non-debug kernels, but turned off by default.
75*2797Sjg  */
76*2797Sjg extern int devid_report_error;		/* devid cache operations */
77*2797Sjg 
78*2797Sjg 
79*2797Sjg /*
80*2797Sjg  * function prototypes
81*2797Sjg  */
82*2797Sjg static int	devid_cache_pack_list(nvf_handle_t, nvlist_t **);
83*2797Sjg static int	devid_cache_unpack_nvlist(nvf_handle_t, nvlist_t *, char *);
84*2797Sjg static void	devid_list_free(nvf_handle_t);
85*2797Sjg 
86*2797Sjg 
87*2797Sjg #ifdef	DEBUG
88*2797Sjg 
89*2797Sjg #define	DEVID_DEBUG(args)	{ if (devid_debug) cmn_err args; }
90*2797Sjg #define	DEVID_DEBUG1(args)	{ if (devid_debug > 1) cmn_err args; }
91*2797Sjg #define	DEVID_DEBUG2(args)	{ if (devid_debug > 2) cmn_err args; }
92*2797Sjg #define	DEVID_DUMP(args)	{ if (devid_debug > 2) args; }
93*2797Sjg #define	DEVID_LOG_REG(args)	{ if (devid_log_registers) devid_log args; }
94*2797Sjg #define	DEVID_LOG_FIND(args)	{ if (devid_log_finds) devid_log args; }
95*2797Sjg #define	DEVID_LOG_LOOKUP(args)	{ if (devid_log_lookups) cmn_err args; }
96*2797Sjg #define	DEVID_LOG_MATCH(args)	{ if (devid_log_matches) devid_log args; }
97*2797Sjg #define	DEVID_LOG_PATHS(args)	{ if (devid_log_paths) cmn_err args; }
98*2797Sjg #define	DEVID_LOG_ERR(args)	{ if (devid_log_failures) devid_log args; }
99*2797Sjg #define	DEVID_LOG_DISC(args)	{ if (devid_log_discovery) cmn_err args; }
100*2797Sjg #define	DEVID_LOG_HOLD(args)	{ if (devid_log_hold) cmn_err args; }
101*2797Sjg #define	DEVID_LOG_UNREG(args)	{ if (devid_log_unregisters) cmn_err args; }
102*2797Sjg #define	DEVID_LOG_REMOVE(args)	{ if (devid_log_removes) cmn_err args; }
103*2797Sjg #define	DEVID_LOG_STALE(args)	{ if (devid_log_stale) devid_log args; }
104*2797Sjg #define	DEVID_LOG_DETACH(args)	{ if (devid_log_detaches) cmn_err args; }
105*2797Sjg 
106*2797Sjg 
107*2797Sjg #define	NVP_DEVID_DEBUG_PATH(arg) {					\
108*2797Sjg 		if (nvp_devid_debug)					\
109*2797Sjg 			cmn_err(CE_CONT, "%s\n", arg);			\
110*2797Sjg 	}
111*2797Sjg 
112*2797Sjg #define	NVP_DEVID_DEBUG_DEVID(arg) {					\
113*2797Sjg 		if (nvp_devid_debug) {					\
114*2797Sjg 			char *ds = ddi_devid_str_encode(arg, NULL);	\
115*2797Sjg 			cmn_err(CE_CONT, "devid: %s\n", ds);		\
116*2797Sjg 			ddi_devid_str_free(ds);				\
117*2797Sjg 		}							\
118*2797Sjg 	}
119*2797Sjg 
120*2797Sjg static void devid_log(char *, ddi_devid_t, char *);
121*2797Sjg 
122*2797Sjg #else
123*2797Sjg 
124*2797Sjg #define	DEVID_DEBUG(args)
125*2797Sjg #define	DEVID_DEBUG1(args)
126*2797Sjg #define	DEVID_DEBUG2(args)
127*2797Sjg #define	DEVID_DUMP(args)
128*2797Sjg #define	DEVID_LOG_REG(args)
129*2797Sjg #define	DEVID_LOG_FIND(args)
130*2797Sjg #define	DEVID_LOG_LOOKUP(args)
131*2797Sjg #define	DEVID_LOG_MATCH(args)
132*2797Sjg #define	DEVID_LOG_PATHS(args)
133*2797Sjg #define	DEVID_LOG_ERR(args)
134*2797Sjg #define	DEVID_LOG_DISC(args)
135*2797Sjg #define	DEVID_LOG_HOLD(args)
136*2797Sjg #define	DEVID_LOG_UNREG(args)
137*2797Sjg #define	DEVID_LOG_REMOVE(args)
138*2797Sjg #define	DEVID_LOG_STALE(args)
139*2797Sjg #define	DEVID_LOG_DETACH(args)
140*2797Sjg #define	NVP_DEVID_DEBUG_PATH(arg)
141*2797Sjg #define	NVP_DEVID_DEBUG_DEVID(arg)
142*2797Sjg 
143*2797Sjg #endif	/* DEBUG */
144*2797Sjg 
145*2797Sjg #define	DEVIDERR(args)		{ if (devid_report_error) cmn_err args; }
146*2797Sjg 
147*2797Sjg #endif	/* _KERNEL */
148*2797Sjg 
149*2797Sjg #ifdef	__cplusplus
150*2797Sjg }
151*2797Sjg #endif
152*2797Sjg 
153*2797Sjg #endif	/* _SYS_DEVID_CACHE_H */
154