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 /*
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 /*
27 * Copyright 2018 Nexenta Systems, Inc.
28 */
29
30 #ifndef _SYS_FM_PROTOCOL_H
31 #define _SYS_FM_PROTOCOL_H
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 #ifdef _KERNEL
38 #include <sys/varargs.h>
39 #include <sys/nvpair.h>
40 #else
41 #include <libnvpair.h>
42 #include <stdarg.h>
43 #endif
44 #include <sys/processor.h>
45
46 /* FM common member names */
47 #define FM_CLASS "class"
48 #define FM_VERSION "version"
49
50 /* FM protocol category 1 class names */
51 #define FM_EREPORT_CLASS "ereport"
52 #define FM_FAULT_CLASS "fault"
53 #define FM_DEFECT_CLASS "defect"
54 #define FM_RSRC_CLASS "resource"
55 #define FM_LIST_EVENT "list"
56 #define FM_IREPORT_CLASS "ireport"
57
58 /* FM list.* event class values */
59 #define FM_LIST_SUSPECT_CLASS FM_LIST_EVENT ".suspect"
60 #define FM_LIST_ISOLATED_CLASS FM_LIST_EVENT ".isolated"
61 #define FM_LIST_REPAIRED_CLASS FM_LIST_EVENT ".repaired"
62 #define FM_LIST_UPDATED_CLASS FM_LIST_EVENT ".updated"
63 #define FM_LIST_RESOLVED_CLASS FM_LIST_EVENT ".resolved"
64
65 /* ereport class subcategory values */
66 #define FM_ERROR_CPU "cpu"
67 #define FM_ERROR_IO "io"
68
69 /* ereport version and payload member names */
70 #define FM_EREPORT_VERS0 0
71 #define FM_EREPORT_VERSION FM_EREPORT_VERS0
72
73 /* ereport payload member names */
74 #define FM_EREPORT_DETECTOR "detector"
75 #define FM_EREPORT_ENA "ena"
76
77 /* list.* event payload member names */
78 #define FM_LIST_EVENT_SIZE "list-sz"
79
80 /* ireport.* event payload member names */
81 #define FM_IREPORT_DETECTOR "detector"
82 #define FM_IREPORT_UUID "uuid"
83 #define FM_IREPORT_PRIORITY "pri"
84 #define FM_IREPORT_ATTRIBUTES "attr"
85
86 /*
87 * list.suspect, isolated, updated, repaired and resolved
88 * versions/payload member names.
89 */
90 #define FM_SUSPECT_UUID "uuid"
91 #define FM_SUSPECT_DIAG_CODE "code"
92 #define FM_SUSPECT_DIAG_TIME "diag-time"
93 #define FM_SUSPECT_DE "de"
94 #define FM_SUSPECT_DESC "desc"
95 #define FM_SUSPECT_FAULT_LIST "fault-list"
96 #define FM_SUSPECT_FAULT_SZ "fault-list-sz"
97 #define FM_SUSPECT_FAULT_STATUS "fault-status"
98 #define FM_SUSPECT_INJECTED "__injected"
99 #define FM_SUSPECT_MESSAGE "message"
100 #define FM_SUSPECT_RETIRE "retire"
101 #define FM_SUSPECT_RESPONSE "response"
102 #define FM_SUSPECT_SEVERITY "severity"
103 #define FM_SUSPECT_TYPE "type"
104
105 #define FM_SUSPECT_VERS0 0
106 #define FM_SUSPECT_VERSION FM_SUSPECT_VERS0
107
108 #define FM_SUSPECT_FAULTY 0x1
109 #define FM_SUSPECT_UNUSABLE 0x2
110 #define FM_SUSPECT_NOT_PRESENT 0x4
111 #define FM_SUSPECT_DEGRADED 0x8
112 #define FM_SUSPECT_REPAIRED 0x10
113 #define FM_SUSPECT_REPLACED 0x20
114 #define FM_SUSPECT_ACQUITTED 0x40
115
116 /* fault event versions and payload member names */
117 #define FM_FAULT_VERS0 0
118 #define FM_FAULT_VERSION FM_FAULT_VERS0
119
120 #define FM_FAULT_ASRU "asru"
121 #define FM_FAULT_FRU "fru"
122 #define FM_FAULT_FRU_LABEL "fru-label"
123 #define FM_FAULT_CERTAINTY "certainty"
124 #define FM_FAULT_RESOURCE "resource"
125 #define FM_FAULT_LOCATION "location"
126
127 /* resource event versions and payload member names */
128 #define FM_RSRC_VERS0 0
129 #define FM_RSRC_VERSION FM_RSRC_VERS0
130 #define FM_RSRC_RESOURCE "resource"
131
132 /* resource.fm.asru.* payload member names */
133 #define FM_RSRC_ASRU_UUID "uuid"
134 #define FM_RSRC_ASRU_CODE "code"
135 #define FM_RSRC_ASRU_FAULTY "faulty"
136 #define FM_RSRC_ASRU_REPAIRED "repaired"
137 #define FM_RSRC_ASRU_REPLACED "replaced"
138 #define FM_RSRC_ASRU_ACQUITTED "acquitted"
139 #define FM_RSRC_ASRU_RESOLVED "resolved"
140 #define FM_RSRC_ASRU_UNUSABLE "unusable"
141 #define FM_RSRC_ASRU_EVENT "event"
142
143 /* resource.fm.xprt.* versions and payload member names */
144 #define FM_RSRC_XPRT_VERS0 0
145 #define FM_RSRC_XPRT_VERSION FM_RSRC_XPRT_VERS0
146 #define FM_RSRC_XPRT_UUID "uuid"
147 #define FM_RSRC_XPRT_SUBCLASS "subclass"
148 #define FM_RSRC_XPRT_FAULT_STATUS "fault-status"
149 #define FM_RSRC_XPRT_FAULT_HAS_ASRU "fault-has-asru"
150
151 /*
152 * FM ENA Format Macros
153 */
154 #define ENA_FORMAT_MASK 0x3
155 #define ENA_FORMAT(ena) ((ena) & ENA_FORMAT_MASK)
156
157 /* ENA format types */
158 #define FM_ENA_FMT0 0
159 #define FM_ENA_FMT1 1
160 #define FM_ENA_FMT2 2
161
162 /* Format 1 */
163 #define ENA_FMT1_GEN_MASK 0x00000000000003FCull
164 #define ENA_FMT1_ID_MASK 0xFFFFFFFFFFFFFC00ull
165 #define ENA_FMT1_CPUID_MASK 0x00000000000FFC00ull
166 #define ENA_FMT1_TIME_MASK 0xFFFFFFFFFFF00000ull
167 #define ENA_FMT1_GEN_SHFT 2
168 #define ENA_FMT1_ID_SHFT 10
169 #define ENA_FMT1_CPUID_SHFT ENA_FMT1_ID_SHFT
170 #define ENA_FMT1_TIME_SHFT 20
171
172 /* Format 2 */
173 #define ENA_FMT2_GEN_MASK 0x00000000000003FCull
174 #define ENA_FMT2_ID_MASK 0xFFFFFFFFFFFFFC00ull
175 #define ENA_FMT2_TIME_MASK ENA_FMT2_ID_MASK
176 #define ENA_FMT2_GEN_SHFT 2
177 #define ENA_FMT2_ID_SHFT 10
178 #define ENA_FMT2_TIME_SHFT ENA_FMT2_ID_SHFT
179
180 /* Common FMRI type names */
181 #define FM_FMRI_AUTHORITY "authority"
182 #define FM_FMRI_SCHEME "scheme"
183 #define FM_FMRI_SVC_AUTHORITY "svc-authority"
184 #define FM_FMRI_FACILITY "facility"
185
186 /* FMRI authority-type member names */
187 #define FM_FMRI_AUTH_CHASSIS "chassis-id"
188 #define FM_FMRI_AUTH_PRODUCT_SN "product-sn"
189 #define FM_FMRI_AUTH_PRODUCT "product-id"
190 #define FM_FMRI_AUTH_DOMAIN "domain-id"
191 #define FM_FMRI_AUTH_SERVER "server-id"
192 #define FM_FMRI_AUTH_HOST "host-id"
193
194 #define FM_AUTH_VERS0 0
195 #define FM_FMRI_AUTH_VERSION FM_AUTH_VERS0
196
197 /* scheme name values */
198 #define FM_FMRI_SCHEME_FMD "fmd"
199 #define FM_FMRI_SCHEME_DEV "dev"
200 #define FM_FMRI_SCHEME_HC "hc"
201 #define FM_FMRI_SCHEME_SVC "svc"
202 #define FM_FMRI_SCHEME_CPU "cpu"
203 #define FM_FMRI_SCHEME_MEM "mem"
204 #define FM_FMRI_SCHEME_MOD "mod"
205 #define FM_FMRI_SCHEME_PKG "pkg"
206 #define FM_FMRI_SCHEME_LEGACY "legacy-hc"
207 #define FM_FMRI_SCHEME_ZFS "zfs"
208 #define FM_FMRI_SCHEME_SW "sw"
209
210 /* Scheme versions */
211 #define FMD_SCHEME_VERSION0 0
212 #define FM_FMD_SCHEME_VERSION FMD_SCHEME_VERSION0
213 #define DEV_SCHEME_VERSION0 0
214 #define FM_DEV_SCHEME_VERSION DEV_SCHEME_VERSION0
215 #define FM_HC_VERS0 0
216 #define FM_HC_SCHEME_VERSION FM_HC_VERS0
217 #define CPU_SCHEME_VERSION0 0
218 #define CPU_SCHEME_VERSION1 1
219 #define FM_CPU_SCHEME_VERSION CPU_SCHEME_VERSION1
220 #define MEM_SCHEME_VERSION0 0
221 #define FM_MEM_SCHEME_VERSION MEM_SCHEME_VERSION0
222 #define MOD_SCHEME_VERSION0 0
223 #define FM_MOD_SCHEME_VERSION MOD_SCHEME_VERSION0
224 #define PKG_SCHEME_VERSION0 0
225 #define FM_PKG_SCHEME_VERSION PKG_SCHEME_VERSION0
226 #define LEGACY_SCHEME_VERSION0 0
227 #define FM_LEGACY_SCHEME_VERSION LEGACY_SCHEME_VERSION0
228 #define SVC_SCHEME_VERSION0 0
229 #define FM_SVC_SCHEME_VERSION SVC_SCHEME_VERSION0
230 #define ZFS_SCHEME_VERSION0 0
231 #define FM_ZFS_SCHEME_VERSION ZFS_SCHEME_VERSION0
232 #define SW_SCHEME_VERSION0 0
233 #define FM_SW_SCHEME_VERSION SW_SCHEME_VERSION0
234
235 /* hc scheme member names */
236 #define FM_FMRI_HC_SERIAL_ID "serial"
237 #define FM_FMRI_HC_PART "part"
238 #define FM_FMRI_HC_REVISION "revision"
239 #define FM_FMRI_HC_ROOT "hc-root"
240 #define FM_FMRI_HC_LIST_SZ "hc-list-sz"
241 #define FM_FMRI_HC_LIST "hc-list"
242 #define FM_FMRI_HC_SPECIFIC "hc-specific"
243
244 /* facility member names */
245 #define FM_FMRI_FACILITY_NAME "facility-name"
246 #define FM_FMRI_FACILITY_TYPE "facility-type"
247
248 /* hc-list version and member names */
249 #define FM_FMRI_HC_NAME "hc-name"
250 #define FM_FMRI_HC_ID "hc-id"
251
252 #define HC_LIST_VERSION0 0
253 #define FM_HC_LIST_VERSION HC_LIST_VERSION0
254
255 /* hc-specific member names */
256 #define FM_FMRI_HC_SPECIFIC_OFFSET "offset"
257 #define FM_FMRI_HC_SPECIFIC_PHYSADDR "physaddr"
258
259 /* fmd module scheme member names */
260 #define FM_FMRI_FMD_NAME "mod-name"
261 #define FM_FMRI_FMD_VERSION "mod-version"
262
263 /* dev scheme member names */
264 #define FM_FMRI_DEV_ID "devid"
265 #define FM_FMRI_DEV_TGTPTLUN0 "target-port-l0id"
266 #define FM_FMRI_DEV_PATH "device-path"
267
268 /* pkg scheme member names */
269 #define FM_FMRI_PKG_BASEDIR "pkg-basedir"
270 #define FM_FMRI_PKG_INST "pkg-inst"
271 #define FM_FMRI_PKG_VERSION "pkg-version"
272
273 /* svc scheme member names */
274 #define FM_FMRI_SVC_NAME "svc-name"
275 #define FM_FMRI_SVC_INSTANCE "svc-instance"
276 #define FM_FMRI_SVC_CONTRACT_ID "svc-contract-id"
277
278 /* svc-authority member names */
279 #define FM_FMRI_SVC_AUTH_SCOPE "scope"
280 #define FM_FMRI_SVC_AUTH_SYSTEM_FQN "system-fqn"
281
282 /* cpu scheme member names */
283 #define FM_FMRI_CPU_ID "cpuid"
284 #define FM_FMRI_CPU_SERIAL_ID "serial"
285 #define FM_FMRI_CPU_MASK "cpumask"
286 #define FM_FMRI_CPU_VID "cpuvid"
287 #define FM_FMRI_CPU_CPUFRU "cpufru"
288 #define FM_FMRI_CPU_CACHE_INDEX "cacheindex"
289 #define FM_FMRI_CPU_CACHE_WAY "cacheway"
290 #define FM_FMRI_CPU_CACHE_BIT "cachebit"
291 #define FM_FMRI_CPU_CACHE_TYPE "cachetype"
292
293 #define FM_FMRI_CPU_CACHE_TYPE_L2 0
294 #define FM_FMRI_CPU_CACHE_TYPE_L3 1
295
296 /* legacy-hc scheme member names */
297 #define FM_FMRI_LEGACY_HC "component"
298 #define FM_FMRI_LEGACY_HC_PREFIX FM_FMRI_SCHEME_HC":///" \
299 FM_FMRI_LEGACY_HC"="
300
301 /* mem scheme member names */
302 #define FM_FMRI_MEM_UNUM "unum"
303 #define FM_FMRI_MEM_SERIAL_ID "serial"
304 #define FM_FMRI_MEM_PHYSADDR "physaddr"
305 #define FM_FMRI_MEM_MEMCONFIG "memconfig"
306 #define FM_FMRI_MEM_OFFSET "offset"
307
308 /* mod scheme member names */
309 #define FM_FMRI_MOD_PKG "mod-pkg"
310 #define FM_FMRI_MOD_NAME "mod-name"
311 #define FM_FMRI_MOD_ID "mod-id"
312 #define FM_FMRI_MOD_DESC "mod-desc"
313
314 /* zfs scheme member names */
315 #define FM_FMRI_ZFS_POOL "pool"
316 #define FM_FMRI_ZFS_VDEV "vdev"
317
318 /* sw scheme member names - extra indentation for members of an nvlist */
319 #define FM_FMRI_SW_OBJ "object"
320 #define FM_FMRI_SW_OBJ_PATH "path"
321 #define FM_FMRI_SW_OBJ_ROOT "root"
322 #define FM_FMRI_SW_OBJ_PKG "pkg"
323 #define FM_FMRI_SW_SITE "site"
324 #define FM_FMRI_SW_SITE_TOKEN "token"
325 #define FM_FMRI_SW_SITE_MODULE "module"
326 #define FM_FMRI_SW_SITE_FILE "file"
327 #define FM_FMRI_SW_SITE_LINE "line"
328 #define FM_FMRI_SW_SITE_FUNC "func"
329 #define FM_FMRI_SW_CTXT "context"
330 #define FM_FMRI_SW_CTXT_ORIGIN "origin"
331 #define FM_FMRI_SW_CTXT_EXECNAME "execname"
332 #define FM_FMRI_SW_CTXT_PID "pid"
333 #define FM_FMRI_SW_CTXT_ZONE "zone"
334 #define FM_FMRI_SW_CTXT_CTID "ctid"
335 #define FM_FMRI_SW_CTXT_STACK "stack"
336
337 extern nv_alloc_t *fm_nva_xcreate(char *, size_t);
338 extern void fm_nva_xdestroy(nv_alloc_t *);
339
340 extern nvlist_t *fm_nvlist_create(nv_alloc_t *);
341 extern void fm_nvlist_destroy(nvlist_t *, int);
342
343 #define FM_NVA_FREE 0 /* free allocator on nvlist_destroy */
344 #define FM_NVA_RETAIN 1 /* keep allocator on nvlist_destroy */
345
346 extern void fm_ereport_set(nvlist_t *, int, const char *, uint64_t,
347 const nvlist_t *, ...);
348 extern void fm_payload_set(nvlist_t *, ...);
349 extern int i_fm_payload_set(nvlist_t *, const char *, va_list);
350 extern void fm_fmri_hc_set(nvlist_t *, int, const nvlist_t *, nvlist_t *,
351 int, ...);
352 extern void fm_fmri_dev_set(nvlist_t *, int, const nvlist_t *, const char *,
353 const char *, const char *);
354 extern void fm_fmri_de_set(nvlist_t *, int, const nvlist_t *, const char *);
355 extern void fm_fmri_cpu_set(nvlist_t *, int, const nvlist_t *, uint32_t,
356 uint8_t *, const char *);
357 extern void fm_fmri_mem_set(nvlist_t *, int, const nvlist_t *, const char *,
358 const char *, uint64_t);
359 extern void fm_authority_set(nvlist_t *, int, const char *, const char *,
360 const char *, const char *);
361 extern void fm_fmri_zfs_set(nvlist_t *, int, uint64_t, uint64_t);
362 extern void fm_fmri_hc_create(nvlist_t *, int, const nvlist_t *, nvlist_t *,
363 nvlist_t *, int, ...);
364
365 extern uint64_t fm_ena_increment(uint64_t);
366 extern uint64_t fm_ena_generate(uint64_t, uchar_t);
367 extern uint64_t fm_ena_generate_cpu(uint64_t, processorid_t, uchar_t);
368 extern uint64_t fm_ena_generation_get(uint64_t);
369 extern uchar_t fm_ena_format_get(uint64_t);
370 extern uint64_t fm_ena_id_get(uint64_t);
371 extern uint64_t fm_ena_time_get(uint64_t);
372
373 #ifdef __cplusplus
374 }
375 #endif
376
377 #endif /* _SYS_FM_PROTOCOL_H */