xref: /titanic_50/usr/src/uts/common/sys/devid_cache.h (revision 753a6d457b330b1b29b2d3eefcd0831116ce950d)
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  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_DEVID_CACHE_H
27 #define	_SYS_DEVID_CACHE_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #include <sys/list.h>
36 
37 /*
38  * The top-level nvpair identifiers in the
39  * /etc/devices/devid_cache nvlist format
40  */
41 #define	DP_DEVID_ID			"devid"
42 
43 #ifdef	_KERNEL
44 
45 /* devid-specific list element */
46 typedef struct nvp_devid {
47 	int			nvp_flags;
48 	char			*nvp_devpath;
49 	dev_info_t		*nvp_dip;
50 	ddi_devid_t		nvp_devid;
51 	list_node_t		nvp_link;	/* link to next element */
52 } nvp_devid_t;
53 
54 
55 /*
56  * nvp_flags - devid
57  */
58 #define	NVP_DEVID_REGISTERED	0x01	/* devid registered on this boot */
59 #define	NVP_DEVID_DIP		0x02	/* devinfo valid for this devid */
60 
61 /*
62  * tunables - see devid_cache.c for more details
63  */
64 extern int devid_discovery_boot;
65 extern int devid_discovery_postboot;
66 extern int devid_discovery_postboot_always;
67 extern int devid_discovery_secs;
68 
69 extern int devid_cache_read_disable;
70 extern int devid_cache_write_disable;
71 
72 /*
73  * More thorough error reporting available both debug &
74  * non-debug kernels, but turned off by default.
75  */
76 extern int devid_report_error;		/* devid cache operations */
77 
78 
79 /*
80  * function prototypes
81  */
82 static int	devid_cache_pack_list(nvf_handle_t, nvlist_t **);
83 static int	devid_cache_unpack_nvlist(nvf_handle_t, nvlist_t *, char *);
84 static void	devid_list_free(nvf_handle_t);
85 
86 
87 #ifdef	DEBUG
88 
89 #define	DEVID_DEBUG(args)	{ if (devid_debug) cmn_err args; }
90 #define	DEVID_DEBUG1(args)	{ if (devid_debug > 1) cmn_err args; }
91 #define	DEVID_DEBUG2(args)	{ if (devid_debug > 2) cmn_err args; }
92 #define	DEVID_DUMP(args)	{ if (devid_debug > 2) args; }
93 #define	DEVID_LOG_REG(args)	{ if (devid_log_registers) devid_log args; }
94 #define	DEVID_LOG_FIND(args)	{ if (devid_log_finds) devid_log args; }
95 #define	DEVID_LOG_LOOKUP(args)	{ if (devid_log_lookups) cmn_err args; }
96 #define	DEVID_LOG_MATCH(args)	{ if (devid_log_matches) devid_log args; }
97 #define	DEVID_LOG_PATHS(args)	{ if (devid_log_paths) cmn_err args; }
98 #define	DEVID_LOG_ERR(args)	{ if (devid_log_failures) devid_log args; }
99 #define	DEVID_LOG_DISC(args)	{ if (devid_log_discovery) cmn_err args; }
100 #define	DEVID_LOG_HOLD(args)	{ if (devid_log_hold) cmn_err args; }
101 #define	DEVID_LOG_UNREG(args)	{ if (devid_log_unregisters) cmn_err args; }
102 #define	DEVID_LOG_REMOVE(args)	{ if (devid_log_removes) cmn_err args; }
103 #define	DEVID_LOG_STALE(args)	{ if (devid_log_stale) devid_log args; }
104 #define	DEVID_LOG_DETACH(args)	{ if (devid_log_detaches) cmn_err args; }
105 
106 
107 #define	NVP_DEVID_DEBUG_PATH(arg) {					\
108 		if (nvp_devid_debug)					\
109 			cmn_err(CE_CONT, "%s\n", arg);			\
110 	}
111 
112 #define	NVP_DEVID_DEBUG_DEVID(arg) {					\
113 		if (nvp_devid_debug) {					\
114 			char *ds = ddi_devid_str_encode(arg, NULL);	\
115 			cmn_err(CE_CONT, "devid: %s\n", ds);		\
116 			ddi_devid_str_free(ds);				\
117 		}							\
118 	}
119 
120 static void devid_log(char *, ddi_devid_t, char *);
121 
122 #else
123 
124 #define	DEVID_DEBUG(args)
125 #define	DEVID_DEBUG1(args)
126 #define	DEVID_DEBUG2(args)
127 #define	DEVID_DUMP(args)
128 #define	DEVID_LOG_REG(args)
129 #define	DEVID_LOG_FIND(args)
130 #define	DEVID_LOG_LOOKUP(args)
131 #define	DEVID_LOG_MATCH(args)
132 #define	DEVID_LOG_PATHS(args)
133 #define	DEVID_LOG_ERR(args)
134 #define	DEVID_LOG_DISC(args)
135 #define	DEVID_LOG_HOLD(args)
136 #define	DEVID_LOG_UNREG(args)
137 #define	DEVID_LOG_REMOVE(args)
138 #define	DEVID_LOG_STALE(args)
139 #define	DEVID_LOG_DETACH(args)
140 #define	NVP_DEVID_DEBUG_PATH(arg)
141 #define	NVP_DEVID_DEBUG_DEVID(arg)
142 
143 #endif	/* DEBUG */
144 
145 #define	DEVIDERR(args)		{ if (devid_report_error) cmn_err args; }
146 
147 #endif	/* _KERNEL */
148 
149 #ifdef	__cplusplus
150 }
151 #endif
152 
153 #endif	/* _SYS_DEVID_CACHE_H */
154