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