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 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 231414Scindi * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate /* 300Sstevel@tonic-gate * Fault Management Architecture (FMA) Resource and Protocol Support 310Sstevel@tonic-gate * 320Sstevel@tonic-gate * The routines contained herein provide services to support kernel subsystems 330Sstevel@tonic-gate * in publishing fault management telemetry (see PSARC 2002/412 and 2003/089). 340Sstevel@tonic-gate * 350Sstevel@tonic-gate * Name-Value Pair Lists 360Sstevel@tonic-gate * 370Sstevel@tonic-gate * The embodiment of an FMA protocol element (event, fmri or authority) is a 380Sstevel@tonic-gate * name-value pair list (nvlist_t). FMA-specific nvlist construtor and 390Sstevel@tonic-gate * destructor functions, fm_nvlist_create() and fm_nvlist_destroy(), are used 400Sstevel@tonic-gate * to create an nvpair list using custom allocators. Callers may choose to 410Sstevel@tonic-gate * allocate either from the kernel memory allocator, or from a preallocated 420Sstevel@tonic-gate * buffer, useful in constrained contexts like high-level interrupt routines. 430Sstevel@tonic-gate * 440Sstevel@tonic-gate * Protocol Event and FMRI Construction 450Sstevel@tonic-gate * 460Sstevel@tonic-gate * Convenience routines are provided to construct nvlist events according to 470Sstevel@tonic-gate * the FMA Event Protocol and Naming Schema specification for ereports and 480Sstevel@tonic-gate * FMRIs for the dev, cpu, hc, mem, legacy hc and de schemes. 490Sstevel@tonic-gate * 500Sstevel@tonic-gate * ENA Manipulation 510Sstevel@tonic-gate * 520Sstevel@tonic-gate * Routines to generate ENA formats 0, 1 and 2 are available as well as 530Sstevel@tonic-gate * routines to increment formats 1 and 2. Individual fields within the 540Sstevel@tonic-gate * ENA are extractable via fm_ena_time_get(), fm_ena_id_get(), 550Sstevel@tonic-gate * fm_ena_format_get() and fm_ena_gen_get(). 560Sstevel@tonic-gate */ 570Sstevel@tonic-gate 580Sstevel@tonic-gate #include <sys/types.h> 590Sstevel@tonic-gate #include <sys/time.h> 600Sstevel@tonic-gate #include <sys/sysevent.h> 610Sstevel@tonic-gate #include <sys/sysevent_impl.h> 620Sstevel@tonic-gate #include <sys/nvpair.h> 630Sstevel@tonic-gate #include <sys/cmn_err.h> 640Sstevel@tonic-gate #include <sys/cpuvar.h> 650Sstevel@tonic-gate #include <sys/sysmacros.h> 660Sstevel@tonic-gate #include <sys/systm.h> 670Sstevel@tonic-gate #include <sys/ddifm.h> 680Sstevel@tonic-gate #include <sys/ddifm_impl.h> 690Sstevel@tonic-gate #include <sys/spl.h> 700Sstevel@tonic-gate #include <sys/dumphdr.h> 710Sstevel@tonic-gate #include <sys/compress.h> 720Sstevel@tonic-gate #include <sys/cpuvar.h> 730Sstevel@tonic-gate #include <sys/console.h> 740Sstevel@tonic-gate #include <sys/panic.h> 751414Scindi #include <sys/kobj.h> 761414Scindi #include <sys/sunddi.h> 770Sstevel@tonic-gate #include <sys/systeminfo.h> 780Sstevel@tonic-gate #include <sys/sysevent/eventdefs.h> 790Sstevel@tonic-gate #include <sys/fm/util.h> 800Sstevel@tonic-gate #include <sys/fm/protocol.h> 810Sstevel@tonic-gate 820Sstevel@tonic-gate /* 830Sstevel@tonic-gate * URL and SUNW-MSG-ID value to display for fm_panic(), defined below. These 840Sstevel@tonic-gate * values must be kept in sync with the FMA source code in usr/src/cmd/fm. 850Sstevel@tonic-gate */ 860Sstevel@tonic-gate static const char *fm_url = "http://www.sun.com/msg"; 870Sstevel@tonic-gate static const char *fm_msgid = "SUNOS-8000-0G"; 880Sstevel@tonic-gate static char *volatile fm_panicstr = NULL; 890Sstevel@tonic-gate 900Sstevel@tonic-gate errorq_t *ereport_errorq; 910Sstevel@tonic-gate void *ereport_dumpbuf; 920Sstevel@tonic-gate size_t ereport_dumplen; 930Sstevel@tonic-gate 940Sstevel@tonic-gate static uint_t ereport_chanlen = ERPT_EVCH_MAX; 950Sstevel@tonic-gate static evchan_t *ereport_chan = NULL; 960Sstevel@tonic-gate static ulong_t ereport_qlen = 0; 970Sstevel@tonic-gate static size_t ereport_size = 0; 980Sstevel@tonic-gate static int ereport_cols = 80; 990Sstevel@tonic-gate 1000Sstevel@tonic-gate /* 1010Sstevel@tonic-gate * Common fault management kstats to record ereport generation 1020Sstevel@tonic-gate * failures 1030Sstevel@tonic-gate */ 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate struct erpt_kstat { 1060Sstevel@tonic-gate kstat_named_t erpt_dropped; /* num erpts dropped on post */ 1070Sstevel@tonic-gate kstat_named_t erpt_set_failed; /* num erpt set failures */ 1080Sstevel@tonic-gate kstat_named_t fmri_set_failed; /* num fmri set failures */ 1090Sstevel@tonic-gate kstat_named_t payload_set_failed; /* num payload set failures */ 1100Sstevel@tonic-gate }; 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate static struct erpt_kstat erpt_kstat_data = { 1130Sstevel@tonic-gate { "erpt-dropped", KSTAT_DATA_UINT64 }, 1140Sstevel@tonic-gate { "erpt-set-failed", KSTAT_DATA_UINT64 }, 1150Sstevel@tonic-gate { "fmri-set-failed", KSTAT_DATA_UINT64 }, 1160Sstevel@tonic-gate { "payload-set-failed", KSTAT_DATA_UINT64 } 1170Sstevel@tonic-gate }; 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate /*ARGSUSED*/ 1200Sstevel@tonic-gate static void 1210Sstevel@tonic-gate fm_drain(void *private, void *data, errorq_elem_t *eep) 1220Sstevel@tonic-gate { 1230Sstevel@tonic-gate nvlist_t *nvl = errorq_elem_nvl(ereport_errorq, eep); 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate if (!panicstr) 1260Sstevel@tonic-gate (void) fm_ereport_post(nvl, EVCH_TRYHARD); 1270Sstevel@tonic-gate else 1280Sstevel@tonic-gate fm_nvprint(nvl); 1290Sstevel@tonic-gate } 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate void 1320Sstevel@tonic-gate fm_init(void) 1330Sstevel@tonic-gate { 1340Sstevel@tonic-gate kstat_t *ksp; 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate (void) sysevent_evc_bind(FM_ERROR_CHAN, 1370Sstevel@tonic-gate &ereport_chan, EVCH_CREAT | EVCH_HOLD_PEND); 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate (void) sysevent_evc_control(ereport_chan, 1400Sstevel@tonic-gate EVCH_SET_CHAN_LEN, &ereport_chanlen); 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate if (ereport_qlen == 0) 1430Sstevel@tonic-gate ereport_qlen = ERPT_MAX_ERRS * MAX(max_ncpus, 4); 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate if (ereport_size == 0) 1460Sstevel@tonic-gate ereport_size = ERPT_DATA_SZ; 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate ereport_errorq = errorq_nvcreate("fm_ereport_queue", 1490Sstevel@tonic-gate (errorq_func_t)fm_drain, NULL, ereport_qlen, ereport_size, 1500Sstevel@tonic-gate FM_ERR_PIL, ERRORQ_VITAL); 1510Sstevel@tonic-gate if (ereport_errorq == NULL) 1520Sstevel@tonic-gate panic("failed to create required ereport error queue"); 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate ereport_dumpbuf = kmem_alloc(ereport_size, KM_SLEEP); 1550Sstevel@tonic-gate ereport_dumplen = ereport_size; 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate /* Initialize ereport allocation and generation kstats */ 1580Sstevel@tonic-gate ksp = kstat_create("unix", 0, "fm", "misc", KSTAT_TYPE_NAMED, 1590Sstevel@tonic-gate sizeof (struct erpt_kstat) / sizeof (kstat_named_t), 1600Sstevel@tonic-gate KSTAT_FLAG_VIRTUAL); 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate if (ksp != NULL) { 1630Sstevel@tonic-gate ksp->ks_data = &erpt_kstat_data; 1640Sstevel@tonic-gate kstat_install(ksp); 1650Sstevel@tonic-gate } else { 1660Sstevel@tonic-gate cmn_err(CE_NOTE, "failed to create fm/misc kstat\n"); 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate } 1690Sstevel@tonic-gate } 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate /* 1720Sstevel@tonic-gate * Formatting utility function for fm_nvprintr. We attempt to wrap chunks of 1730Sstevel@tonic-gate * output so they aren't split across console lines, and return the end column. 1740Sstevel@tonic-gate */ 1750Sstevel@tonic-gate /*PRINTFLIKE4*/ 1760Sstevel@tonic-gate static int 1770Sstevel@tonic-gate fm_printf(int depth, int c, int cols, const char *format, ...) 1780Sstevel@tonic-gate { 1790Sstevel@tonic-gate va_list ap; 1800Sstevel@tonic-gate int width; 1810Sstevel@tonic-gate char c1; 1820Sstevel@tonic-gate 1830Sstevel@tonic-gate va_start(ap, format); 1840Sstevel@tonic-gate width = vsnprintf(&c1, sizeof (c1), format, ap); 1850Sstevel@tonic-gate va_end(ap); 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate if (c + width >= cols) { 1880Sstevel@tonic-gate console_printf("\n\r"); 1890Sstevel@tonic-gate c = 0; 1900Sstevel@tonic-gate if (format[0] != ' ' && depth > 0) { 1910Sstevel@tonic-gate console_printf(" "); 1920Sstevel@tonic-gate c++; 1930Sstevel@tonic-gate } 1940Sstevel@tonic-gate } 1950Sstevel@tonic-gate 1960Sstevel@tonic-gate va_start(ap, format); 1970Sstevel@tonic-gate console_vprintf(format, ap); 1980Sstevel@tonic-gate va_end(ap); 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate return ((c + width) % cols); 2010Sstevel@tonic-gate } 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate /* 2040Sstevel@tonic-gate * Recursively print a nvlist in the specified column width and return the 2050Sstevel@tonic-gate * column we end up in. This function is called recursively by fm_nvprint(), 2060Sstevel@tonic-gate * below. We generically format the entire nvpair using hexadecimal 2070Sstevel@tonic-gate * integers and strings, and elide any integer arrays. Arrays are basically 2080Sstevel@tonic-gate * used for cache dumps right now, so we suppress them so as not to overwhelm 2090Sstevel@tonic-gate * the amount of console output we produce at panic time. This can be further 2100Sstevel@tonic-gate * enhanced as FMA technology grows based upon the needs of consumers. All 2110Sstevel@tonic-gate * FMA telemetry is logged using the dump device transport, so the console 2120Sstevel@tonic-gate * output serves only as a fallback in case this procedure is unsuccessful. 2130Sstevel@tonic-gate */ 2140Sstevel@tonic-gate static int 2150Sstevel@tonic-gate fm_nvprintr(nvlist_t *nvl, int d, int c, int cols) 2160Sstevel@tonic-gate { 2170Sstevel@tonic-gate nvpair_t *nvp; 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate for (nvp = nvlist_next_nvpair(nvl, NULL); 2200Sstevel@tonic-gate nvp != NULL; nvp = nvlist_next_nvpair(nvl, nvp)) { 2210Sstevel@tonic-gate 2220Sstevel@tonic-gate data_type_t type = nvpair_type(nvp); 2230Sstevel@tonic-gate const char *name = nvpair_name(nvp); 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate boolean_t b; 2260Sstevel@tonic-gate uint8_t i8; 2270Sstevel@tonic-gate uint16_t i16; 2280Sstevel@tonic-gate uint32_t i32; 2290Sstevel@tonic-gate uint64_t i64; 2300Sstevel@tonic-gate char *str; 2310Sstevel@tonic-gate nvlist_t *cnv; 2320Sstevel@tonic-gate 2330Sstevel@tonic-gate if (strcmp(name, FM_CLASS) == 0) 2340Sstevel@tonic-gate continue; /* already printed by caller */ 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate c = fm_printf(d, c, cols, " %s=", name); 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate switch (type) { 2390Sstevel@tonic-gate case DATA_TYPE_BOOLEAN: 2400Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, " 1"); 2410Sstevel@tonic-gate break; 2420Sstevel@tonic-gate 2430Sstevel@tonic-gate case DATA_TYPE_BOOLEAN_VALUE: 2440Sstevel@tonic-gate (void) nvpair_value_boolean_value(nvp, &b); 2450Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, b ? "1" : "0"); 2460Sstevel@tonic-gate break; 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate case DATA_TYPE_BYTE: 2490Sstevel@tonic-gate (void) nvpair_value_byte(nvp, &i8); 2500Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%x", i8); 2510Sstevel@tonic-gate break; 2520Sstevel@tonic-gate 2530Sstevel@tonic-gate case DATA_TYPE_INT8: 2540Sstevel@tonic-gate (void) nvpair_value_int8(nvp, (void *)&i8); 2550Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%x", i8); 2560Sstevel@tonic-gate break; 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate case DATA_TYPE_UINT8: 2590Sstevel@tonic-gate (void) nvpair_value_uint8(nvp, &i8); 2600Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%x", i8); 2610Sstevel@tonic-gate break; 2620Sstevel@tonic-gate 2630Sstevel@tonic-gate case DATA_TYPE_INT16: 2640Sstevel@tonic-gate (void) nvpair_value_int16(nvp, (void *)&i16); 2650Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%x", i16); 2660Sstevel@tonic-gate break; 2670Sstevel@tonic-gate 2680Sstevel@tonic-gate case DATA_TYPE_UINT16: 2690Sstevel@tonic-gate (void) nvpair_value_uint16(nvp, &i16); 2700Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%x", i16); 2710Sstevel@tonic-gate break; 2720Sstevel@tonic-gate 2730Sstevel@tonic-gate case DATA_TYPE_INT32: 2740Sstevel@tonic-gate (void) nvpair_value_int32(nvp, (void *)&i32); 2750Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%x", i32); 2760Sstevel@tonic-gate break; 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate case DATA_TYPE_UINT32: 2790Sstevel@tonic-gate (void) nvpair_value_uint32(nvp, &i32); 2800Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%x", i32); 2810Sstevel@tonic-gate break; 2820Sstevel@tonic-gate 2830Sstevel@tonic-gate case DATA_TYPE_INT64: 2840Sstevel@tonic-gate (void) nvpair_value_int64(nvp, (void *)&i64); 2850Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%llx", 2860Sstevel@tonic-gate (u_longlong_t)i64); 2870Sstevel@tonic-gate break; 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate case DATA_TYPE_UINT64: 2900Sstevel@tonic-gate (void) nvpair_value_uint64(nvp, &i64); 2910Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%llx", 2920Sstevel@tonic-gate (u_longlong_t)i64); 2930Sstevel@tonic-gate break; 2940Sstevel@tonic-gate 2950Sstevel@tonic-gate case DATA_TYPE_HRTIME: 2960Sstevel@tonic-gate (void) nvpair_value_hrtime(nvp, (void *)&i64); 2970Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%llx", 2980Sstevel@tonic-gate (u_longlong_t)i64); 2990Sstevel@tonic-gate break; 3000Sstevel@tonic-gate 3010Sstevel@tonic-gate case DATA_TYPE_STRING: 3020Sstevel@tonic-gate (void) nvpair_value_string(nvp, &str); 3030Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "\"%s\"", 3040Sstevel@tonic-gate str ? str : "<NULL>"); 3050Sstevel@tonic-gate break; 3060Sstevel@tonic-gate 3070Sstevel@tonic-gate case DATA_TYPE_NVLIST: 3080Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "["); 3090Sstevel@tonic-gate (void) nvpair_value_nvlist(nvp, &cnv); 3100Sstevel@tonic-gate c = fm_nvprintr(cnv, d + 1, c, cols); 3110Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, " ]"); 3120Sstevel@tonic-gate break; 3130Sstevel@tonic-gate 3140Sstevel@tonic-gate case DATA_TYPE_BOOLEAN_ARRAY: 3150Sstevel@tonic-gate case DATA_TYPE_BYTE_ARRAY: 3160Sstevel@tonic-gate case DATA_TYPE_INT8_ARRAY: 3170Sstevel@tonic-gate case DATA_TYPE_UINT8_ARRAY: 3180Sstevel@tonic-gate case DATA_TYPE_INT16_ARRAY: 3190Sstevel@tonic-gate case DATA_TYPE_UINT16_ARRAY: 3200Sstevel@tonic-gate case DATA_TYPE_INT32_ARRAY: 3210Sstevel@tonic-gate case DATA_TYPE_UINT32_ARRAY: 3220Sstevel@tonic-gate case DATA_TYPE_INT64_ARRAY: 3230Sstevel@tonic-gate case DATA_TYPE_UINT64_ARRAY: 3240Sstevel@tonic-gate case DATA_TYPE_STRING_ARRAY: 3250Sstevel@tonic-gate case DATA_TYPE_NVLIST_ARRAY: 3260Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "[...]"); 3270Sstevel@tonic-gate break; 3280Sstevel@tonic-gate case DATA_TYPE_UNKNOWN: 3290Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "<unknown>"); 3300Sstevel@tonic-gate break; 3310Sstevel@tonic-gate } 3320Sstevel@tonic-gate } 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate return (c); 3350Sstevel@tonic-gate } 3360Sstevel@tonic-gate 3370Sstevel@tonic-gate void 3380Sstevel@tonic-gate fm_nvprint(nvlist_t *nvl) 3390Sstevel@tonic-gate { 3400Sstevel@tonic-gate char *class; 3410Sstevel@tonic-gate int c = 0; 3420Sstevel@tonic-gate 3430Sstevel@tonic-gate console_printf("\r"); 3440Sstevel@tonic-gate 3450Sstevel@tonic-gate if (nvlist_lookup_string(nvl, FM_CLASS, &class) == 0) 3460Sstevel@tonic-gate c = fm_printf(0, c, ereport_cols, "%s", class); 3470Sstevel@tonic-gate 3480Sstevel@tonic-gate if (fm_nvprintr(nvl, 0, c, ereport_cols) != 0) 3490Sstevel@tonic-gate console_printf("\n"); 3500Sstevel@tonic-gate 3510Sstevel@tonic-gate console_printf("\n"); 3520Sstevel@tonic-gate } 3530Sstevel@tonic-gate 3540Sstevel@tonic-gate /* 3550Sstevel@tonic-gate * Wrapper for panic() that first produces an FMA-style message for admins. 3560Sstevel@tonic-gate * Normally such messages are generated by fmd(1M)'s syslog-msgs agent: this 3570Sstevel@tonic-gate * is the one exception to that rule and the only error that gets messaged. 3580Sstevel@tonic-gate * This function is intended for use by subsystems that have detected a fatal 3590Sstevel@tonic-gate * error and enqueued appropriate ereports and wish to then force a panic. 3600Sstevel@tonic-gate */ 3610Sstevel@tonic-gate /*PRINTFLIKE1*/ 3620Sstevel@tonic-gate void 3630Sstevel@tonic-gate fm_panic(const char *format, ...) 3640Sstevel@tonic-gate { 3650Sstevel@tonic-gate va_list ap; 3660Sstevel@tonic-gate 3670Sstevel@tonic-gate (void) casptr((void *)&fm_panicstr, NULL, (void *)format); 3680Sstevel@tonic-gate va_start(ap, format); 3690Sstevel@tonic-gate vpanic(format, ap); 3700Sstevel@tonic-gate va_end(ap); 3710Sstevel@tonic-gate } 3720Sstevel@tonic-gate 3730Sstevel@tonic-gate /* 3740Sstevel@tonic-gate * Print any appropriate FMA banner message before the panic message. This 3750Sstevel@tonic-gate * function is called by panicsys() and prints the message for fm_panic(). 3760Sstevel@tonic-gate * We print the message here so that it comes after the system is quiesced. 3770Sstevel@tonic-gate * A one-line summary is recorded in the log only (cmn_err(9F) with "!" prefix). 3780Sstevel@tonic-gate * The rest of the message is for the console only and not needed in the log, 3790Sstevel@tonic-gate * so it is printed using console_printf(). We break it up into multiple 3800Sstevel@tonic-gate * chunks so as to avoid overflowing any small legacy prom_printf() buffers. 3810Sstevel@tonic-gate */ 3820Sstevel@tonic-gate void 3830Sstevel@tonic-gate fm_banner(void) 3840Sstevel@tonic-gate { 3850Sstevel@tonic-gate timespec_t tod; 3860Sstevel@tonic-gate hrtime_t now; 3870Sstevel@tonic-gate 3880Sstevel@tonic-gate if (!fm_panicstr) 3890Sstevel@tonic-gate return; /* panic was not initiated by fm_panic(); do nothing */ 3900Sstevel@tonic-gate 3910Sstevel@tonic-gate if (panicstr) { 3920Sstevel@tonic-gate tod = panic_hrestime; 3930Sstevel@tonic-gate now = panic_hrtime; 3940Sstevel@tonic-gate } else { 3950Sstevel@tonic-gate gethrestime(&tod); 3960Sstevel@tonic-gate now = gethrtime_waitfree(); 3970Sstevel@tonic-gate } 3980Sstevel@tonic-gate 3990Sstevel@tonic-gate cmn_err(CE_NOTE, "!SUNW-MSG-ID: %s, " 4000Sstevel@tonic-gate "TYPE: Error, VER: 1, SEVERITY: Major\n", fm_msgid); 4010Sstevel@tonic-gate 4020Sstevel@tonic-gate console_printf( 4030Sstevel@tonic-gate "\n\rSUNW-MSG-ID: %s, TYPE: Error, VER: 1, SEVERITY: Major\n" 4040Sstevel@tonic-gate "EVENT-TIME: 0x%lx.0x%lx (0x%llx)\n", 4050Sstevel@tonic-gate fm_msgid, tod.tv_sec, tod.tv_nsec, (u_longlong_t)now); 4060Sstevel@tonic-gate 4070Sstevel@tonic-gate console_printf( 4080Sstevel@tonic-gate "PLATFORM: %s, CSN: -, HOSTNAME: %s\n" 4090Sstevel@tonic-gate "SOURCE: %s, REV: %s %s\n", 4100Sstevel@tonic-gate platform, utsname.nodename, utsname.sysname, 4110Sstevel@tonic-gate utsname.release, utsname.version); 4120Sstevel@tonic-gate 4130Sstevel@tonic-gate console_printf( 4140Sstevel@tonic-gate "DESC: Errors have been detected that require a reboot to ensure system\n" 4150Sstevel@tonic-gate "integrity. See %s/%s for more information.\n", 4160Sstevel@tonic-gate fm_url, fm_msgid); 4170Sstevel@tonic-gate 4180Sstevel@tonic-gate console_printf( 4190Sstevel@tonic-gate "AUTO-RESPONSE: Solaris will attempt to save and diagnose the error telemetry\n" 4200Sstevel@tonic-gate "IMPACT: The system will sync files, save a crash dump if needed, and reboot\n" 4210Sstevel@tonic-gate "REC-ACTION: Save the error summary below in case telemetry cannot be saved\n"); 4220Sstevel@tonic-gate 4230Sstevel@tonic-gate console_printf("\n"); 4240Sstevel@tonic-gate } 4250Sstevel@tonic-gate 4260Sstevel@tonic-gate /* 4270Sstevel@tonic-gate * Utility function to write all of the pending ereports to the dump device. 4280Sstevel@tonic-gate * This function is called at either normal reboot or panic time, and simply 4290Sstevel@tonic-gate * iterates over the in-transit messages in the ereport sysevent channel. 4300Sstevel@tonic-gate */ 4310Sstevel@tonic-gate void 4320Sstevel@tonic-gate fm_ereport_dump(void) 4330Sstevel@tonic-gate { 4340Sstevel@tonic-gate evchanq_t *chq; 4350Sstevel@tonic-gate sysevent_t *sep; 4360Sstevel@tonic-gate erpt_dump_t ed; 4370Sstevel@tonic-gate 4380Sstevel@tonic-gate timespec_t tod; 4390Sstevel@tonic-gate hrtime_t now; 4400Sstevel@tonic-gate char *buf; 4410Sstevel@tonic-gate size_t len; 4420Sstevel@tonic-gate 4430Sstevel@tonic-gate if (panicstr) { 4440Sstevel@tonic-gate tod = panic_hrestime; 4450Sstevel@tonic-gate now = panic_hrtime; 4460Sstevel@tonic-gate } else { 4470Sstevel@tonic-gate if (ereport_errorq != NULL) 4480Sstevel@tonic-gate errorq_drain(ereport_errorq); 4490Sstevel@tonic-gate gethrestime(&tod); 4500Sstevel@tonic-gate now = gethrtime_waitfree(); 4510Sstevel@tonic-gate } 4520Sstevel@tonic-gate 4530Sstevel@tonic-gate /* 4540Sstevel@tonic-gate * In the panic case, sysevent_evc_walk_init() will return NULL. 4550Sstevel@tonic-gate */ 4560Sstevel@tonic-gate if ((chq = sysevent_evc_walk_init(ereport_chan, NULL)) == NULL && 4570Sstevel@tonic-gate !panicstr) 4580Sstevel@tonic-gate return; /* event channel isn't initialized yet */ 4590Sstevel@tonic-gate 4600Sstevel@tonic-gate while ((sep = sysevent_evc_walk_step(chq)) != NULL) { 4610Sstevel@tonic-gate if ((buf = sysevent_evc_event_attr(sep, &len)) == NULL) 4620Sstevel@tonic-gate break; 4630Sstevel@tonic-gate 4640Sstevel@tonic-gate ed.ed_magic = ERPT_MAGIC; 4650Sstevel@tonic-gate ed.ed_chksum = checksum32(buf, len); 4660Sstevel@tonic-gate ed.ed_size = (uint32_t)len; 4670Sstevel@tonic-gate ed.ed_pad = 0; 4680Sstevel@tonic-gate ed.ed_hrt_nsec = SE_TIME(sep); 4690Sstevel@tonic-gate ed.ed_hrt_base = now; 4700Sstevel@tonic-gate ed.ed_tod_base.sec = tod.tv_sec; 4710Sstevel@tonic-gate ed.ed_tod_base.nsec = tod.tv_nsec; 4720Sstevel@tonic-gate 4730Sstevel@tonic-gate dumpvp_write(&ed, sizeof (ed)); 4740Sstevel@tonic-gate dumpvp_write(buf, len); 4750Sstevel@tonic-gate } 4760Sstevel@tonic-gate 4770Sstevel@tonic-gate sysevent_evc_walk_fini(chq); 4780Sstevel@tonic-gate } 4790Sstevel@tonic-gate 4800Sstevel@tonic-gate /* 4810Sstevel@tonic-gate * Post an error report (ereport) to the sysevent error channel. The error 4820Sstevel@tonic-gate * channel must be established with a prior call to sysevent_evc_create() 4830Sstevel@tonic-gate * before publication may occur. 4840Sstevel@tonic-gate */ 4850Sstevel@tonic-gate void 4860Sstevel@tonic-gate fm_ereport_post(nvlist_t *ereport, int evc_flag) 4870Sstevel@tonic-gate { 4880Sstevel@tonic-gate size_t nvl_size = 0; 4890Sstevel@tonic-gate evchan_t *error_chan; 4900Sstevel@tonic-gate 4910Sstevel@tonic-gate (void) nvlist_size(ereport, &nvl_size, NV_ENCODE_NATIVE); 4920Sstevel@tonic-gate if (nvl_size > ERPT_DATA_SZ || nvl_size == 0) { 4930Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.erpt_dropped.value.ui64, 1); 4940Sstevel@tonic-gate return; 4950Sstevel@tonic-gate } 4960Sstevel@tonic-gate 4970Sstevel@tonic-gate if (sysevent_evc_bind(FM_ERROR_CHAN, &error_chan, 4980Sstevel@tonic-gate EVCH_CREAT|EVCH_HOLD_PEND) != 0) { 4990Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.erpt_dropped.value.ui64, 1); 5000Sstevel@tonic-gate return; 5010Sstevel@tonic-gate } 5020Sstevel@tonic-gate 5030Sstevel@tonic-gate if (sysevent_evc_publish(error_chan, EC_FM, ESC_FM_ERROR, 5040Sstevel@tonic-gate SUNW_VENDOR, FM_PUB, ereport, evc_flag) != 0) { 5050Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.erpt_dropped.value.ui64, 1); 5060Sstevel@tonic-gate sysevent_evc_unbind(error_chan); 5070Sstevel@tonic-gate return; 5080Sstevel@tonic-gate } 5090Sstevel@tonic-gate sysevent_evc_unbind(error_chan); 5100Sstevel@tonic-gate } 5110Sstevel@tonic-gate 5120Sstevel@tonic-gate /* 5130Sstevel@tonic-gate * Wrapppers for FM nvlist allocators 5140Sstevel@tonic-gate */ 5150Sstevel@tonic-gate /* ARGSUSED */ 5160Sstevel@tonic-gate static void * 5170Sstevel@tonic-gate i_fm_alloc(nv_alloc_t *nva, size_t size) 5180Sstevel@tonic-gate { 5190Sstevel@tonic-gate return (kmem_zalloc(size, KM_SLEEP)); 5200Sstevel@tonic-gate } 5210Sstevel@tonic-gate 5220Sstevel@tonic-gate /* ARGSUSED */ 5230Sstevel@tonic-gate static void 5240Sstevel@tonic-gate i_fm_free(nv_alloc_t *nva, void *buf, size_t size) 5250Sstevel@tonic-gate { 5260Sstevel@tonic-gate kmem_free(buf, size); 5270Sstevel@tonic-gate } 5280Sstevel@tonic-gate 5290Sstevel@tonic-gate const nv_alloc_ops_t fm_mem_alloc_ops = { 5300Sstevel@tonic-gate NULL, 5310Sstevel@tonic-gate NULL, 5320Sstevel@tonic-gate i_fm_alloc, 5330Sstevel@tonic-gate i_fm_free, 5340Sstevel@tonic-gate NULL 5350Sstevel@tonic-gate }; 5360Sstevel@tonic-gate 5370Sstevel@tonic-gate /* 5380Sstevel@tonic-gate * Create and initialize a new nv_alloc_t for a fixed buffer, buf. A pointer 5390Sstevel@tonic-gate * to the newly allocated nv_alloc_t structure is returned upon success or NULL 5400Sstevel@tonic-gate * is returned to indicate that the nv_alloc structure could not be created. 5410Sstevel@tonic-gate */ 5420Sstevel@tonic-gate nv_alloc_t * 5430Sstevel@tonic-gate fm_nva_xcreate(char *buf, size_t bufsz) 5440Sstevel@tonic-gate { 5450Sstevel@tonic-gate nv_alloc_t *nvhdl = kmem_zalloc(sizeof (nv_alloc_t), KM_SLEEP); 5460Sstevel@tonic-gate 5470Sstevel@tonic-gate if (bufsz == 0 || nv_alloc_init(nvhdl, nv_fixed_ops, buf, bufsz) != 0) { 5480Sstevel@tonic-gate kmem_free(nvhdl, sizeof (nv_alloc_t)); 5490Sstevel@tonic-gate return (NULL); 5500Sstevel@tonic-gate } 5510Sstevel@tonic-gate 5520Sstevel@tonic-gate return (nvhdl); 5530Sstevel@tonic-gate } 5540Sstevel@tonic-gate 5550Sstevel@tonic-gate /* 5560Sstevel@tonic-gate * Destroy a previously allocated nv_alloc structure. The fixed buffer 5570Sstevel@tonic-gate * associated with nva must be freed by the caller. 5580Sstevel@tonic-gate */ 5590Sstevel@tonic-gate void 5600Sstevel@tonic-gate fm_nva_xdestroy(nv_alloc_t *nva) 5610Sstevel@tonic-gate { 5620Sstevel@tonic-gate nv_alloc_fini(nva); 5630Sstevel@tonic-gate kmem_free(nva, sizeof (nv_alloc_t)); 5640Sstevel@tonic-gate } 5650Sstevel@tonic-gate 5660Sstevel@tonic-gate /* 5670Sstevel@tonic-gate * Create a new nv list. A pointer to a new nv list structure is returned 5680Sstevel@tonic-gate * upon success or NULL is returned to indicate that the structure could 5690Sstevel@tonic-gate * not be created. The newly created nv list is created and managed by the 5700Sstevel@tonic-gate * operations installed in nva. If nva is NULL, the default FMA nva 5710Sstevel@tonic-gate * operations are installed and used. 5720Sstevel@tonic-gate * 5730Sstevel@tonic-gate * When called from the kernel and nva == NULL, this function must be called 5740Sstevel@tonic-gate * from passive kernel context with no locks held that can prevent a 5750Sstevel@tonic-gate * sleeping memory allocation from occurring. Otherwise, this function may 5760Sstevel@tonic-gate * be called from other kernel contexts as long a valid nva created via 5770Sstevel@tonic-gate * fm_nva_create() is supplied. 5780Sstevel@tonic-gate */ 5790Sstevel@tonic-gate nvlist_t * 5800Sstevel@tonic-gate fm_nvlist_create(nv_alloc_t *nva) 5810Sstevel@tonic-gate { 5820Sstevel@tonic-gate int hdl_alloced = 0; 5830Sstevel@tonic-gate nvlist_t *nvl; 5840Sstevel@tonic-gate nv_alloc_t *nvhdl; 5850Sstevel@tonic-gate 5860Sstevel@tonic-gate if (nva == NULL) { 5870Sstevel@tonic-gate nvhdl = kmem_zalloc(sizeof (nv_alloc_t), KM_SLEEP); 5880Sstevel@tonic-gate 5890Sstevel@tonic-gate if (nv_alloc_init(nvhdl, &fm_mem_alloc_ops, NULL, 0) != 0) { 5900Sstevel@tonic-gate kmem_free(nvhdl, sizeof (nv_alloc_t)); 5910Sstevel@tonic-gate return (NULL); 5920Sstevel@tonic-gate } 5930Sstevel@tonic-gate hdl_alloced = 1; 5940Sstevel@tonic-gate } else { 5950Sstevel@tonic-gate nvhdl = nva; 5960Sstevel@tonic-gate } 5970Sstevel@tonic-gate 5980Sstevel@tonic-gate if (nvlist_xalloc(&nvl, NV_UNIQUE_NAME, nvhdl) != 0) { 5990Sstevel@tonic-gate if (hdl_alloced) { 6000Sstevel@tonic-gate kmem_free(nvhdl, sizeof (nv_alloc_t)); 6010Sstevel@tonic-gate nv_alloc_fini(nvhdl); 6020Sstevel@tonic-gate } 6030Sstevel@tonic-gate return (NULL); 6040Sstevel@tonic-gate } 6050Sstevel@tonic-gate 6060Sstevel@tonic-gate return (nvl); 6070Sstevel@tonic-gate } 6080Sstevel@tonic-gate 6090Sstevel@tonic-gate /* 6100Sstevel@tonic-gate * Destroy a previously allocated nvlist structure. flag indicates whether 6110Sstevel@tonic-gate * or not the associated nva structure should be freed (FM_NVA_FREE) or 6120Sstevel@tonic-gate * retained (FM_NVA_RETAIN). Retaining the nv alloc structure allows 6130Sstevel@tonic-gate * it to be re-used for future nvlist creation operations. 6140Sstevel@tonic-gate */ 6150Sstevel@tonic-gate void 6160Sstevel@tonic-gate fm_nvlist_destroy(nvlist_t *nvl, int flag) 6170Sstevel@tonic-gate { 6181414Scindi nv_alloc_t *nva = nvlist_lookup_nv_alloc(nvl); 6190Sstevel@tonic-gate 6200Sstevel@tonic-gate nvlist_free(nvl); 6210Sstevel@tonic-gate 6221414Scindi if (nva != NULL) { 6230Sstevel@tonic-gate if (flag == FM_NVA_FREE) 6241414Scindi fm_nva_xdestroy(nva); 6250Sstevel@tonic-gate } 6260Sstevel@tonic-gate } 6270Sstevel@tonic-gate 6280Sstevel@tonic-gate int 6290Sstevel@tonic-gate i_fm_payload_set(nvlist_t *payload, const char *name, va_list ap) 6300Sstevel@tonic-gate { 6310Sstevel@tonic-gate int nelem, ret = 0; 6320Sstevel@tonic-gate data_type_t type; 6330Sstevel@tonic-gate 6340Sstevel@tonic-gate while (ret == 0 && name != NULL) { 6350Sstevel@tonic-gate type = va_arg(ap, data_type_t); 6360Sstevel@tonic-gate switch (type) { 6370Sstevel@tonic-gate case DATA_TYPE_BYTE: 6380Sstevel@tonic-gate ret = nvlist_add_byte(payload, name, 6390Sstevel@tonic-gate va_arg(ap, uint_t)); 6400Sstevel@tonic-gate break; 6410Sstevel@tonic-gate case DATA_TYPE_BYTE_ARRAY: 6420Sstevel@tonic-gate nelem = va_arg(ap, int); 6430Sstevel@tonic-gate ret = nvlist_add_byte_array(payload, name, 6440Sstevel@tonic-gate va_arg(ap, uchar_t *), nelem); 6450Sstevel@tonic-gate break; 6460Sstevel@tonic-gate case DATA_TYPE_BOOLEAN_VALUE: 6470Sstevel@tonic-gate ret = nvlist_add_boolean_value(payload, name, 6480Sstevel@tonic-gate va_arg(ap, boolean_t)); 6490Sstevel@tonic-gate break; 6500Sstevel@tonic-gate case DATA_TYPE_BOOLEAN_ARRAY: 6510Sstevel@tonic-gate nelem = va_arg(ap, int); 6520Sstevel@tonic-gate ret = nvlist_add_boolean_array(payload, name, 6530Sstevel@tonic-gate va_arg(ap, boolean_t *), nelem); 6540Sstevel@tonic-gate break; 6550Sstevel@tonic-gate case DATA_TYPE_INT8: 6560Sstevel@tonic-gate ret = nvlist_add_int8(payload, name, 6570Sstevel@tonic-gate va_arg(ap, int)); 6580Sstevel@tonic-gate break; 6590Sstevel@tonic-gate case DATA_TYPE_INT8_ARRAY: 6600Sstevel@tonic-gate nelem = va_arg(ap, int); 6610Sstevel@tonic-gate ret = nvlist_add_int8_array(payload, name, 6620Sstevel@tonic-gate va_arg(ap, int8_t *), nelem); 6630Sstevel@tonic-gate break; 6640Sstevel@tonic-gate case DATA_TYPE_UINT8: 6650Sstevel@tonic-gate ret = nvlist_add_uint8(payload, name, 6660Sstevel@tonic-gate va_arg(ap, uint_t)); 6670Sstevel@tonic-gate break; 6680Sstevel@tonic-gate case DATA_TYPE_UINT8_ARRAY: 6690Sstevel@tonic-gate nelem = va_arg(ap, int); 6700Sstevel@tonic-gate ret = nvlist_add_uint8_array(payload, name, 6710Sstevel@tonic-gate va_arg(ap, uint8_t *), nelem); 6720Sstevel@tonic-gate break; 6730Sstevel@tonic-gate case DATA_TYPE_INT16: 6740Sstevel@tonic-gate ret = nvlist_add_int16(payload, name, 6750Sstevel@tonic-gate va_arg(ap, int)); 6760Sstevel@tonic-gate break; 6770Sstevel@tonic-gate case DATA_TYPE_INT16_ARRAY: 6780Sstevel@tonic-gate nelem = va_arg(ap, int); 6790Sstevel@tonic-gate ret = nvlist_add_int16_array(payload, name, 6800Sstevel@tonic-gate va_arg(ap, int16_t *), nelem); 6810Sstevel@tonic-gate break; 6820Sstevel@tonic-gate case DATA_TYPE_UINT16: 6830Sstevel@tonic-gate ret = nvlist_add_uint16(payload, name, 6840Sstevel@tonic-gate va_arg(ap, uint_t)); 6850Sstevel@tonic-gate break; 6860Sstevel@tonic-gate case DATA_TYPE_UINT16_ARRAY: 6870Sstevel@tonic-gate nelem = va_arg(ap, int); 6880Sstevel@tonic-gate ret = nvlist_add_uint16_array(payload, name, 6890Sstevel@tonic-gate va_arg(ap, uint16_t *), nelem); 6900Sstevel@tonic-gate break; 6910Sstevel@tonic-gate case DATA_TYPE_INT32: 6920Sstevel@tonic-gate ret = nvlist_add_int32(payload, name, 6930Sstevel@tonic-gate va_arg(ap, int32_t)); 6940Sstevel@tonic-gate break; 6950Sstevel@tonic-gate case DATA_TYPE_INT32_ARRAY: 6960Sstevel@tonic-gate nelem = va_arg(ap, int); 6970Sstevel@tonic-gate ret = nvlist_add_int32_array(payload, name, 6980Sstevel@tonic-gate va_arg(ap, int32_t *), nelem); 6990Sstevel@tonic-gate break; 7000Sstevel@tonic-gate case DATA_TYPE_UINT32: 7010Sstevel@tonic-gate ret = nvlist_add_uint32(payload, name, 7020Sstevel@tonic-gate va_arg(ap, uint32_t)); 7030Sstevel@tonic-gate break; 7040Sstevel@tonic-gate case DATA_TYPE_UINT32_ARRAY: 7050Sstevel@tonic-gate nelem = va_arg(ap, int); 7060Sstevel@tonic-gate ret = nvlist_add_uint32_array(payload, name, 7070Sstevel@tonic-gate va_arg(ap, uint32_t *), nelem); 7080Sstevel@tonic-gate break; 7090Sstevel@tonic-gate case DATA_TYPE_INT64: 7100Sstevel@tonic-gate ret = nvlist_add_int64(payload, name, 7110Sstevel@tonic-gate va_arg(ap, int64_t)); 7120Sstevel@tonic-gate break; 7130Sstevel@tonic-gate case DATA_TYPE_INT64_ARRAY: 7140Sstevel@tonic-gate nelem = va_arg(ap, int); 7150Sstevel@tonic-gate ret = nvlist_add_int64_array(payload, name, 7160Sstevel@tonic-gate va_arg(ap, int64_t *), nelem); 7170Sstevel@tonic-gate break; 7180Sstevel@tonic-gate case DATA_TYPE_UINT64: 7190Sstevel@tonic-gate ret = nvlist_add_uint64(payload, name, 7200Sstevel@tonic-gate va_arg(ap, uint64_t)); 7210Sstevel@tonic-gate break; 7220Sstevel@tonic-gate case DATA_TYPE_UINT64_ARRAY: 7230Sstevel@tonic-gate nelem = va_arg(ap, int); 7240Sstevel@tonic-gate ret = nvlist_add_uint64_array(payload, name, 7250Sstevel@tonic-gate va_arg(ap, uint64_t *), nelem); 7260Sstevel@tonic-gate break; 7270Sstevel@tonic-gate case DATA_TYPE_STRING: 7280Sstevel@tonic-gate ret = nvlist_add_string(payload, name, 7290Sstevel@tonic-gate va_arg(ap, char *)); 7300Sstevel@tonic-gate break; 7310Sstevel@tonic-gate case DATA_TYPE_STRING_ARRAY: 7320Sstevel@tonic-gate nelem = va_arg(ap, int); 7330Sstevel@tonic-gate ret = nvlist_add_string_array(payload, name, 7340Sstevel@tonic-gate va_arg(ap, char **), nelem); 7350Sstevel@tonic-gate break; 7360Sstevel@tonic-gate case DATA_TYPE_NVLIST: 7370Sstevel@tonic-gate ret = nvlist_add_nvlist(payload, name, 7380Sstevel@tonic-gate va_arg(ap, nvlist_t *)); 7390Sstevel@tonic-gate break; 7400Sstevel@tonic-gate case DATA_TYPE_NVLIST_ARRAY: 7410Sstevel@tonic-gate nelem = va_arg(ap, int); 7420Sstevel@tonic-gate ret = nvlist_add_nvlist_array(payload, name, 7430Sstevel@tonic-gate va_arg(ap, nvlist_t **), nelem); 7440Sstevel@tonic-gate break; 7450Sstevel@tonic-gate default: 7460Sstevel@tonic-gate ret = EINVAL; 7470Sstevel@tonic-gate } 7480Sstevel@tonic-gate 7490Sstevel@tonic-gate name = va_arg(ap, char *); 7500Sstevel@tonic-gate } 7510Sstevel@tonic-gate return (ret); 7520Sstevel@tonic-gate } 7530Sstevel@tonic-gate 7540Sstevel@tonic-gate void 7550Sstevel@tonic-gate fm_payload_set(nvlist_t *payload, ...) 7560Sstevel@tonic-gate { 7570Sstevel@tonic-gate int ret; 7580Sstevel@tonic-gate const char *name; 7590Sstevel@tonic-gate va_list ap; 7600Sstevel@tonic-gate 7610Sstevel@tonic-gate va_start(ap, payload); 7620Sstevel@tonic-gate name = va_arg(ap, char *); 7630Sstevel@tonic-gate ret = i_fm_payload_set(payload, name, ap); 7640Sstevel@tonic-gate va_end(ap); 7650Sstevel@tonic-gate 7660Sstevel@tonic-gate if (ret) 7670Sstevel@tonic-gate atomic_add_64( 7680Sstevel@tonic-gate &erpt_kstat_data.payload_set_failed.value.ui64, 1); 7690Sstevel@tonic-gate } 7700Sstevel@tonic-gate 7710Sstevel@tonic-gate /* 7720Sstevel@tonic-gate * Set-up and validate the members of an ereport event according to: 7730Sstevel@tonic-gate * 7740Sstevel@tonic-gate * Member name Type Value 7750Sstevel@tonic-gate * ==================================================== 7760Sstevel@tonic-gate * class string ereport 7770Sstevel@tonic-gate * version uint8_t 0 7780Sstevel@tonic-gate * ena uint64_t <ena> 7790Sstevel@tonic-gate * detector nvlist_t <detector> 7800Sstevel@tonic-gate * ereport-payload nvlist_t <var args> 7810Sstevel@tonic-gate * 7820Sstevel@tonic-gate */ 7830Sstevel@tonic-gate void 7840Sstevel@tonic-gate fm_ereport_set(nvlist_t *ereport, int version, const char *erpt_class, 7850Sstevel@tonic-gate uint64_t ena, const nvlist_t *detector, ...) 7860Sstevel@tonic-gate { 7870Sstevel@tonic-gate char ereport_class[FM_MAX_CLASS]; 7880Sstevel@tonic-gate const char *name; 7890Sstevel@tonic-gate va_list ap; 7900Sstevel@tonic-gate int ret; 7910Sstevel@tonic-gate 7920Sstevel@tonic-gate if (version != FM_EREPORT_VERS0) { 7930Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1); 7940Sstevel@tonic-gate return; 7950Sstevel@tonic-gate } 7960Sstevel@tonic-gate 7970Sstevel@tonic-gate (void) snprintf(ereport_class, FM_MAX_CLASS, "%s.%s", 7980Sstevel@tonic-gate FM_EREPORT_CLASS, erpt_class); 7990Sstevel@tonic-gate if (nvlist_add_string(ereport, FM_CLASS, ereport_class) != 0) { 8000Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1); 8010Sstevel@tonic-gate return; 8020Sstevel@tonic-gate } 8030Sstevel@tonic-gate 8040Sstevel@tonic-gate if (nvlist_add_uint64(ereport, FM_EREPORT_ENA, ena)) { 8050Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1); 8060Sstevel@tonic-gate } 8070Sstevel@tonic-gate 8080Sstevel@tonic-gate if (nvlist_add_nvlist(ereport, FM_EREPORT_DETECTOR, 8090Sstevel@tonic-gate (nvlist_t *)detector) != 0) { 8100Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1); 8110Sstevel@tonic-gate } 8120Sstevel@tonic-gate 8130Sstevel@tonic-gate va_start(ap, detector); 8140Sstevel@tonic-gate name = va_arg(ap, const char *); 8150Sstevel@tonic-gate ret = i_fm_payload_set(ereport, name, ap); 8160Sstevel@tonic-gate va_end(ap); 8170Sstevel@tonic-gate 8180Sstevel@tonic-gate if (ret) 8190Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1); 8200Sstevel@tonic-gate } 8210Sstevel@tonic-gate 8221414Scindi /* 8231414Scindi * Set-up and validate the members of an hc fmri according to; 8241414Scindi * 8251414Scindi * Member name Type Value 8261414Scindi * =================================================== 8271414Scindi * version uint8_t 0 8281414Scindi * auth nvlist_t <auth> 8291414Scindi * hc-name string <name> 8301414Scindi * hc-id string <id> 8311414Scindi * 8321414Scindi * Note that auth and hc-id are optional members. 8331414Scindi */ 8340Sstevel@tonic-gate 8351414Scindi #define HC_MAXPAIRS 20 8361414Scindi #define HC_MAXNAMELEN 50 8370Sstevel@tonic-gate 8381414Scindi static int 8391414Scindi fm_fmri_hc_set_common(nvlist_t *fmri, int version, const nvlist_t *auth) 8401414Scindi { 8411414Scindi if (version != FM_HC_SCHEME_VERSION) { 8421414Scindi atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 8431414Scindi return (0); 8441414Scindi } 8451414Scindi 8461414Scindi if (nvlist_add_uint8(fmri, FM_VERSION, version) != 0 || 8471414Scindi nvlist_add_string(fmri, FM_FMRI_SCHEME, FM_FMRI_SCHEME_HC) != 0) { 8481414Scindi atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 8491414Scindi return (0); 8501414Scindi } 8511414Scindi 8521414Scindi if (auth != NULL && nvlist_add_nvlist(fmri, FM_FMRI_AUTHORITY, 8531414Scindi (nvlist_t *)auth) != 0) { 8541414Scindi atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 8551414Scindi return (0); 8560Sstevel@tonic-gate } 8570Sstevel@tonic-gate 8581414Scindi return (1); 8591414Scindi } 8600Sstevel@tonic-gate 8611414Scindi void 8621414Scindi fm_fmri_hc_set(nvlist_t *fmri, int version, const nvlist_t *auth, 8631414Scindi nvlist_t *snvl, int npairs, ...) 8641414Scindi { 8651414Scindi nv_alloc_t *nva = nvlist_lookup_nv_alloc(fmri); 8661414Scindi nvlist_t *pairs[HC_MAXPAIRS]; 8671414Scindi va_list ap; 8681414Scindi int i; 8691414Scindi 8701414Scindi if (!fm_fmri_hc_set_common(fmri, version, auth)) 8711414Scindi return; 8721414Scindi 8731414Scindi npairs = MIN(npairs, HC_MAXPAIRS); 8741414Scindi 8751414Scindi va_start(ap, npairs); 8761414Scindi for (i = 0; i < npairs; i++) { 8771414Scindi const char *name = va_arg(ap, const char *); 8781414Scindi uint32_t id = va_arg(ap, uint32_t); 8791414Scindi char idstr[11]; 8800Sstevel@tonic-gate 8811414Scindi (void) snprintf(idstr, sizeof (idstr), "%u", id); 8821414Scindi 8831414Scindi pairs[i] = fm_nvlist_create(nva); 8841414Scindi if (nvlist_add_string(pairs[i], FM_FMRI_HC_NAME, name) != 0 || 8851414Scindi nvlist_add_string(pairs[i], FM_FMRI_HC_ID, idstr) != 0) { 8861414Scindi atomic_add_64( 8871414Scindi &erpt_kstat_data.fmri_set_failed.value.ui64, 1); 8881414Scindi } 8890Sstevel@tonic-gate } 8901414Scindi va_end(ap); 8910Sstevel@tonic-gate 8921414Scindi if (nvlist_add_nvlist_array(fmri, FM_FMRI_HC_LIST, pairs, npairs) != 0) 8931414Scindi atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 8941414Scindi 8951414Scindi for (i = 0; i < npairs; i++) 8961414Scindi fm_nvlist_destroy(pairs[i], FM_NVA_RETAIN); 8971414Scindi 8981414Scindi if (snvl != NULL) { 8991414Scindi if (nvlist_add_nvlist(fmri, FM_FMRI_HC_SPECIFIC, snvl) != 0) { 9001414Scindi atomic_add_64( 9011414Scindi &erpt_kstat_data.fmri_set_failed.value.ui64, 1); 9021414Scindi } 9031414Scindi } 9040Sstevel@tonic-gate } 9050Sstevel@tonic-gate 9060Sstevel@tonic-gate /* 9070Sstevel@tonic-gate * Set-up and validate the members of an dev fmri according to: 9080Sstevel@tonic-gate * 9090Sstevel@tonic-gate * Member name Type Value 9100Sstevel@tonic-gate * ==================================================== 9110Sstevel@tonic-gate * version uint8_t 0 9120Sstevel@tonic-gate * auth nvlist_t <auth> 9130Sstevel@tonic-gate * devpath string <devpath> 9140Sstevel@tonic-gate * devid string <devid> 9150Sstevel@tonic-gate * 9160Sstevel@tonic-gate * Note that auth and devid are optional members. 9170Sstevel@tonic-gate */ 9180Sstevel@tonic-gate void 9190Sstevel@tonic-gate fm_fmri_dev_set(nvlist_t *fmri_dev, int version, const nvlist_t *auth, 9200Sstevel@tonic-gate const char *devpath, const char *devid) 9210Sstevel@tonic-gate { 9220Sstevel@tonic-gate if (version != DEV_SCHEME_VERSION0) { 9230Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 9240Sstevel@tonic-gate return; 9250Sstevel@tonic-gate } 9260Sstevel@tonic-gate 9270Sstevel@tonic-gate if (nvlist_add_uint8(fmri_dev, FM_VERSION, version) != 0) { 9280Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 9290Sstevel@tonic-gate return; 9300Sstevel@tonic-gate } 9310Sstevel@tonic-gate 9320Sstevel@tonic-gate if (nvlist_add_string(fmri_dev, FM_FMRI_SCHEME, 9330Sstevel@tonic-gate FM_FMRI_SCHEME_DEV) != 0) { 9340Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 9350Sstevel@tonic-gate return; 9360Sstevel@tonic-gate } 9370Sstevel@tonic-gate 9380Sstevel@tonic-gate if (auth != NULL) { 9390Sstevel@tonic-gate if (nvlist_add_nvlist(fmri_dev, FM_FMRI_AUTHORITY, 9400Sstevel@tonic-gate (nvlist_t *)auth) != 0) { 9410Sstevel@tonic-gate atomic_add_64( 9420Sstevel@tonic-gate &erpt_kstat_data.fmri_set_failed.value.ui64, 1); 9430Sstevel@tonic-gate } 9440Sstevel@tonic-gate } 9450Sstevel@tonic-gate 9460Sstevel@tonic-gate if (nvlist_add_string(fmri_dev, FM_FMRI_DEV_PATH, devpath) != 0) { 9470Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 9480Sstevel@tonic-gate } 9490Sstevel@tonic-gate 9500Sstevel@tonic-gate if (devid != NULL) 9510Sstevel@tonic-gate if (nvlist_add_string(fmri_dev, FM_FMRI_DEV_ID, devid) != 0) 9520Sstevel@tonic-gate atomic_add_64( 9530Sstevel@tonic-gate &erpt_kstat_data.fmri_set_failed.value.ui64, 1); 9540Sstevel@tonic-gate } 9550Sstevel@tonic-gate 9560Sstevel@tonic-gate /* 9570Sstevel@tonic-gate * Set-up and validate the members of an cpu fmri according to: 9580Sstevel@tonic-gate * 9590Sstevel@tonic-gate * Member name Type Value 9600Sstevel@tonic-gate * ==================================================== 9610Sstevel@tonic-gate * version uint8_t 0 9620Sstevel@tonic-gate * auth nvlist_t <auth> 9630Sstevel@tonic-gate * cpuid uint32_t <cpu_id> 9640Sstevel@tonic-gate * cpumask uint8_t <cpu_mask> 9650Sstevel@tonic-gate * serial uint64_t <serial_id> 9660Sstevel@tonic-gate * 9671414Scindi * Note that auth, cpumask, serial are optional members. 9680Sstevel@tonic-gate * 9690Sstevel@tonic-gate */ 9700Sstevel@tonic-gate void 9710Sstevel@tonic-gate fm_fmri_cpu_set(nvlist_t *fmri_cpu, int version, const nvlist_t *auth, 9721414Scindi uint32_t cpu_id, uint8_t *cpu_maskp, const char *serial_idp) 9730Sstevel@tonic-gate { 9741414Scindi uint64_t *failedp = &erpt_kstat_data.fmri_set_failed.value.ui64; 9751414Scindi 9761414Scindi if (version < CPU_SCHEME_VERSION1) { 9771414Scindi atomic_add_64(failedp, 1); 9780Sstevel@tonic-gate return; 9790Sstevel@tonic-gate } 9800Sstevel@tonic-gate 9810Sstevel@tonic-gate if (nvlist_add_uint8(fmri_cpu, FM_VERSION, version) != 0) { 9821414Scindi atomic_add_64(failedp, 1); 9830Sstevel@tonic-gate return; 9840Sstevel@tonic-gate } 9850Sstevel@tonic-gate 9860Sstevel@tonic-gate if (nvlist_add_string(fmri_cpu, FM_FMRI_SCHEME, 9870Sstevel@tonic-gate FM_FMRI_SCHEME_CPU) != 0) { 9881414Scindi atomic_add_64(failedp, 1); 9890Sstevel@tonic-gate return; 9900Sstevel@tonic-gate } 9910Sstevel@tonic-gate 9921414Scindi if (auth != NULL && nvlist_add_nvlist(fmri_cpu, FM_FMRI_AUTHORITY, 9931414Scindi (nvlist_t *)auth) != 0) 9941414Scindi atomic_add_64(failedp, 1); 9951414Scindi 9961414Scindi if (nvlist_add_uint32(fmri_cpu, FM_FMRI_CPU_ID, cpu_id) != 0) 9971414Scindi atomic_add_64(failedp, 1); 9980Sstevel@tonic-gate 9991414Scindi if (cpu_maskp != NULL && nvlist_add_uint8(fmri_cpu, FM_FMRI_CPU_MASK, 10001414Scindi *cpu_maskp) != 0) 10011414Scindi atomic_add_64(failedp, 1); 10020Sstevel@tonic-gate 10031414Scindi if (serial_idp == NULL || nvlist_add_string(fmri_cpu, 10041414Scindi FM_FMRI_CPU_SERIAL_ID, (char *)serial_idp) != 0) 10051414Scindi atomic_add_64(failedp, 1); 10060Sstevel@tonic-gate } 10070Sstevel@tonic-gate 10080Sstevel@tonic-gate /* 10090Sstevel@tonic-gate * Set-up and validate the members of a mem according to: 10100Sstevel@tonic-gate * 10110Sstevel@tonic-gate * Member name Type Value 10120Sstevel@tonic-gate * ==================================================== 10130Sstevel@tonic-gate * version uint8_t 0 10140Sstevel@tonic-gate * auth nvlist_t <auth> [optional] 10150Sstevel@tonic-gate * unum string <unum> 10161186Sayznaga * serial string <serial> [optional*] 10171186Sayznaga * offset uint64_t <offset> [optional] 10180Sstevel@tonic-gate * 10191186Sayznaga * * serial is required if offset is present 10200Sstevel@tonic-gate */ 10210Sstevel@tonic-gate void 10220Sstevel@tonic-gate fm_fmri_mem_set(nvlist_t *fmri, int version, const nvlist_t *auth, 10231186Sayznaga const char *unum, const char *serial, uint64_t offset) 10240Sstevel@tonic-gate { 10250Sstevel@tonic-gate if (version != MEM_SCHEME_VERSION0) { 10260Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 10270Sstevel@tonic-gate return; 10280Sstevel@tonic-gate } 10290Sstevel@tonic-gate 10301186Sayznaga if (!serial && (offset != (uint64_t)-1)) { 10311186Sayznaga atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 10321186Sayznaga return; 10331186Sayznaga } 10341186Sayznaga 10350Sstevel@tonic-gate if (nvlist_add_uint8(fmri, FM_VERSION, version) != 0) { 10360Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 10370Sstevel@tonic-gate return; 10380Sstevel@tonic-gate } 10390Sstevel@tonic-gate 10400Sstevel@tonic-gate if (nvlist_add_string(fmri, FM_FMRI_SCHEME, FM_FMRI_SCHEME_MEM) != 0) { 10410Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 10420Sstevel@tonic-gate return; 10430Sstevel@tonic-gate } 10440Sstevel@tonic-gate 10450Sstevel@tonic-gate if (auth != NULL) { 10460Sstevel@tonic-gate if (nvlist_add_nvlist(fmri, FM_FMRI_AUTHORITY, 10470Sstevel@tonic-gate (nvlist_t *)auth) != 0) { 10480Sstevel@tonic-gate atomic_add_64( 10490Sstevel@tonic-gate &erpt_kstat_data.fmri_set_failed.value.ui64, 1); 10500Sstevel@tonic-gate } 10510Sstevel@tonic-gate } 10520Sstevel@tonic-gate 10530Sstevel@tonic-gate if (nvlist_add_string(fmri, FM_FMRI_MEM_UNUM, unum) != 0) { 10540Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 10550Sstevel@tonic-gate } 10560Sstevel@tonic-gate 10570Sstevel@tonic-gate if (serial != NULL) { 10580Sstevel@tonic-gate if (nvlist_add_string_array(fmri, FM_FMRI_MEM_SERIAL_ID, 10590Sstevel@tonic-gate (char **)&serial, 1) != 0) { 10600Sstevel@tonic-gate atomic_add_64( 10610Sstevel@tonic-gate &erpt_kstat_data.fmri_set_failed.value.ui64, 1); 10620Sstevel@tonic-gate } 10631186Sayznaga if (offset != (uint64_t)-1) { 10641186Sayznaga if (nvlist_add_uint64(fmri, FM_FMRI_MEM_OFFSET, 10651186Sayznaga offset) != 0) { 10661186Sayznaga atomic_add_64(&erpt_kstat_data. 10671186Sayznaga fmri_set_failed.value.ui64, 1); 10681186Sayznaga } 10691186Sayznaga } 10700Sstevel@tonic-gate } 10710Sstevel@tonic-gate } 10720Sstevel@tonic-gate 10730Sstevel@tonic-gate uint64_t 10740Sstevel@tonic-gate fm_ena_increment(uint64_t ena) 10750Sstevel@tonic-gate { 10760Sstevel@tonic-gate uint64_t new_ena; 10770Sstevel@tonic-gate 10780Sstevel@tonic-gate switch (ENA_FORMAT(ena)) { 10790Sstevel@tonic-gate case FM_ENA_FMT1: 10800Sstevel@tonic-gate new_ena = ena + (1 << ENA_FMT1_GEN_SHFT); 10810Sstevel@tonic-gate break; 10820Sstevel@tonic-gate case FM_ENA_FMT2: 10830Sstevel@tonic-gate new_ena = ena + (1 << ENA_FMT2_GEN_SHFT); 10840Sstevel@tonic-gate break; 10850Sstevel@tonic-gate default: 10860Sstevel@tonic-gate new_ena = 0; 10870Sstevel@tonic-gate } 10880Sstevel@tonic-gate 10890Sstevel@tonic-gate return (new_ena); 10900Sstevel@tonic-gate } 10910Sstevel@tonic-gate 10920Sstevel@tonic-gate uint64_t 10930Sstevel@tonic-gate fm_ena_generate_cpu(uint64_t timestamp, processorid_t cpuid, uchar_t format) 10940Sstevel@tonic-gate { 10950Sstevel@tonic-gate uint64_t ena = 0; 10960Sstevel@tonic-gate 10970Sstevel@tonic-gate switch (format) { 10980Sstevel@tonic-gate case FM_ENA_FMT1: 10990Sstevel@tonic-gate if (timestamp) { 11000Sstevel@tonic-gate ena = (uint64_t)((format & ENA_FORMAT_MASK) | 11010Sstevel@tonic-gate ((cpuid << ENA_FMT1_CPUID_SHFT) & 11020Sstevel@tonic-gate ENA_FMT1_CPUID_MASK) | 11030Sstevel@tonic-gate ((timestamp << ENA_FMT1_TIME_SHFT) & 11040Sstevel@tonic-gate ENA_FMT1_TIME_MASK)); 11050Sstevel@tonic-gate } else { 11060Sstevel@tonic-gate ena = (uint64_t)((format & ENA_FORMAT_MASK) | 11070Sstevel@tonic-gate ((cpuid << ENA_FMT1_CPUID_SHFT) & 11080Sstevel@tonic-gate ENA_FMT1_CPUID_MASK) | 11090Sstevel@tonic-gate ((gethrtime_waitfree() << ENA_FMT1_TIME_SHFT) & 11100Sstevel@tonic-gate ENA_FMT1_TIME_MASK)); 11110Sstevel@tonic-gate } 11120Sstevel@tonic-gate break; 11130Sstevel@tonic-gate case FM_ENA_FMT2: 11140Sstevel@tonic-gate ena = (uint64_t)((format & ENA_FORMAT_MASK) | 11150Sstevel@tonic-gate ((timestamp << ENA_FMT2_TIME_SHFT) & ENA_FMT2_TIME_MASK)); 11160Sstevel@tonic-gate break; 11170Sstevel@tonic-gate default: 11180Sstevel@tonic-gate break; 11190Sstevel@tonic-gate } 11200Sstevel@tonic-gate 11210Sstevel@tonic-gate return (ena); 11220Sstevel@tonic-gate } 11230Sstevel@tonic-gate 11240Sstevel@tonic-gate uint64_t 11250Sstevel@tonic-gate fm_ena_generate(uint64_t timestamp, uchar_t format) 11260Sstevel@tonic-gate { 11270Sstevel@tonic-gate return (fm_ena_generate_cpu(timestamp, CPU->cpu_id, format)); 11280Sstevel@tonic-gate } 11290Sstevel@tonic-gate 11300Sstevel@tonic-gate uint64_t 11310Sstevel@tonic-gate fm_ena_generation_get(uint64_t ena) 11320Sstevel@tonic-gate { 11330Sstevel@tonic-gate uint64_t gen; 11340Sstevel@tonic-gate 11350Sstevel@tonic-gate switch (ENA_FORMAT(ena)) { 11360Sstevel@tonic-gate case FM_ENA_FMT1: 11370Sstevel@tonic-gate gen = (ena & ENA_FMT1_GEN_MASK) >> ENA_FMT1_GEN_SHFT; 11380Sstevel@tonic-gate break; 11390Sstevel@tonic-gate case FM_ENA_FMT2: 11400Sstevel@tonic-gate gen = (ena & ENA_FMT2_GEN_MASK) >> ENA_FMT2_GEN_SHFT; 11410Sstevel@tonic-gate break; 11420Sstevel@tonic-gate default: 11430Sstevel@tonic-gate gen = 0; 11440Sstevel@tonic-gate break; 11450Sstevel@tonic-gate } 11460Sstevel@tonic-gate 11470Sstevel@tonic-gate return (gen); 11480Sstevel@tonic-gate } 11490Sstevel@tonic-gate 11500Sstevel@tonic-gate uchar_t 11510Sstevel@tonic-gate fm_ena_format_get(uint64_t ena) 11520Sstevel@tonic-gate { 11530Sstevel@tonic-gate 11540Sstevel@tonic-gate return (ENA_FORMAT(ena)); 11550Sstevel@tonic-gate } 11560Sstevel@tonic-gate 11570Sstevel@tonic-gate uint64_t 11580Sstevel@tonic-gate fm_ena_id_get(uint64_t ena) 11590Sstevel@tonic-gate { 11600Sstevel@tonic-gate uint64_t id; 11610Sstevel@tonic-gate 11620Sstevel@tonic-gate switch (ENA_FORMAT(ena)) { 11630Sstevel@tonic-gate case FM_ENA_FMT1: 11640Sstevel@tonic-gate id = (ena & ENA_FMT1_ID_MASK) >> ENA_FMT1_ID_SHFT; 11650Sstevel@tonic-gate break; 11660Sstevel@tonic-gate case FM_ENA_FMT2: 11670Sstevel@tonic-gate id = (ena & ENA_FMT2_ID_MASK) >> ENA_FMT2_ID_SHFT; 11680Sstevel@tonic-gate break; 11690Sstevel@tonic-gate default: 11700Sstevel@tonic-gate id = 0; 11710Sstevel@tonic-gate } 11720Sstevel@tonic-gate 11730Sstevel@tonic-gate return (id); 11740Sstevel@tonic-gate } 11750Sstevel@tonic-gate 11760Sstevel@tonic-gate uint64_t 11770Sstevel@tonic-gate fm_ena_time_get(uint64_t ena) 11780Sstevel@tonic-gate { 11790Sstevel@tonic-gate uint64_t time; 11800Sstevel@tonic-gate 11810Sstevel@tonic-gate switch (ENA_FORMAT(ena)) { 11820Sstevel@tonic-gate case FM_ENA_FMT1: 11830Sstevel@tonic-gate time = (ena & ENA_FMT1_TIME_MASK) >> ENA_FMT1_TIME_SHFT; 11840Sstevel@tonic-gate break; 11850Sstevel@tonic-gate case FM_ENA_FMT2: 11860Sstevel@tonic-gate time = (ena & ENA_FMT2_TIME_MASK) >> ENA_FMT2_TIME_SHFT; 11870Sstevel@tonic-gate break; 11880Sstevel@tonic-gate default: 11890Sstevel@tonic-gate time = 0; 11900Sstevel@tonic-gate } 11910Sstevel@tonic-gate 11920Sstevel@tonic-gate return (time); 11930Sstevel@tonic-gate } 11941414Scindi 11951414Scindi /* 11961414Scindi * Convert a getpcstack() trace to symbolic name+offset, and add the resulting 11971414Scindi * string array to a Fault Management ereport as FM_EREPORT_PAYLOAD_NAME_STACK. 11981414Scindi */ 11991414Scindi void 12001414Scindi fm_payload_stack_add(nvlist_t *payload, const pc_t *stack, int depth) 12011414Scindi { 12021414Scindi int i; 12031414Scindi char *sym; 12041414Scindi ulong_t off; 12051414Scindi char *stkpp[FM_STK_DEPTH]; 12061414Scindi char buf[FM_STK_DEPTH * FM_SYM_SZ]; 12071414Scindi char *stkp = buf; 12081414Scindi 12091414Scindi for (i = 0; i < depth && i != FM_STK_DEPTH; i++, stkp += FM_SYM_SZ) { 12101414Scindi if ((sym = kobj_getsymname(stack[i], &off)) != NULL) 12111414Scindi (void) snprintf(stkp, FM_SYM_SZ, "%s+%lx", sym, off); 12121414Scindi else 12131414Scindi (void) snprintf(stkp, FM_SYM_SZ, "%lx", (long)stack[i]); 12141414Scindi stkpp[i] = stkp; 12151414Scindi } 12161414Scindi 12171414Scindi fm_payload_set(payload, FM_EREPORT_PAYLOAD_NAME_STACK, 1218*1437Sdilpreet DATA_TYPE_STRING_ARRAY, depth, stkpp, NULL); 12191414Scindi } 1220