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 51544Seschrock * Common Development and Distribution License (the "License"). 61544Seschrock * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 2212213SGavin.Maltby@Sun.COM * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 230Sstevel@tonic-gate */ 240Sstevel@tonic-gate 250Sstevel@tonic-gate /* 260Sstevel@tonic-gate * Fault Management Architecture (FMA) Resource and Protocol Support 270Sstevel@tonic-gate * 280Sstevel@tonic-gate * The routines contained herein provide services to support kernel subsystems 290Sstevel@tonic-gate * in publishing fault management telemetry (see PSARC 2002/412 and 2003/089). 300Sstevel@tonic-gate * 310Sstevel@tonic-gate * Name-Value Pair Lists 320Sstevel@tonic-gate * 330Sstevel@tonic-gate * The embodiment of an FMA protocol element (event, fmri or authority) is a 340Sstevel@tonic-gate * name-value pair list (nvlist_t). FMA-specific nvlist construtor and 350Sstevel@tonic-gate * destructor functions, fm_nvlist_create() and fm_nvlist_destroy(), are used 360Sstevel@tonic-gate * to create an nvpair list using custom allocators. Callers may choose to 370Sstevel@tonic-gate * allocate either from the kernel memory allocator, or from a preallocated 380Sstevel@tonic-gate * buffer, useful in constrained contexts like high-level interrupt routines. 390Sstevel@tonic-gate * 400Sstevel@tonic-gate * Protocol Event and FMRI Construction 410Sstevel@tonic-gate * 420Sstevel@tonic-gate * Convenience routines are provided to construct nvlist events according to 430Sstevel@tonic-gate * the FMA Event Protocol and Naming Schema specification for ereports and 440Sstevel@tonic-gate * FMRIs for the dev, cpu, hc, mem, legacy hc and de schemes. 450Sstevel@tonic-gate * 460Sstevel@tonic-gate * ENA Manipulation 470Sstevel@tonic-gate * 480Sstevel@tonic-gate * Routines to generate ENA formats 0, 1 and 2 are available as well as 490Sstevel@tonic-gate * routines to increment formats 1 and 2. Individual fields within the 500Sstevel@tonic-gate * ENA are extractable via fm_ena_time_get(), fm_ena_id_get(), 510Sstevel@tonic-gate * fm_ena_format_get() and fm_ena_gen_get(). 520Sstevel@tonic-gate */ 530Sstevel@tonic-gate 540Sstevel@tonic-gate #include <sys/types.h> 550Sstevel@tonic-gate #include <sys/time.h> 560Sstevel@tonic-gate #include <sys/sysevent.h> 570Sstevel@tonic-gate #include <sys/sysevent_impl.h> 580Sstevel@tonic-gate #include <sys/nvpair.h> 590Sstevel@tonic-gate #include <sys/cmn_err.h> 600Sstevel@tonic-gate #include <sys/cpuvar.h> 610Sstevel@tonic-gate #include <sys/sysmacros.h> 620Sstevel@tonic-gate #include <sys/systm.h> 630Sstevel@tonic-gate #include <sys/ddifm.h> 640Sstevel@tonic-gate #include <sys/ddifm_impl.h> 650Sstevel@tonic-gate #include <sys/spl.h> 660Sstevel@tonic-gate #include <sys/dumphdr.h> 670Sstevel@tonic-gate #include <sys/compress.h> 680Sstevel@tonic-gate #include <sys/cpuvar.h> 690Sstevel@tonic-gate #include <sys/console.h> 700Sstevel@tonic-gate #include <sys/panic.h> 711414Scindi #include <sys/kobj.h> 721414Scindi #include <sys/sunddi.h> 730Sstevel@tonic-gate #include <sys/systeminfo.h> 740Sstevel@tonic-gate #include <sys/sysevent/eventdefs.h> 750Sstevel@tonic-gate #include <sys/fm/util.h> 760Sstevel@tonic-gate #include <sys/fm/protocol.h> 770Sstevel@tonic-gate 780Sstevel@tonic-gate /* 790Sstevel@tonic-gate * URL and SUNW-MSG-ID value to display for fm_panic(), defined below. These 800Sstevel@tonic-gate * values must be kept in sync with the FMA source code in usr/src/cmd/fm. 810Sstevel@tonic-gate */ 820Sstevel@tonic-gate static const char *fm_url = "http://www.sun.com/msg"; 830Sstevel@tonic-gate static const char *fm_msgid = "SUNOS-8000-0G"; 840Sstevel@tonic-gate static char *volatile fm_panicstr = NULL; 850Sstevel@tonic-gate 860Sstevel@tonic-gate errorq_t *ereport_errorq; 870Sstevel@tonic-gate void *ereport_dumpbuf; 880Sstevel@tonic-gate size_t ereport_dumplen; 890Sstevel@tonic-gate 900Sstevel@tonic-gate static uint_t ereport_chanlen = ERPT_EVCH_MAX; 910Sstevel@tonic-gate static evchan_t *ereport_chan = NULL; 920Sstevel@tonic-gate static ulong_t ereport_qlen = 0; 930Sstevel@tonic-gate static size_t ereport_size = 0; 940Sstevel@tonic-gate static int ereport_cols = 80; 950Sstevel@tonic-gate 9610664SAdrian.Frost@Sun.COM extern void fastreboot_disable_highpil(void); 9710664SAdrian.Frost@Sun.COM 980Sstevel@tonic-gate /* 990Sstevel@tonic-gate * Common fault management kstats to record ereport generation 1000Sstevel@tonic-gate * failures 1010Sstevel@tonic-gate */ 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate struct erpt_kstat { 1040Sstevel@tonic-gate kstat_named_t erpt_dropped; /* num erpts dropped on post */ 1050Sstevel@tonic-gate kstat_named_t erpt_set_failed; /* num erpt set failures */ 1060Sstevel@tonic-gate kstat_named_t fmri_set_failed; /* num fmri set failures */ 1070Sstevel@tonic-gate kstat_named_t payload_set_failed; /* num payload set failures */ 1080Sstevel@tonic-gate }; 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate static struct erpt_kstat erpt_kstat_data = { 1110Sstevel@tonic-gate { "erpt-dropped", KSTAT_DATA_UINT64 }, 1120Sstevel@tonic-gate { "erpt-set-failed", KSTAT_DATA_UINT64 }, 1130Sstevel@tonic-gate { "fmri-set-failed", KSTAT_DATA_UINT64 }, 1140Sstevel@tonic-gate { "payload-set-failed", KSTAT_DATA_UINT64 } 1150Sstevel@tonic-gate }; 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate /*ARGSUSED*/ 1180Sstevel@tonic-gate static void 1190Sstevel@tonic-gate fm_drain(void *private, void *data, errorq_elem_t *eep) 1200Sstevel@tonic-gate { 1210Sstevel@tonic-gate nvlist_t *nvl = errorq_elem_nvl(ereport_errorq, eep); 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate if (!panicstr) 1240Sstevel@tonic-gate (void) fm_ereport_post(nvl, EVCH_TRYHARD); 1250Sstevel@tonic-gate else 1260Sstevel@tonic-gate fm_nvprint(nvl); 1270Sstevel@tonic-gate } 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate void 1300Sstevel@tonic-gate fm_init(void) 1310Sstevel@tonic-gate { 1320Sstevel@tonic-gate kstat_t *ksp; 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate (void) sysevent_evc_bind(FM_ERROR_CHAN, 1350Sstevel@tonic-gate &ereport_chan, EVCH_CREAT | EVCH_HOLD_PEND); 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate (void) sysevent_evc_control(ereport_chan, 1380Sstevel@tonic-gate EVCH_SET_CHAN_LEN, &ereport_chanlen); 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate if (ereport_qlen == 0) 1410Sstevel@tonic-gate ereport_qlen = ERPT_MAX_ERRS * MAX(max_ncpus, 4); 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate if (ereport_size == 0) 1440Sstevel@tonic-gate ereport_size = ERPT_DATA_SZ; 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate ereport_errorq = errorq_nvcreate("fm_ereport_queue", 1470Sstevel@tonic-gate (errorq_func_t)fm_drain, NULL, ereport_qlen, ereport_size, 1480Sstevel@tonic-gate FM_ERR_PIL, ERRORQ_VITAL); 1490Sstevel@tonic-gate if (ereport_errorq == NULL) 1500Sstevel@tonic-gate panic("failed to create required ereport error queue"); 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate ereport_dumpbuf = kmem_alloc(ereport_size, KM_SLEEP); 1530Sstevel@tonic-gate ereport_dumplen = ereport_size; 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate /* Initialize ereport allocation and generation kstats */ 1560Sstevel@tonic-gate ksp = kstat_create("unix", 0, "fm", "misc", KSTAT_TYPE_NAMED, 1570Sstevel@tonic-gate sizeof (struct erpt_kstat) / sizeof (kstat_named_t), 1580Sstevel@tonic-gate KSTAT_FLAG_VIRTUAL); 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate if (ksp != NULL) { 1610Sstevel@tonic-gate ksp->ks_data = &erpt_kstat_data; 1620Sstevel@tonic-gate kstat_install(ksp); 1630Sstevel@tonic-gate } else { 1640Sstevel@tonic-gate cmn_err(CE_NOTE, "failed to create fm/misc kstat\n"); 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate } 1670Sstevel@tonic-gate } 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate /* 1700Sstevel@tonic-gate * Formatting utility function for fm_nvprintr. We attempt to wrap chunks of 1710Sstevel@tonic-gate * output so they aren't split across console lines, and return the end column. 1720Sstevel@tonic-gate */ 1730Sstevel@tonic-gate /*PRINTFLIKE4*/ 1740Sstevel@tonic-gate static int 1750Sstevel@tonic-gate fm_printf(int depth, int c, int cols, const char *format, ...) 1760Sstevel@tonic-gate { 1770Sstevel@tonic-gate va_list ap; 1780Sstevel@tonic-gate int width; 1790Sstevel@tonic-gate char c1; 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate va_start(ap, format); 1820Sstevel@tonic-gate width = vsnprintf(&c1, sizeof (c1), format, ap); 1830Sstevel@tonic-gate va_end(ap); 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate if (c + width >= cols) { 1860Sstevel@tonic-gate console_printf("\n\r"); 1870Sstevel@tonic-gate c = 0; 1880Sstevel@tonic-gate if (format[0] != ' ' && depth > 0) { 1890Sstevel@tonic-gate console_printf(" "); 1900Sstevel@tonic-gate c++; 1910Sstevel@tonic-gate } 1920Sstevel@tonic-gate } 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate va_start(ap, format); 1950Sstevel@tonic-gate console_vprintf(format, ap); 1960Sstevel@tonic-gate va_end(ap); 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate return ((c + width) % cols); 1990Sstevel@tonic-gate } 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate /* 2020Sstevel@tonic-gate * Recursively print a nvlist in the specified column width and return the 2030Sstevel@tonic-gate * column we end up in. This function is called recursively by fm_nvprint(), 2040Sstevel@tonic-gate * below. We generically format the entire nvpair using hexadecimal 2050Sstevel@tonic-gate * integers and strings, and elide any integer arrays. Arrays are basically 2060Sstevel@tonic-gate * used for cache dumps right now, so we suppress them so as not to overwhelm 2070Sstevel@tonic-gate * the amount of console output we produce at panic time. This can be further 2080Sstevel@tonic-gate * enhanced as FMA technology grows based upon the needs of consumers. All 2090Sstevel@tonic-gate * FMA telemetry is logged using the dump device transport, so the console 2100Sstevel@tonic-gate * output serves only as a fallback in case this procedure is unsuccessful. 2110Sstevel@tonic-gate */ 2120Sstevel@tonic-gate static int 2130Sstevel@tonic-gate fm_nvprintr(nvlist_t *nvl, int d, int c, int cols) 2140Sstevel@tonic-gate { 2150Sstevel@tonic-gate nvpair_t *nvp; 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate for (nvp = nvlist_next_nvpair(nvl, NULL); 2180Sstevel@tonic-gate nvp != NULL; nvp = nvlist_next_nvpair(nvl, nvp)) { 2190Sstevel@tonic-gate 2200Sstevel@tonic-gate data_type_t type = nvpair_type(nvp); 2210Sstevel@tonic-gate const char *name = nvpair_name(nvp); 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate boolean_t b; 2240Sstevel@tonic-gate uint8_t i8; 2250Sstevel@tonic-gate uint16_t i16; 2260Sstevel@tonic-gate uint32_t i32; 2270Sstevel@tonic-gate uint64_t i64; 2280Sstevel@tonic-gate char *str; 2290Sstevel@tonic-gate nvlist_t *cnv; 2300Sstevel@tonic-gate 2310Sstevel@tonic-gate if (strcmp(name, FM_CLASS) == 0) 2320Sstevel@tonic-gate continue; /* already printed by caller */ 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate c = fm_printf(d, c, cols, " %s=", name); 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate switch (type) { 2370Sstevel@tonic-gate case DATA_TYPE_BOOLEAN: 2380Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, " 1"); 2390Sstevel@tonic-gate break; 2400Sstevel@tonic-gate 2410Sstevel@tonic-gate case DATA_TYPE_BOOLEAN_VALUE: 2420Sstevel@tonic-gate (void) nvpair_value_boolean_value(nvp, &b); 2430Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, b ? "1" : "0"); 2440Sstevel@tonic-gate break; 2450Sstevel@tonic-gate 2460Sstevel@tonic-gate case DATA_TYPE_BYTE: 2470Sstevel@tonic-gate (void) nvpair_value_byte(nvp, &i8); 2480Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%x", i8); 2490Sstevel@tonic-gate break; 2500Sstevel@tonic-gate 2510Sstevel@tonic-gate case DATA_TYPE_INT8: 2520Sstevel@tonic-gate (void) nvpair_value_int8(nvp, (void *)&i8); 2530Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%x", i8); 2540Sstevel@tonic-gate break; 2550Sstevel@tonic-gate 2560Sstevel@tonic-gate case DATA_TYPE_UINT8: 2570Sstevel@tonic-gate (void) nvpair_value_uint8(nvp, &i8); 2580Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%x", i8); 2590Sstevel@tonic-gate break; 2600Sstevel@tonic-gate 2610Sstevel@tonic-gate case DATA_TYPE_INT16: 2620Sstevel@tonic-gate (void) nvpair_value_int16(nvp, (void *)&i16); 2630Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%x", i16); 2640Sstevel@tonic-gate break; 2650Sstevel@tonic-gate 2660Sstevel@tonic-gate case DATA_TYPE_UINT16: 2670Sstevel@tonic-gate (void) nvpair_value_uint16(nvp, &i16); 2680Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%x", i16); 2690Sstevel@tonic-gate break; 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate case DATA_TYPE_INT32: 2720Sstevel@tonic-gate (void) nvpair_value_int32(nvp, (void *)&i32); 2730Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%x", i32); 2740Sstevel@tonic-gate break; 2750Sstevel@tonic-gate 2760Sstevel@tonic-gate case DATA_TYPE_UINT32: 2770Sstevel@tonic-gate (void) nvpair_value_uint32(nvp, &i32); 2780Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%x", i32); 2790Sstevel@tonic-gate break; 2800Sstevel@tonic-gate 2810Sstevel@tonic-gate case DATA_TYPE_INT64: 2820Sstevel@tonic-gate (void) nvpair_value_int64(nvp, (void *)&i64); 2830Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%llx", 2840Sstevel@tonic-gate (u_longlong_t)i64); 2850Sstevel@tonic-gate break; 2860Sstevel@tonic-gate 2870Sstevel@tonic-gate case DATA_TYPE_UINT64: 2880Sstevel@tonic-gate (void) nvpair_value_uint64(nvp, &i64); 2890Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%llx", 2900Sstevel@tonic-gate (u_longlong_t)i64); 2910Sstevel@tonic-gate break; 2920Sstevel@tonic-gate 2930Sstevel@tonic-gate case DATA_TYPE_HRTIME: 2940Sstevel@tonic-gate (void) nvpair_value_hrtime(nvp, (void *)&i64); 2950Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%llx", 2960Sstevel@tonic-gate (u_longlong_t)i64); 2970Sstevel@tonic-gate break; 2980Sstevel@tonic-gate 2990Sstevel@tonic-gate case DATA_TYPE_STRING: 3000Sstevel@tonic-gate (void) nvpair_value_string(nvp, &str); 3010Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "\"%s\"", 3020Sstevel@tonic-gate str ? str : "<NULL>"); 3030Sstevel@tonic-gate break; 3040Sstevel@tonic-gate 3050Sstevel@tonic-gate case DATA_TYPE_NVLIST: 3060Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "["); 3070Sstevel@tonic-gate (void) nvpair_value_nvlist(nvp, &cnv); 3080Sstevel@tonic-gate c = fm_nvprintr(cnv, d + 1, c, cols); 3090Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, " ]"); 3100Sstevel@tonic-gate break; 3110Sstevel@tonic-gate 3127532SSean.Ye@Sun.COM case DATA_TYPE_NVLIST_ARRAY: { 3137532SSean.Ye@Sun.COM nvlist_t **val; 3147532SSean.Ye@Sun.COM uint_t i, nelem; 3157532SSean.Ye@Sun.COM 3167532SSean.Ye@Sun.COM c = fm_printf(d + 1, c, cols, "["); 3177532SSean.Ye@Sun.COM (void) nvpair_value_nvlist_array(nvp, &val, &nelem); 3187532SSean.Ye@Sun.COM for (i = 0; i < nelem; i++) { 3197532SSean.Ye@Sun.COM c = fm_nvprintr(val[i], d + 1, c, cols); 3207532SSean.Ye@Sun.COM } 3217532SSean.Ye@Sun.COM c = fm_printf(d + 1, c, cols, " ]"); 3227532SSean.Ye@Sun.COM } 3237532SSean.Ye@Sun.COM break; 3247532SSean.Ye@Sun.COM 3250Sstevel@tonic-gate case DATA_TYPE_BOOLEAN_ARRAY: 3260Sstevel@tonic-gate case DATA_TYPE_BYTE_ARRAY: 3270Sstevel@tonic-gate case DATA_TYPE_INT8_ARRAY: 3280Sstevel@tonic-gate case DATA_TYPE_UINT8_ARRAY: 3290Sstevel@tonic-gate case DATA_TYPE_INT16_ARRAY: 3300Sstevel@tonic-gate case DATA_TYPE_UINT16_ARRAY: 3310Sstevel@tonic-gate case DATA_TYPE_INT32_ARRAY: 3320Sstevel@tonic-gate case DATA_TYPE_UINT32_ARRAY: 3330Sstevel@tonic-gate case DATA_TYPE_INT64_ARRAY: 3340Sstevel@tonic-gate case DATA_TYPE_UINT64_ARRAY: 3350Sstevel@tonic-gate case DATA_TYPE_STRING_ARRAY: 3360Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "[...]"); 3370Sstevel@tonic-gate break; 3380Sstevel@tonic-gate case DATA_TYPE_UNKNOWN: 3390Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "<unknown>"); 3400Sstevel@tonic-gate break; 3410Sstevel@tonic-gate } 3420Sstevel@tonic-gate } 3430Sstevel@tonic-gate 3440Sstevel@tonic-gate return (c); 3450Sstevel@tonic-gate } 3460Sstevel@tonic-gate 3470Sstevel@tonic-gate void 3480Sstevel@tonic-gate fm_nvprint(nvlist_t *nvl) 3490Sstevel@tonic-gate { 3500Sstevel@tonic-gate char *class; 3510Sstevel@tonic-gate int c = 0; 3520Sstevel@tonic-gate 3530Sstevel@tonic-gate console_printf("\r"); 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate if (nvlist_lookup_string(nvl, FM_CLASS, &class) == 0) 3560Sstevel@tonic-gate c = fm_printf(0, c, ereport_cols, "%s", class); 3570Sstevel@tonic-gate 3580Sstevel@tonic-gate if (fm_nvprintr(nvl, 0, c, ereport_cols) != 0) 3590Sstevel@tonic-gate console_printf("\n"); 3600Sstevel@tonic-gate 3610Sstevel@tonic-gate console_printf("\n"); 3620Sstevel@tonic-gate } 3630Sstevel@tonic-gate 3640Sstevel@tonic-gate /* 3650Sstevel@tonic-gate * Wrapper for panic() that first produces an FMA-style message for admins. 3660Sstevel@tonic-gate * Normally such messages are generated by fmd(1M)'s syslog-msgs agent: this 3670Sstevel@tonic-gate * is the one exception to that rule and the only error that gets messaged. 3680Sstevel@tonic-gate * This function is intended for use by subsystems that have detected a fatal 3690Sstevel@tonic-gate * error and enqueued appropriate ereports and wish to then force a panic. 3700Sstevel@tonic-gate */ 3710Sstevel@tonic-gate /*PRINTFLIKE1*/ 3720Sstevel@tonic-gate void 3730Sstevel@tonic-gate fm_panic(const char *format, ...) 3740Sstevel@tonic-gate { 3750Sstevel@tonic-gate va_list ap; 3760Sstevel@tonic-gate 3770Sstevel@tonic-gate (void) casptr((void *)&fm_panicstr, NULL, (void *)format); 37810664SAdrian.Frost@Sun.COM #if defined(__i386) || defined(__amd64) 37910664SAdrian.Frost@Sun.COM fastreboot_disable_highpil(); 38010664SAdrian.Frost@Sun.COM #endif /* __i386 || __amd64 */ 3810Sstevel@tonic-gate va_start(ap, format); 3820Sstevel@tonic-gate vpanic(format, ap); 3830Sstevel@tonic-gate va_end(ap); 3840Sstevel@tonic-gate } 3850Sstevel@tonic-gate 3860Sstevel@tonic-gate /* 3870Sstevel@tonic-gate * Print any appropriate FMA banner message before the panic message. This 3880Sstevel@tonic-gate * function is called by panicsys() and prints the message for fm_panic(). 3890Sstevel@tonic-gate * We print the message here so that it comes after the system is quiesced. 3900Sstevel@tonic-gate * A one-line summary is recorded in the log only (cmn_err(9F) with "!" prefix). 3910Sstevel@tonic-gate * The rest of the message is for the console only and not needed in the log, 3920Sstevel@tonic-gate * so it is printed using console_printf(). We break it up into multiple 3930Sstevel@tonic-gate * chunks so as to avoid overflowing any small legacy prom_printf() buffers. 3940Sstevel@tonic-gate */ 3950Sstevel@tonic-gate void 3960Sstevel@tonic-gate fm_banner(void) 3970Sstevel@tonic-gate { 3980Sstevel@tonic-gate timespec_t tod; 3990Sstevel@tonic-gate hrtime_t now; 4000Sstevel@tonic-gate 4010Sstevel@tonic-gate if (!fm_panicstr) 4020Sstevel@tonic-gate return; /* panic was not initiated by fm_panic(); do nothing */ 4030Sstevel@tonic-gate 4040Sstevel@tonic-gate if (panicstr) { 4050Sstevel@tonic-gate tod = panic_hrestime; 4060Sstevel@tonic-gate now = panic_hrtime; 4070Sstevel@tonic-gate } else { 4080Sstevel@tonic-gate gethrestime(&tod); 4090Sstevel@tonic-gate now = gethrtime_waitfree(); 4100Sstevel@tonic-gate } 4110Sstevel@tonic-gate 4120Sstevel@tonic-gate cmn_err(CE_NOTE, "!SUNW-MSG-ID: %s, " 4130Sstevel@tonic-gate "TYPE: Error, VER: 1, SEVERITY: Major\n", fm_msgid); 4140Sstevel@tonic-gate 4150Sstevel@tonic-gate console_printf( 4160Sstevel@tonic-gate "\n\rSUNW-MSG-ID: %s, TYPE: Error, VER: 1, SEVERITY: Major\n" 4170Sstevel@tonic-gate "EVENT-TIME: 0x%lx.0x%lx (0x%llx)\n", 4180Sstevel@tonic-gate fm_msgid, tod.tv_sec, tod.tv_nsec, (u_longlong_t)now); 4190Sstevel@tonic-gate 4200Sstevel@tonic-gate console_printf( 4216014Ssuha "PLATFORM: %s, CSN: -, HOSTNAME: %s\n" 4220Sstevel@tonic-gate "SOURCE: %s, REV: %s %s\n", 4230Sstevel@tonic-gate platform, utsname.nodename, utsname.sysname, 4240Sstevel@tonic-gate utsname.release, utsname.version); 4250Sstevel@tonic-gate 4260Sstevel@tonic-gate console_printf( 4270Sstevel@tonic-gate "DESC: Errors have been detected that require a reboot to ensure system\n" 4280Sstevel@tonic-gate "integrity. See %s/%s for more information.\n", 4290Sstevel@tonic-gate fm_url, fm_msgid); 4300Sstevel@tonic-gate 4310Sstevel@tonic-gate console_printf( 4320Sstevel@tonic-gate "AUTO-RESPONSE: Solaris will attempt to save and diagnose the error telemetry\n" 4330Sstevel@tonic-gate "IMPACT: The system will sync files, save a crash dump if needed, and reboot\n" 4340Sstevel@tonic-gate "REC-ACTION: Save the error summary below in case telemetry cannot be saved\n"); 4350Sstevel@tonic-gate 4360Sstevel@tonic-gate console_printf("\n"); 4370Sstevel@tonic-gate } 4380Sstevel@tonic-gate 4390Sstevel@tonic-gate /* 4400Sstevel@tonic-gate * Utility function to write all of the pending ereports to the dump device. 4410Sstevel@tonic-gate * This function is called at either normal reboot or panic time, and simply 4420Sstevel@tonic-gate * iterates over the in-transit messages in the ereport sysevent channel. 4430Sstevel@tonic-gate */ 4440Sstevel@tonic-gate void 4450Sstevel@tonic-gate fm_ereport_dump(void) 4460Sstevel@tonic-gate { 4470Sstevel@tonic-gate evchanq_t *chq; 4480Sstevel@tonic-gate sysevent_t *sep; 4490Sstevel@tonic-gate erpt_dump_t ed; 4500Sstevel@tonic-gate 4510Sstevel@tonic-gate timespec_t tod; 4520Sstevel@tonic-gate hrtime_t now; 4530Sstevel@tonic-gate char *buf; 4540Sstevel@tonic-gate size_t len; 4550Sstevel@tonic-gate 4560Sstevel@tonic-gate if (panicstr) { 4570Sstevel@tonic-gate tod = panic_hrestime; 4580Sstevel@tonic-gate now = panic_hrtime; 4590Sstevel@tonic-gate } else { 4600Sstevel@tonic-gate if (ereport_errorq != NULL) 4610Sstevel@tonic-gate errorq_drain(ereport_errorq); 4620Sstevel@tonic-gate gethrestime(&tod); 4630Sstevel@tonic-gate now = gethrtime_waitfree(); 4640Sstevel@tonic-gate } 4650Sstevel@tonic-gate 4660Sstevel@tonic-gate /* 4670Sstevel@tonic-gate * In the panic case, sysevent_evc_walk_init() will return NULL. 4680Sstevel@tonic-gate */ 4690Sstevel@tonic-gate if ((chq = sysevent_evc_walk_init(ereport_chan, NULL)) == NULL && 4700Sstevel@tonic-gate !panicstr) 4710Sstevel@tonic-gate return; /* event channel isn't initialized yet */ 4720Sstevel@tonic-gate 4730Sstevel@tonic-gate while ((sep = sysevent_evc_walk_step(chq)) != NULL) { 4740Sstevel@tonic-gate if ((buf = sysevent_evc_event_attr(sep, &len)) == NULL) 4750Sstevel@tonic-gate break; 4760Sstevel@tonic-gate 4770Sstevel@tonic-gate ed.ed_magic = ERPT_MAGIC; 4780Sstevel@tonic-gate ed.ed_chksum = checksum32(buf, len); 4790Sstevel@tonic-gate ed.ed_size = (uint32_t)len; 4800Sstevel@tonic-gate ed.ed_pad = 0; 4810Sstevel@tonic-gate ed.ed_hrt_nsec = SE_TIME(sep); 4820Sstevel@tonic-gate ed.ed_hrt_base = now; 4830Sstevel@tonic-gate ed.ed_tod_base.sec = tod.tv_sec; 4840Sstevel@tonic-gate ed.ed_tod_base.nsec = tod.tv_nsec; 4850Sstevel@tonic-gate 4860Sstevel@tonic-gate dumpvp_write(&ed, sizeof (ed)); 4870Sstevel@tonic-gate dumpvp_write(buf, len); 4880Sstevel@tonic-gate } 4890Sstevel@tonic-gate 4900Sstevel@tonic-gate sysevent_evc_walk_fini(chq); 4910Sstevel@tonic-gate } 4920Sstevel@tonic-gate 4930Sstevel@tonic-gate /* 4940Sstevel@tonic-gate * Post an error report (ereport) to the sysevent error channel. The error 4950Sstevel@tonic-gate * channel must be established with a prior call to sysevent_evc_create() 4960Sstevel@tonic-gate * before publication may occur. 4970Sstevel@tonic-gate */ 4980Sstevel@tonic-gate void 4990Sstevel@tonic-gate fm_ereport_post(nvlist_t *ereport, int evc_flag) 5000Sstevel@tonic-gate { 5010Sstevel@tonic-gate size_t nvl_size = 0; 5020Sstevel@tonic-gate evchan_t *error_chan; 5030Sstevel@tonic-gate 5040Sstevel@tonic-gate (void) nvlist_size(ereport, &nvl_size, NV_ENCODE_NATIVE); 5050Sstevel@tonic-gate if (nvl_size > ERPT_DATA_SZ || nvl_size == 0) { 5060Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.erpt_dropped.value.ui64, 1); 5070Sstevel@tonic-gate return; 5080Sstevel@tonic-gate } 5090Sstevel@tonic-gate 5100Sstevel@tonic-gate if (sysevent_evc_bind(FM_ERROR_CHAN, &error_chan, 5110Sstevel@tonic-gate EVCH_CREAT|EVCH_HOLD_PEND) != 0) { 5120Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.erpt_dropped.value.ui64, 1); 5130Sstevel@tonic-gate return; 5140Sstevel@tonic-gate } 5150Sstevel@tonic-gate 5160Sstevel@tonic-gate if (sysevent_evc_publish(error_chan, EC_FM, ESC_FM_ERROR, 5170Sstevel@tonic-gate SUNW_VENDOR, FM_PUB, ereport, evc_flag) != 0) { 5180Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.erpt_dropped.value.ui64, 1); 51911102SGavin.Maltby@Sun.COM (void) sysevent_evc_unbind(error_chan); 5200Sstevel@tonic-gate return; 5210Sstevel@tonic-gate } 52211102SGavin.Maltby@Sun.COM (void) sysevent_evc_unbind(error_chan); 5230Sstevel@tonic-gate } 5240Sstevel@tonic-gate 5250Sstevel@tonic-gate /* 5260Sstevel@tonic-gate * Wrapppers for FM nvlist allocators 5270Sstevel@tonic-gate */ 5280Sstevel@tonic-gate /* ARGSUSED */ 5290Sstevel@tonic-gate static void * 5300Sstevel@tonic-gate i_fm_alloc(nv_alloc_t *nva, size_t size) 5310Sstevel@tonic-gate { 5320Sstevel@tonic-gate return (kmem_zalloc(size, KM_SLEEP)); 5330Sstevel@tonic-gate } 5340Sstevel@tonic-gate 5350Sstevel@tonic-gate /* ARGSUSED */ 5360Sstevel@tonic-gate static void 5370Sstevel@tonic-gate i_fm_free(nv_alloc_t *nva, void *buf, size_t size) 5380Sstevel@tonic-gate { 5390Sstevel@tonic-gate kmem_free(buf, size); 5400Sstevel@tonic-gate } 5410Sstevel@tonic-gate 5420Sstevel@tonic-gate const nv_alloc_ops_t fm_mem_alloc_ops = { 5430Sstevel@tonic-gate NULL, 5440Sstevel@tonic-gate NULL, 5450Sstevel@tonic-gate i_fm_alloc, 5460Sstevel@tonic-gate i_fm_free, 5470Sstevel@tonic-gate NULL 5480Sstevel@tonic-gate }; 5490Sstevel@tonic-gate 5500Sstevel@tonic-gate /* 5510Sstevel@tonic-gate * Create and initialize a new nv_alloc_t for a fixed buffer, buf. A pointer 5520Sstevel@tonic-gate * to the newly allocated nv_alloc_t structure is returned upon success or NULL 5530Sstevel@tonic-gate * is returned to indicate that the nv_alloc structure could not be created. 5540Sstevel@tonic-gate */ 5550Sstevel@tonic-gate nv_alloc_t * 5560Sstevel@tonic-gate fm_nva_xcreate(char *buf, size_t bufsz) 5570Sstevel@tonic-gate { 5580Sstevel@tonic-gate nv_alloc_t *nvhdl = kmem_zalloc(sizeof (nv_alloc_t), KM_SLEEP); 5590Sstevel@tonic-gate 5600Sstevel@tonic-gate if (bufsz == 0 || nv_alloc_init(nvhdl, nv_fixed_ops, buf, bufsz) != 0) { 5610Sstevel@tonic-gate kmem_free(nvhdl, sizeof (nv_alloc_t)); 5620Sstevel@tonic-gate return (NULL); 5630Sstevel@tonic-gate } 5640Sstevel@tonic-gate 5650Sstevel@tonic-gate return (nvhdl); 5660Sstevel@tonic-gate } 5670Sstevel@tonic-gate 5680Sstevel@tonic-gate /* 5690Sstevel@tonic-gate * Destroy a previously allocated nv_alloc structure. The fixed buffer 5700Sstevel@tonic-gate * associated with nva must be freed by the caller. 5710Sstevel@tonic-gate */ 5720Sstevel@tonic-gate void 5730Sstevel@tonic-gate fm_nva_xdestroy(nv_alloc_t *nva) 5740Sstevel@tonic-gate { 5750Sstevel@tonic-gate nv_alloc_fini(nva); 5760Sstevel@tonic-gate kmem_free(nva, sizeof (nv_alloc_t)); 5770Sstevel@tonic-gate } 5780Sstevel@tonic-gate 5790Sstevel@tonic-gate /* 5800Sstevel@tonic-gate * Create a new nv list. A pointer to a new nv list structure is returned 5810Sstevel@tonic-gate * upon success or NULL is returned to indicate that the structure could 5820Sstevel@tonic-gate * not be created. The newly created nv list is created and managed by the 5830Sstevel@tonic-gate * operations installed in nva. If nva is NULL, the default FMA nva 5840Sstevel@tonic-gate * operations are installed and used. 5850Sstevel@tonic-gate * 5860Sstevel@tonic-gate * When called from the kernel and nva == NULL, this function must be called 5870Sstevel@tonic-gate * from passive kernel context with no locks held that can prevent a 5880Sstevel@tonic-gate * sleeping memory allocation from occurring. Otherwise, this function may 5890Sstevel@tonic-gate * be called from other kernel contexts as long a valid nva created via 5900Sstevel@tonic-gate * fm_nva_create() is supplied. 5910Sstevel@tonic-gate */ 5920Sstevel@tonic-gate nvlist_t * 5930Sstevel@tonic-gate fm_nvlist_create(nv_alloc_t *nva) 5940Sstevel@tonic-gate { 5950Sstevel@tonic-gate int hdl_alloced = 0; 5960Sstevel@tonic-gate nvlist_t *nvl; 5970Sstevel@tonic-gate nv_alloc_t *nvhdl; 5980Sstevel@tonic-gate 5990Sstevel@tonic-gate if (nva == NULL) { 6000Sstevel@tonic-gate nvhdl = kmem_zalloc(sizeof (nv_alloc_t), KM_SLEEP); 6010Sstevel@tonic-gate 6020Sstevel@tonic-gate if (nv_alloc_init(nvhdl, &fm_mem_alloc_ops, NULL, 0) != 0) { 6030Sstevel@tonic-gate kmem_free(nvhdl, sizeof (nv_alloc_t)); 6040Sstevel@tonic-gate return (NULL); 6050Sstevel@tonic-gate } 6060Sstevel@tonic-gate hdl_alloced = 1; 6070Sstevel@tonic-gate } else { 6080Sstevel@tonic-gate nvhdl = nva; 6090Sstevel@tonic-gate } 6100Sstevel@tonic-gate 6110Sstevel@tonic-gate if (nvlist_xalloc(&nvl, NV_UNIQUE_NAME, nvhdl) != 0) { 6120Sstevel@tonic-gate if (hdl_alloced) { 613*12726SJakub.Jermar@Sun.COM nv_alloc_fini(nvhdl); 6140Sstevel@tonic-gate kmem_free(nvhdl, sizeof (nv_alloc_t)); 6150Sstevel@tonic-gate } 6160Sstevel@tonic-gate return (NULL); 6170Sstevel@tonic-gate } 6180Sstevel@tonic-gate 6190Sstevel@tonic-gate return (nvl); 6200Sstevel@tonic-gate } 6210Sstevel@tonic-gate 6220Sstevel@tonic-gate /* 6230Sstevel@tonic-gate * Destroy a previously allocated nvlist structure. flag indicates whether 6240Sstevel@tonic-gate * or not the associated nva structure should be freed (FM_NVA_FREE) or 6250Sstevel@tonic-gate * retained (FM_NVA_RETAIN). Retaining the nv alloc structure allows 6260Sstevel@tonic-gate * it to be re-used for future nvlist creation operations. 6270Sstevel@tonic-gate */ 6280Sstevel@tonic-gate void 6290Sstevel@tonic-gate fm_nvlist_destroy(nvlist_t *nvl, int flag) 6300Sstevel@tonic-gate { 6311414Scindi nv_alloc_t *nva = nvlist_lookup_nv_alloc(nvl); 6320Sstevel@tonic-gate 6330Sstevel@tonic-gate nvlist_free(nvl); 6340Sstevel@tonic-gate 6351414Scindi if (nva != NULL) { 6360Sstevel@tonic-gate if (flag == FM_NVA_FREE) 6371414Scindi fm_nva_xdestroy(nva); 6380Sstevel@tonic-gate } 6390Sstevel@tonic-gate } 6400Sstevel@tonic-gate 6410Sstevel@tonic-gate int 6420Sstevel@tonic-gate i_fm_payload_set(nvlist_t *payload, const char *name, va_list ap) 6430Sstevel@tonic-gate { 6440Sstevel@tonic-gate int nelem, ret = 0; 6450Sstevel@tonic-gate data_type_t type; 6460Sstevel@tonic-gate 6470Sstevel@tonic-gate while (ret == 0 && name != NULL) { 6480Sstevel@tonic-gate type = va_arg(ap, data_type_t); 6490Sstevel@tonic-gate switch (type) { 6500Sstevel@tonic-gate case DATA_TYPE_BYTE: 6510Sstevel@tonic-gate ret = nvlist_add_byte(payload, name, 6520Sstevel@tonic-gate va_arg(ap, uint_t)); 6530Sstevel@tonic-gate break; 6540Sstevel@tonic-gate case DATA_TYPE_BYTE_ARRAY: 6550Sstevel@tonic-gate nelem = va_arg(ap, int); 6560Sstevel@tonic-gate ret = nvlist_add_byte_array(payload, name, 6570Sstevel@tonic-gate va_arg(ap, uchar_t *), nelem); 6580Sstevel@tonic-gate break; 6590Sstevel@tonic-gate case DATA_TYPE_BOOLEAN_VALUE: 6600Sstevel@tonic-gate ret = nvlist_add_boolean_value(payload, name, 6610Sstevel@tonic-gate va_arg(ap, boolean_t)); 6620Sstevel@tonic-gate break; 6630Sstevel@tonic-gate case DATA_TYPE_BOOLEAN_ARRAY: 6640Sstevel@tonic-gate nelem = va_arg(ap, int); 6650Sstevel@tonic-gate ret = nvlist_add_boolean_array(payload, name, 6660Sstevel@tonic-gate va_arg(ap, boolean_t *), nelem); 6670Sstevel@tonic-gate break; 6680Sstevel@tonic-gate case DATA_TYPE_INT8: 6690Sstevel@tonic-gate ret = nvlist_add_int8(payload, name, 6700Sstevel@tonic-gate va_arg(ap, int)); 6710Sstevel@tonic-gate break; 6720Sstevel@tonic-gate case DATA_TYPE_INT8_ARRAY: 6730Sstevel@tonic-gate nelem = va_arg(ap, int); 6740Sstevel@tonic-gate ret = nvlist_add_int8_array(payload, name, 6750Sstevel@tonic-gate va_arg(ap, int8_t *), nelem); 6760Sstevel@tonic-gate break; 6770Sstevel@tonic-gate case DATA_TYPE_UINT8: 6780Sstevel@tonic-gate ret = nvlist_add_uint8(payload, name, 6790Sstevel@tonic-gate va_arg(ap, uint_t)); 6800Sstevel@tonic-gate break; 6810Sstevel@tonic-gate case DATA_TYPE_UINT8_ARRAY: 6820Sstevel@tonic-gate nelem = va_arg(ap, int); 6830Sstevel@tonic-gate ret = nvlist_add_uint8_array(payload, name, 6840Sstevel@tonic-gate va_arg(ap, uint8_t *), nelem); 6850Sstevel@tonic-gate break; 6860Sstevel@tonic-gate case DATA_TYPE_INT16: 6870Sstevel@tonic-gate ret = nvlist_add_int16(payload, name, 6880Sstevel@tonic-gate va_arg(ap, int)); 6890Sstevel@tonic-gate break; 6900Sstevel@tonic-gate case DATA_TYPE_INT16_ARRAY: 6910Sstevel@tonic-gate nelem = va_arg(ap, int); 6920Sstevel@tonic-gate ret = nvlist_add_int16_array(payload, name, 6930Sstevel@tonic-gate va_arg(ap, int16_t *), nelem); 6940Sstevel@tonic-gate break; 6950Sstevel@tonic-gate case DATA_TYPE_UINT16: 6960Sstevel@tonic-gate ret = nvlist_add_uint16(payload, name, 6970Sstevel@tonic-gate va_arg(ap, uint_t)); 6980Sstevel@tonic-gate break; 6990Sstevel@tonic-gate case DATA_TYPE_UINT16_ARRAY: 7000Sstevel@tonic-gate nelem = va_arg(ap, int); 7010Sstevel@tonic-gate ret = nvlist_add_uint16_array(payload, name, 7020Sstevel@tonic-gate va_arg(ap, uint16_t *), nelem); 7030Sstevel@tonic-gate break; 7040Sstevel@tonic-gate case DATA_TYPE_INT32: 7050Sstevel@tonic-gate ret = nvlist_add_int32(payload, name, 7060Sstevel@tonic-gate va_arg(ap, int32_t)); 7070Sstevel@tonic-gate break; 7080Sstevel@tonic-gate case DATA_TYPE_INT32_ARRAY: 7090Sstevel@tonic-gate nelem = va_arg(ap, int); 7100Sstevel@tonic-gate ret = nvlist_add_int32_array(payload, name, 7110Sstevel@tonic-gate va_arg(ap, int32_t *), nelem); 7120Sstevel@tonic-gate break; 7130Sstevel@tonic-gate case DATA_TYPE_UINT32: 7140Sstevel@tonic-gate ret = nvlist_add_uint32(payload, name, 7150Sstevel@tonic-gate va_arg(ap, uint32_t)); 7160Sstevel@tonic-gate break; 7170Sstevel@tonic-gate case DATA_TYPE_UINT32_ARRAY: 7180Sstevel@tonic-gate nelem = va_arg(ap, int); 7190Sstevel@tonic-gate ret = nvlist_add_uint32_array(payload, name, 7200Sstevel@tonic-gate va_arg(ap, uint32_t *), nelem); 7210Sstevel@tonic-gate break; 7220Sstevel@tonic-gate case DATA_TYPE_INT64: 7230Sstevel@tonic-gate ret = nvlist_add_int64(payload, name, 7240Sstevel@tonic-gate va_arg(ap, int64_t)); 7250Sstevel@tonic-gate break; 7260Sstevel@tonic-gate case DATA_TYPE_INT64_ARRAY: 7270Sstevel@tonic-gate nelem = va_arg(ap, int); 7280Sstevel@tonic-gate ret = nvlist_add_int64_array(payload, name, 7290Sstevel@tonic-gate va_arg(ap, int64_t *), nelem); 7300Sstevel@tonic-gate break; 7310Sstevel@tonic-gate case DATA_TYPE_UINT64: 7320Sstevel@tonic-gate ret = nvlist_add_uint64(payload, name, 7330Sstevel@tonic-gate va_arg(ap, uint64_t)); 7340Sstevel@tonic-gate break; 7350Sstevel@tonic-gate case DATA_TYPE_UINT64_ARRAY: 7360Sstevel@tonic-gate nelem = va_arg(ap, int); 7370Sstevel@tonic-gate ret = nvlist_add_uint64_array(payload, name, 7380Sstevel@tonic-gate va_arg(ap, uint64_t *), nelem); 7390Sstevel@tonic-gate break; 7400Sstevel@tonic-gate case DATA_TYPE_STRING: 7410Sstevel@tonic-gate ret = nvlist_add_string(payload, name, 7420Sstevel@tonic-gate va_arg(ap, char *)); 7430Sstevel@tonic-gate break; 7440Sstevel@tonic-gate case DATA_TYPE_STRING_ARRAY: 7450Sstevel@tonic-gate nelem = va_arg(ap, int); 7460Sstevel@tonic-gate ret = nvlist_add_string_array(payload, name, 7470Sstevel@tonic-gate va_arg(ap, char **), nelem); 7480Sstevel@tonic-gate break; 7490Sstevel@tonic-gate case DATA_TYPE_NVLIST: 7500Sstevel@tonic-gate ret = nvlist_add_nvlist(payload, name, 7510Sstevel@tonic-gate va_arg(ap, nvlist_t *)); 7520Sstevel@tonic-gate break; 7530Sstevel@tonic-gate case DATA_TYPE_NVLIST_ARRAY: 7540Sstevel@tonic-gate nelem = va_arg(ap, int); 7550Sstevel@tonic-gate ret = nvlist_add_nvlist_array(payload, name, 7560Sstevel@tonic-gate va_arg(ap, nvlist_t **), nelem); 7570Sstevel@tonic-gate break; 7580Sstevel@tonic-gate default: 7590Sstevel@tonic-gate ret = EINVAL; 7600Sstevel@tonic-gate } 7610Sstevel@tonic-gate 7620Sstevel@tonic-gate name = va_arg(ap, char *); 7630Sstevel@tonic-gate } 7640Sstevel@tonic-gate return (ret); 7650Sstevel@tonic-gate } 7660Sstevel@tonic-gate 7670Sstevel@tonic-gate void 7680Sstevel@tonic-gate fm_payload_set(nvlist_t *payload, ...) 7690Sstevel@tonic-gate { 7700Sstevel@tonic-gate int ret; 7710Sstevel@tonic-gate const char *name; 7720Sstevel@tonic-gate va_list ap; 7730Sstevel@tonic-gate 7740Sstevel@tonic-gate va_start(ap, payload); 7750Sstevel@tonic-gate name = va_arg(ap, char *); 7760Sstevel@tonic-gate ret = i_fm_payload_set(payload, name, ap); 7770Sstevel@tonic-gate va_end(ap); 7780Sstevel@tonic-gate 7790Sstevel@tonic-gate if (ret) 7800Sstevel@tonic-gate atomic_add_64( 7810Sstevel@tonic-gate &erpt_kstat_data.payload_set_failed.value.ui64, 1); 7820Sstevel@tonic-gate } 7830Sstevel@tonic-gate 7840Sstevel@tonic-gate /* 7850Sstevel@tonic-gate * Set-up and validate the members of an ereport event according to: 7860Sstevel@tonic-gate * 7870Sstevel@tonic-gate * Member name Type Value 7880Sstevel@tonic-gate * ==================================================== 7890Sstevel@tonic-gate * class string ereport 7900Sstevel@tonic-gate * version uint8_t 0 7910Sstevel@tonic-gate * ena uint64_t <ena> 7920Sstevel@tonic-gate * detector nvlist_t <detector> 7930Sstevel@tonic-gate * ereport-payload nvlist_t <var args> 7940Sstevel@tonic-gate * 79512213SGavin.Maltby@Sun.COM * We don't actually add a 'version' member to the payload. Really, 79612213SGavin.Maltby@Sun.COM * the version quoted to us by our caller is that of the category 1 79712213SGavin.Maltby@Sun.COM * "ereport" event class (and we require FM_EREPORT_VERS0) but 79812213SGavin.Maltby@Sun.COM * the payload version of the actual leaf class event under construction 79912213SGavin.Maltby@Sun.COM * may be something else. Callers should supply a version in the varargs, 80012213SGavin.Maltby@Sun.COM * or (better) we could take two version arguments - one for the 80112213SGavin.Maltby@Sun.COM * ereport category 1 classification (expect FM_EREPORT_VERS0) and one 80212213SGavin.Maltby@Sun.COM * for the leaf class. 8030Sstevel@tonic-gate */ 8040Sstevel@tonic-gate void 8050Sstevel@tonic-gate fm_ereport_set(nvlist_t *ereport, int version, const char *erpt_class, 8060Sstevel@tonic-gate uint64_t ena, const nvlist_t *detector, ...) 8070Sstevel@tonic-gate { 8080Sstevel@tonic-gate char ereport_class[FM_MAX_CLASS]; 8090Sstevel@tonic-gate const char *name; 8100Sstevel@tonic-gate va_list ap; 8110Sstevel@tonic-gate int ret; 8120Sstevel@tonic-gate 8130Sstevel@tonic-gate if (version != FM_EREPORT_VERS0) { 8140Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1); 8150Sstevel@tonic-gate return; 8160Sstevel@tonic-gate } 8170Sstevel@tonic-gate 8180Sstevel@tonic-gate (void) snprintf(ereport_class, FM_MAX_CLASS, "%s.%s", 8190Sstevel@tonic-gate FM_EREPORT_CLASS, erpt_class); 8200Sstevel@tonic-gate if (nvlist_add_string(ereport, FM_CLASS, ereport_class) != 0) { 8210Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1); 8220Sstevel@tonic-gate return; 8230Sstevel@tonic-gate } 8240Sstevel@tonic-gate 8250Sstevel@tonic-gate if (nvlist_add_uint64(ereport, FM_EREPORT_ENA, ena)) { 8260Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1); 8270Sstevel@tonic-gate } 8280Sstevel@tonic-gate 8290Sstevel@tonic-gate if (nvlist_add_nvlist(ereport, FM_EREPORT_DETECTOR, 8300Sstevel@tonic-gate (nvlist_t *)detector) != 0) { 8310Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1); 8320Sstevel@tonic-gate } 8330Sstevel@tonic-gate 8340Sstevel@tonic-gate va_start(ap, detector); 8350Sstevel@tonic-gate name = va_arg(ap, const char *); 8360Sstevel@tonic-gate ret = i_fm_payload_set(ereport, name, ap); 8370Sstevel@tonic-gate va_end(ap); 8380Sstevel@tonic-gate 8390Sstevel@tonic-gate if (ret) 8400Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1); 8410Sstevel@tonic-gate } 8420Sstevel@tonic-gate 8431414Scindi /* 8441414Scindi * Set-up and validate the members of an hc fmri according to; 8451414Scindi * 8461414Scindi * Member name Type Value 8471414Scindi * =================================================== 8481414Scindi * version uint8_t 0 8491414Scindi * auth nvlist_t <auth> 8501414Scindi * hc-name string <name> 8511414Scindi * hc-id string <id> 8521414Scindi * 8531414Scindi * Note that auth and hc-id are optional members. 8541414Scindi */ 8550Sstevel@tonic-gate 8561414Scindi #define HC_MAXPAIRS 20 8571414Scindi #define HC_MAXNAMELEN 50 8580Sstevel@tonic-gate 8591414Scindi static int 8601414Scindi fm_fmri_hc_set_common(nvlist_t *fmri, int version, const nvlist_t *auth) 8611414Scindi { 8621414Scindi if (version != FM_HC_SCHEME_VERSION) { 8631414Scindi atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 8641414Scindi return (0); 8651414Scindi } 8661414Scindi 8671414Scindi if (nvlist_add_uint8(fmri, FM_VERSION, version) != 0 || 8681414Scindi nvlist_add_string(fmri, FM_FMRI_SCHEME, FM_FMRI_SCHEME_HC) != 0) { 8691414Scindi atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 8701414Scindi return (0); 8711414Scindi } 8721414Scindi 8731414Scindi if (auth != NULL && nvlist_add_nvlist(fmri, FM_FMRI_AUTHORITY, 8741414Scindi (nvlist_t *)auth) != 0) { 8751414Scindi atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 8761414Scindi return (0); 8770Sstevel@tonic-gate } 8780Sstevel@tonic-gate 8791414Scindi return (1); 8801414Scindi } 8810Sstevel@tonic-gate 8821414Scindi void 8831414Scindi fm_fmri_hc_set(nvlist_t *fmri, int version, const nvlist_t *auth, 8841414Scindi nvlist_t *snvl, int npairs, ...) 8851414Scindi { 8861414Scindi nv_alloc_t *nva = nvlist_lookup_nv_alloc(fmri); 8871414Scindi nvlist_t *pairs[HC_MAXPAIRS]; 8881414Scindi va_list ap; 8891414Scindi int i; 8901414Scindi 8911414Scindi if (!fm_fmri_hc_set_common(fmri, version, auth)) 8921414Scindi return; 8931414Scindi 8941414Scindi npairs = MIN(npairs, HC_MAXPAIRS); 8951414Scindi 8961414Scindi va_start(ap, npairs); 8971414Scindi for (i = 0; i < npairs; i++) { 8981414Scindi const char *name = va_arg(ap, const char *); 8991414Scindi uint32_t id = va_arg(ap, uint32_t); 9001414Scindi char idstr[11]; 9010Sstevel@tonic-gate 9021414Scindi (void) snprintf(idstr, sizeof (idstr), "%u", id); 9031414Scindi 9041414Scindi pairs[i] = fm_nvlist_create(nva); 9051414Scindi if (nvlist_add_string(pairs[i], FM_FMRI_HC_NAME, name) != 0 || 9061414Scindi nvlist_add_string(pairs[i], FM_FMRI_HC_ID, idstr) != 0) { 9071414Scindi atomic_add_64( 9081414Scindi &erpt_kstat_data.fmri_set_failed.value.ui64, 1); 9091414Scindi } 9100Sstevel@tonic-gate } 9111414Scindi va_end(ap); 9120Sstevel@tonic-gate 9131414Scindi if (nvlist_add_nvlist_array(fmri, FM_FMRI_HC_LIST, pairs, npairs) != 0) 9141414Scindi atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 9151414Scindi 9161414Scindi for (i = 0; i < npairs; i++) 9171414Scindi fm_nvlist_destroy(pairs[i], FM_NVA_RETAIN); 9181414Scindi 9191414Scindi if (snvl != NULL) { 9201414Scindi if (nvlist_add_nvlist(fmri, FM_FMRI_HC_SPECIFIC, snvl) != 0) { 9211414Scindi atomic_add_64( 9221414Scindi &erpt_kstat_data.fmri_set_failed.value.ui64, 1); 9231414Scindi } 9241414Scindi } 9250Sstevel@tonic-gate } 9260Sstevel@tonic-gate 9270Sstevel@tonic-gate /* 9280Sstevel@tonic-gate * Set-up and validate the members of an dev fmri according to: 9290Sstevel@tonic-gate * 9300Sstevel@tonic-gate * Member name Type Value 9310Sstevel@tonic-gate * ==================================================== 9320Sstevel@tonic-gate * version uint8_t 0 9330Sstevel@tonic-gate * auth nvlist_t <auth> 9340Sstevel@tonic-gate * devpath string <devpath> 93512213SGavin.Maltby@Sun.COM * [devid] string <devid> 93612213SGavin.Maltby@Sun.COM * [target-port-l0id] string <target-port-lun0-id> 9370Sstevel@tonic-gate * 9380Sstevel@tonic-gate * Note that auth and devid are optional members. 9390Sstevel@tonic-gate */ 9400Sstevel@tonic-gate void 9410Sstevel@tonic-gate fm_fmri_dev_set(nvlist_t *fmri_dev, int version, const nvlist_t *auth, 94212213SGavin.Maltby@Sun.COM const char *devpath, const char *devid, const char *tpl0) 9430Sstevel@tonic-gate { 94412213SGavin.Maltby@Sun.COM int err = 0; 94512213SGavin.Maltby@Sun.COM 9460Sstevel@tonic-gate if (version != DEV_SCHEME_VERSION0) { 9470Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 9480Sstevel@tonic-gate return; 9490Sstevel@tonic-gate } 9500Sstevel@tonic-gate 95112213SGavin.Maltby@Sun.COM err |= nvlist_add_uint8(fmri_dev, FM_VERSION, version); 95212213SGavin.Maltby@Sun.COM err |= nvlist_add_string(fmri_dev, FM_FMRI_SCHEME, FM_FMRI_SCHEME_DEV); 9530Sstevel@tonic-gate 9540Sstevel@tonic-gate if (auth != NULL) { 95512213SGavin.Maltby@Sun.COM err |= nvlist_add_nvlist(fmri_dev, FM_FMRI_AUTHORITY, 95612213SGavin.Maltby@Sun.COM (nvlist_t *)auth); 9570Sstevel@tonic-gate } 9580Sstevel@tonic-gate 95912213SGavin.Maltby@Sun.COM err |= nvlist_add_string(fmri_dev, FM_FMRI_DEV_PATH, devpath); 9600Sstevel@tonic-gate 9610Sstevel@tonic-gate if (devid != NULL) 96212213SGavin.Maltby@Sun.COM err |= nvlist_add_string(fmri_dev, FM_FMRI_DEV_ID, devid); 96312213SGavin.Maltby@Sun.COM 96412213SGavin.Maltby@Sun.COM if (tpl0 != NULL) 96512213SGavin.Maltby@Sun.COM err |= nvlist_add_string(fmri_dev, FM_FMRI_DEV_TGTPTLUN0, tpl0); 96612213SGavin.Maltby@Sun.COM 96712213SGavin.Maltby@Sun.COM if (err) 96812213SGavin.Maltby@Sun.COM atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 96912213SGavin.Maltby@Sun.COM 9700Sstevel@tonic-gate } 9710Sstevel@tonic-gate 9720Sstevel@tonic-gate /* 9730Sstevel@tonic-gate * Set-up and validate the members of an cpu fmri according to: 9740Sstevel@tonic-gate * 9750Sstevel@tonic-gate * Member name Type Value 9760Sstevel@tonic-gate * ==================================================== 9770Sstevel@tonic-gate * version uint8_t 0 9780Sstevel@tonic-gate * auth nvlist_t <auth> 9790Sstevel@tonic-gate * cpuid uint32_t <cpu_id> 9800Sstevel@tonic-gate * cpumask uint8_t <cpu_mask> 9810Sstevel@tonic-gate * serial uint64_t <serial_id> 9820Sstevel@tonic-gate * 9831414Scindi * Note that auth, cpumask, serial are optional members. 9840Sstevel@tonic-gate * 9850Sstevel@tonic-gate */ 9860Sstevel@tonic-gate void 9870Sstevel@tonic-gate fm_fmri_cpu_set(nvlist_t *fmri_cpu, int version, const nvlist_t *auth, 9881414Scindi uint32_t cpu_id, uint8_t *cpu_maskp, const char *serial_idp) 9890Sstevel@tonic-gate { 9901414Scindi uint64_t *failedp = &erpt_kstat_data.fmri_set_failed.value.ui64; 9911414Scindi 9921414Scindi if (version < CPU_SCHEME_VERSION1) { 9931414Scindi atomic_add_64(failedp, 1); 9940Sstevel@tonic-gate return; 9950Sstevel@tonic-gate } 9960Sstevel@tonic-gate 9970Sstevel@tonic-gate if (nvlist_add_uint8(fmri_cpu, FM_VERSION, version) != 0) { 9981414Scindi atomic_add_64(failedp, 1); 9990Sstevel@tonic-gate return; 10000Sstevel@tonic-gate } 10010Sstevel@tonic-gate 10020Sstevel@tonic-gate if (nvlist_add_string(fmri_cpu, FM_FMRI_SCHEME, 10030Sstevel@tonic-gate FM_FMRI_SCHEME_CPU) != 0) { 10041414Scindi atomic_add_64(failedp, 1); 10050Sstevel@tonic-gate return; 10060Sstevel@tonic-gate } 10070Sstevel@tonic-gate 10081414Scindi if (auth != NULL && nvlist_add_nvlist(fmri_cpu, FM_FMRI_AUTHORITY, 10091414Scindi (nvlist_t *)auth) != 0) 10101414Scindi atomic_add_64(failedp, 1); 10111414Scindi 10121414Scindi if (nvlist_add_uint32(fmri_cpu, FM_FMRI_CPU_ID, cpu_id) != 0) 10131414Scindi atomic_add_64(failedp, 1); 10140Sstevel@tonic-gate 10151414Scindi if (cpu_maskp != NULL && nvlist_add_uint8(fmri_cpu, FM_FMRI_CPU_MASK, 10161414Scindi *cpu_maskp) != 0) 10171414Scindi atomic_add_64(failedp, 1); 10180Sstevel@tonic-gate 10191414Scindi if (serial_idp == NULL || nvlist_add_string(fmri_cpu, 10201414Scindi FM_FMRI_CPU_SERIAL_ID, (char *)serial_idp) != 0) 10211414Scindi atomic_add_64(failedp, 1); 10220Sstevel@tonic-gate } 10230Sstevel@tonic-gate 10240Sstevel@tonic-gate /* 10250Sstevel@tonic-gate * Set-up and validate the members of a mem according to: 10260Sstevel@tonic-gate * 10270Sstevel@tonic-gate * Member name Type Value 10280Sstevel@tonic-gate * ==================================================== 10290Sstevel@tonic-gate * version uint8_t 0 10300Sstevel@tonic-gate * auth nvlist_t <auth> [optional] 10310Sstevel@tonic-gate * unum string <unum> 10321186Sayznaga * serial string <serial> [optional*] 10331186Sayznaga * offset uint64_t <offset> [optional] 10340Sstevel@tonic-gate * 10351186Sayznaga * * serial is required if offset is present 10360Sstevel@tonic-gate */ 10370Sstevel@tonic-gate void 10380Sstevel@tonic-gate fm_fmri_mem_set(nvlist_t *fmri, int version, const nvlist_t *auth, 10391186Sayznaga const char *unum, const char *serial, uint64_t offset) 10400Sstevel@tonic-gate { 10410Sstevel@tonic-gate if (version != MEM_SCHEME_VERSION0) { 10420Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 10430Sstevel@tonic-gate return; 10440Sstevel@tonic-gate } 10450Sstevel@tonic-gate 10461186Sayznaga if (!serial && (offset != (uint64_t)-1)) { 10471186Sayznaga atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 10481186Sayznaga return; 10491186Sayznaga } 10501186Sayznaga 10510Sstevel@tonic-gate if (nvlist_add_uint8(fmri, FM_VERSION, version) != 0) { 10520Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 10530Sstevel@tonic-gate return; 10540Sstevel@tonic-gate } 10550Sstevel@tonic-gate 10560Sstevel@tonic-gate if (nvlist_add_string(fmri, FM_FMRI_SCHEME, FM_FMRI_SCHEME_MEM) != 0) { 10570Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 10580Sstevel@tonic-gate return; 10590Sstevel@tonic-gate } 10600Sstevel@tonic-gate 10610Sstevel@tonic-gate if (auth != NULL) { 10620Sstevel@tonic-gate if (nvlist_add_nvlist(fmri, FM_FMRI_AUTHORITY, 10630Sstevel@tonic-gate (nvlist_t *)auth) != 0) { 10640Sstevel@tonic-gate atomic_add_64( 10650Sstevel@tonic-gate &erpt_kstat_data.fmri_set_failed.value.ui64, 1); 10660Sstevel@tonic-gate } 10670Sstevel@tonic-gate } 10680Sstevel@tonic-gate 10690Sstevel@tonic-gate if (nvlist_add_string(fmri, FM_FMRI_MEM_UNUM, unum) != 0) { 10700Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 10710Sstevel@tonic-gate } 10720Sstevel@tonic-gate 10730Sstevel@tonic-gate if (serial != NULL) { 10740Sstevel@tonic-gate if (nvlist_add_string_array(fmri, FM_FMRI_MEM_SERIAL_ID, 10750Sstevel@tonic-gate (char **)&serial, 1) != 0) { 10760Sstevel@tonic-gate atomic_add_64( 10770Sstevel@tonic-gate &erpt_kstat_data.fmri_set_failed.value.ui64, 1); 10780Sstevel@tonic-gate } 10791186Sayznaga if (offset != (uint64_t)-1) { 10801186Sayznaga if (nvlist_add_uint64(fmri, FM_FMRI_MEM_OFFSET, 10811186Sayznaga offset) != 0) { 10821186Sayznaga atomic_add_64(&erpt_kstat_data. 10831186Sayznaga fmri_set_failed.value.ui64, 1); 10841186Sayznaga } 10851186Sayznaga } 10860Sstevel@tonic-gate } 10870Sstevel@tonic-gate } 10880Sstevel@tonic-gate 10891544Seschrock void 10901544Seschrock fm_fmri_zfs_set(nvlist_t *fmri, int version, uint64_t pool_guid, 10911544Seschrock uint64_t vdev_guid) 10921544Seschrock { 10931544Seschrock if (version != ZFS_SCHEME_VERSION0) { 10941544Seschrock atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 10951544Seschrock return; 10961544Seschrock } 10971544Seschrock 10981544Seschrock if (nvlist_add_uint8(fmri, FM_VERSION, version) != 0) { 10991544Seschrock atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 11001544Seschrock return; 11011544Seschrock } 11021544Seschrock 11031544Seschrock if (nvlist_add_string(fmri, FM_FMRI_SCHEME, FM_FMRI_SCHEME_ZFS) != 0) { 11041544Seschrock atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 11051544Seschrock return; 11061544Seschrock } 11071544Seschrock 11081544Seschrock if (nvlist_add_uint64(fmri, FM_FMRI_ZFS_POOL, pool_guid) != 0) { 11091544Seschrock atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 11101544Seschrock } 11111544Seschrock 11121544Seschrock if (vdev_guid != 0) { 11131544Seschrock if (nvlist_add_uint64(fmri, FM_FMRI_ZFS_VDEV, vdev_guid) != 0) { 11141544Seschrock atomic_add_64( 11151544Seschrock &erpt_kstat_data.fmri_set_failed.value.ui64, 1); 11161544Seschrock } 11171544Seschrock } 11181544Seschrock } 11191544Seschrock 11200Sstevel@tonic-gate uint64_t 11210Sstevel@tonic-gate fm_ena_increment(uint64_t ena) 11220Sstevel@tonic-gate { 11230Sstevel@tonic-gate uint64_t new_ena; 11240Sstevel@tonic-gate 11250Sstevel@tonic-gate switch (ENA_FORMAT(ena)) { 11260Sstevel@tonic-gate case FM_ENA_FMT1: 11270Sstevel@tonic-gate new_ena = ena + (1 << ENA_FMT1_GEN_SHFT); 11280Sstevel@tonic-gate break; 11290Sstevel@tonic-gate case FM_ENA_FMT2: 11300Sstevel@tonic-gate new_ena = ena + (1 << ENA_FMT2_GEN_SHFT); 11310Sstevel@tonic-gate break; 11320Sstevel@tonic-gate default: 11330Sstevel@tonic-gate new_ena = 0; 11340Sstevel@tonic-gate } 11350Sstevel@tonic-gate 11360Sstevel@tonic-gate return (new_ena); 11370Sstevel@tonic-gate } 11380Sstevel@tonic-gate 11390Sstevel@tonic-gate uint64_t 11400Sstevel@tonic-gate fm_ena_generate_cpu(uint64_t timestamp, processorid_t cpuid, uchar_t format) 11410Sstevel@tonic-gate { 11420Sstevel@tonic-gate uint64_t ena = 0; 11430Sstevel@tonic-gate 11440Sstevel@tonic-gate switch (format) { 11450Sstevel@tonic-gate case FM_ENA_FMT1: 11460Sstevel@tonic-gate if (timestamp) { 11470Sstevel@tonic-gate ena = (uint64_t)((format & ENA_FORMAT_MASK) | 11480Sstevel@tonic-gate ((cpuid << ENA_FMT1_CPUID_SHFT) & 11490Sstevel@tonic-gate ENA_FMT1_CPUID_MASK) | 11500Sstevel@tonic-gate ((timestamp << ENA_FMT1_TIME_SHFT) & 11510Sstevel@tonic-gate ENA_FMT1_TIME_MASK)); 11520Sstevel@tonic-gate } else { 11530Sstevel@tonic-gate ena = (uint64_t)((format & ENA_FORMAT_MASK) | 11540Sstevel@tonic-gate ((cpuid << ENA_FMT1_CPUID_SHFT) & 11550Sstevel@tonic-gate ENA_FMT1_CPUID_MASK) | 11560Sstevel@tonic-gate ((gethrtime_waitfree() << ENA_FMT1_TIME_SHFT) & 11570Sstevel@tonic-gate ENA_FMT1_TIME_MASK)); 11580Sstevel@tonic-gate } 11590Sstevel@tonic-gate break; 11600Sstevel@tonic-gate case FM_ENA_FMT2: 11610Sstevel@tonic-gate ena = (uint64_t)((format & ENA_FORMAT_MASK) | 11620Sstevel@tonic-gate ((timestamp << ENA_FMT2_TIME_SHFT) & ENA_FMT2_TIME_MASK)); 11630Sstevel@tonic-gate break; 11640Sstevel@tonic-gate default: 11650Sstevel@tonic-gate break; 11660Sstevel@tonic-gate } 11670Sstevel@tonic-gate 11680Sstevel@tonic-gate return (ena); 11690Sstevel@tonic-gate } 11700Sstevel@tonic-gate 11710Sstevel@tonic-gate uint64_t 11720Sstevel@tonic-gate fm_ena_generate(uint64_t timestamp, uchar_t format) 11730Sstevel@tonic-gate { 11740Sstevel@tonic-gate return (fm_ena_generate_cpu(timestamp, CPU->cpu_id, format)); 11750Sstevel@tonic-gate } 11760Sstevel@tonic-gate 11770Sstevel@tonic-gate uint64_t 11780Sstevel@tonic-gate fm_ena_generation_get(uint64_t ena) 11790Sstevel@tonic-gate { 11800Sstevel@tonic-gate uint64_t gen; 11810Sstevel@tonic-gate 11820Sstevel@tonic-gate switch (ENA_FORMAT(ena)) { 11830Sstevel@tonic-gate case FM_ENA_FMT1: 11840Sstevel@tonic-gate gen = (ena & ENA_FMT1_GEN_MASK) >> ENA_FMT1_GEN_SHFT; 11850Sstevel@tonic-gate break; 11860Sstevel@tonic-gate case FM_ENA_FMT2: 11870Sstevel@tonic-gate gen = (ena & ENA_FMT2_GEN_MASK) >> ENA_FMT2_GEN_SHFT; 11880Sstevel@tonic-gate break; 11890Sstevel@tonic-gate default: 11900Sstevel@tonic-gate gen = 0; 11910Sstevel@tonic-gate break; 11920Sstevel@tonic-gate } 11930Sstevel@tonic-gate 11940Sstevel@tonic-gate return (gen); 11950Sstevel@tonic-gate } 11960Sstevel@tonic-gate 11970Sstevel@tonic-gate uchar_t 11980Sstevel@tonic-gate fm_ena_format_get(uint64_t ena) 11990Sstevel@tonic-gate { 12000Sstevel@tonic-gate 12010Sstevel@tonic-gate return (ENA_FORMAT(ena)); 12020Sstevel@tonic-gate } 12030Sstevel@tonic-gate 12040Sstevel@tonic-gate uint64_t 12050Sstevel@tonic-gate fm_ena_id_get(uint64_t ena) 12060Sstevel@tonic-gate { 12070Sstevel@tonic-gate uint64_t id; 12080Sstevel@tonic-gate 12090Sstevel@tonic-gate switch (ENA_FORMAT(ena)) { 12100Sstevel@tonic-gate case FM_ENA_FMT1: 12110Sstevel@tonic-gate id = (ena & ENA_FMT1_ID_MASK) >> ENA_FMT1_ID_SHFT; 12120Sstevel@tonic-gate break; 12130Sstevel@tonic-gate case FM_ENA_FMT2: 12140Sstevel@tonic-gate id = (ena & ENA_FMT2_ID_MASK) >> ENA_FMT2_ID_SHFT; 12150Sstevel@tonic-gate break; 12160Sstevel@tonic-gate default: 12170Sstevel@tonic-gate id = 0; 12180Sstevel@tonic-gate } 12190Sstevel@tonic-gate 12200Sstevel@tonic-gate return (id); 12210Sstevel@tonic-gate } 12220Sstevel@tonic-gate 12230Sstevel@tonic-gate uint64_t 12240Sstevel@tonic-gate fm_ena_time_get(uint64_t ena) 12250Sstevel@tonic-gate { 12260Sstevel@tonic-gate uint64_t time; 12270Sstevel@tonic-gate 12280Sstevel@tonic-gate switch (ENA_FORMAT(ena)) { 12290Sstevel@tonic-gate case FM_ENA_FMT1: 12300Sstevel@tonic-gate time = (ena & ENA_FMT1_TIME_MASK) >> ENA_FMT1_TIME_SHFT; 12310Sstevel@tonic-gate break; 12320Sstevel@tonic-gate case FM_ENA_FMT2: 12330Sstevel@tonic-gate time = (ena & ENA_FMT2_TIME_MASK) >> ENA_FMT2_TIME_SHFT; 12340Sstevel@tonic-gate break; 12350Sstevel@tonic-gate default: 12360Sstevel@tonic-gate time = 0; 12370Sstevel@tonic-gate } 12380Sstevel@tonic-gate 12390Sstevel@tonic-gate return (time); 12400Sstevel@tonic-gate } 12411414Scindi 12421414Scindi /* 12431414Scindi * Convert a getpcstack() trace to symbolic name+offset, and add the resulting 12441414Scindi * string array to a Fault Management ereport as FM_EREPORT_PAYLOAD_NAME_STACK. 12451414Scindi */ 12461414Scindi void 12471414Scindi fm_payload_stack_add(nvlist_t *payload, const pc_t *stack, int depth) 12481414Scindi { 12491414Scindi int i; 12501414Scindi char *sym; 12511414Scindi ulong_t off; 12521414Scindi char *stkpp[FM_STK_DEPTH]; 12531414Scindi char buf[FM_STK_DEPTH * FM_SYM_SZ]; 12541414Scindi char *stkp = buf; 12551414Scindi 12561414Scindi for (i = 0; i < depth && i != FM_STK_DEPTH; i++, stkp += FM_SYM_SZ) { 12571414Scindi if ((sym = kobj_getsymname(stack[i], &off)) != NULL) 12581414Scindi (void) snprintf(stkp, FM_SYM_SZ, "%s+%lx", sym, off); 12591414Scindi else 12601414Scindi (void) snprintf(stkp, FM_SYM_SZ, "%lx", (long)stack[i]); 12611414Scindi stkpp[i] = stkp; 12621414Scindi } 12631414Scindi 12641414Scindi fm_payload_set(payload, FM_EREPORT_PAYLOAD_NAME_STACK, 12651437Sdilpreet DATA_TYPE_STRING_ARRAY, depth, stkpp, NULL); 12661414Scindi } 12679613SAbhinandan.Ekande@Sun.COM 12689613SAbhinandan.Ekande@Sun.COM void 12699613SAbhinandan.Ekande@Sun.COM print_msg_hwerr(ctid_t ct_id, proc_t *p) 12709613SAbhinandan.Ekande@Sun.COM { 12719613SAbhinandan.Ekande@Sun.COM uprintf("Killed process %d (%s) in contract id %d " 12729613SAbhinandan.Ekande@Sun.COM "due to hardware error\n", p->p_pid, p->p_user.u_comm, ct_id); 12739613SAbhinandan.Ekande@Sun.COM } 127410942STom.Pothier@Sun.COM 127510942STom.Pothier@Sun.COM void 127610942STom.Pothier@Sun.COM fm_fmri_hc_create(nvlist_t *fmri, int version, const nvlist_t *auth, 127710942STom.Pothier@Sun.COM nvlist_t *snvl, nvlist_t *bboard, int npairs, ...) 127810942STom.Pothier@Sun.COM { 127910942STom.Pothier@Sun.COM nv_alloc_t *nva = nvlist_lookup_nv_alloc(fmri); 128010942STom.Pothier@Sun.COM nvlist_t *pairs[HC_MAXPAIRS]; 128110942STom.Pothier@Sun.COM nvlist_t **hcl; 128210942STom.Pothier@Sun.COM uint_t n; 128310942STom.Pothier@Sun.COM int i, j; 128410942STom.Pothier@Sun.COM va_list ap; 128510942STom.Pothier@Sun.COM char *hcname, *hcid; 128610942STom.Pothier@Sun.COM 128710942STom.Pothier@Sun.COM if (!fm_fmri_hc_set_common(fmri, version, auth)) 128810942STom.Pothier@Sun.COM return; 128910942STom.Pothier@Sun.COM 129010942STom.Pothier@Sun.COM /* 129110942STom.Pothier@Sun.COM * copy the bboard nvpairs to the pairs array 129210942STom.Pothier@Sun.COM */ 129310942STom.Pothier@Sun.COM if (nvlist_lookup_nvlist_array(bboard, FM_FMRI_HC_LIST, &hcl, &n) 129410942STom.Pothier@Sun.COM != 0) { 129510942STom.Pothier@Sun.COM atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 129610942STom.Pothier@Sun.COM return; 129710942STom.Pothier@Sun.COM } 129810942STom.Pothier@Sun.COM 129910942STom.Pothier@Sun.COM for (i = 0; i < n; i++) { 130010942STom.Pothier@Sun.COM if (nvlist_lookup_string(hcl[i], FM_FMRI_HC_NAME, 130110942STom.Pothier@Sun.COM &hcname) != 0) { 130210942STom.Pothier@Sun.COM atomic_add_64( 130310942STom.Pothier@Sun.COM &erpt_kstat_data.fmri_set_failed.value.ui64, 1); 130410942STom.Pothier@Sun.COM return; 130510942STom.Pothier@Sun.COM } 130610942STom.Pothier@Sun.COM if (nvlist_lookup_string(hcl[i], FM_FMRI_HC_ID, &hcid) != 0) { 130710942STom.Pothier@Sun.COM atomic_add_64( 130810942STom.Pothier@Sun.COM &erpt_kstat_data.fmri_set_failed.value.ui64, 1); 130910942STom.Pothier@Sun.COM return; 131010942STom.Pothier@Sun.COM } 131110942STom.Pothier@Sun.COM 131210942STom.Pothier@Sun.COM pairs[i] = fm_nvlist_create(nva); 131310942STom.Pothier@Sun.COM if (nvlist_add_string(pairs[i], FM_FMRI_HC_NAME, hcname) != 0 || 131410942STom.Pothier@Sun.COM nvlist_add_string(pairs[i], FM_FMRI_HC_ID, hcid) != 0) { 131510942STom.Pothier@Sun.COM for (j = 0; j <= i; j++) { 131610942STom.Pothier@Sun.COM if (pairs[j] != NULL) 131710942STom.Pothier@Sun.COM fm_nvlist_destroy(pairs[j], 131810942STom.Pothier@Sun.COM FM_NVA_RETAIN); 131910942STom.Pothier@Sun.COM } 132010942STom.Pothier@Sun.COM atomic_add_64( 132110942STom.Pothier@Sun.COM &erpt_kstat_data.fmri_set_failed.value.ui64, 1); 132210942STom.Pothier@Sun.COM return; 132310942STom.Pothier@Sun.COM } 132410942STom.Pothier@Sun.COM } 132510942STom.Pothier@Sun.COM 132610942STom.Pothier@Sun.COM /* 132710942STom.Pothier@Sun.COM * create the pairs from passed in pairs 132810942STom.Pothier@Sun.COM */ 132910942STom.Pothier@Sun.COM npairs = MIN(npairs, HC_MAXPAIRS); 133010942STom.Pothier@Sun.COM 133110942STom.Pothier@Sun.COM va_start(ap, npairs); 133210942STom.Pothier@Sun.COM for (i = n; i < npairs + n; i++) { 133310942STom.Pothier@Sun.COM const char *name = va_arg(ap, const char *); 133410942STom.Pothier@Sun.COM uint32_t id = va_arg(ap, uint32_t); 133510942STom.Pothier@Sun.COM char idstr[11]; 133610942STom.Pothier@Sun.COM (void) snprintf(idstr, sizeof (idstr), "%u", id); 133710942STom.Pothier@Sun.COM pairs[i] = fm_nvlist_create(nva); 133810942STom.Pothier@Sun.COM if (nvlist_add_string(pairs[i], FM_FMRI_HC_NAME, name) != 0 || 133910942STom.Pothier@Sun.COM nvlist_add_string(pairs[i], FM_FMRI_HC_ID, idstr) != 0) { 134010942STom.Pothier@Sun.COM for (j = 0; j <= i; j++) { 134110942STom.Pothier@Sun.COM if (pairs[j] != NULL) 134210942STom.Pothier@Sun.COM fm_nvlist_destroy(pairs[j], 134310942STom.Pothier@Sun.COM FM_NVA_RETAIN); 134410942STom.Pothier@Sun.COM } 134510942STom.Pothier@Sun.COM atomic_add_64( 134610942STom.Pothier@Sun.COM &erpt_kstat_data.fmri_set_failed.value.ui64, 1); 134710942STom.Pothier@Sun.COM return; 134810942STom.Pothier@Sun.COM } 134910942STom.Pothier@Sun.COM } 135010942STom.Pothier@Sun.COM va_end(ap); 135110942STom.Pothier@Sun.COM 135210942STom.Pothier@Sun.COM /* 135310942STom.Pothier@Sun.COM * Create the fmri hc list 135410942STom.Pothier@Sun.COM */ 135510942STom.Pothier@Sun.COM if (nvlist_add_nvlist_array(fmri, FM_FMRI_HC_LIST, pairs, 135610942STom.Pothier@Sun.COM npairs + n) != 0) { 135710942STom.Pothier@Sun.COM atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 135810942STom.Pothier@Sun.COM return; 135910942STom.Pothier@Sun.COM } 136010942STom.Pothier@Sun.COM 136110942STom.Pothier@Sun.COM for (i = 0; i < npairs + n; i++) { 136210942STom.Pothier@Sun.COM fm_nvlist_destroy(pairs[i], FM_NVA_RETAIN); 136310942STom.Pothier@Sun.COM } 136410942STom.Pothier@Sun.COM 136510942STom.Pothier@Sun.COM if (snvl != NULL) { 136610942STom.Pothier@Sun.COM if (nvlist_add_nvlist(fmri, FM_FMRI_HC_SPECIFIC, snvl) != 0) { 136710942STom.Pothier@Sun.COM atomic_add_64( 136810942STom.Pothier@Sun.COM &erpt_kstat_data.fmri_set_failed.value.ui64, 1); 136910942STom.Pothier@Sun.COM return; 137010942STom.Pothier@Sun.COM } 137110942STom.Pothier@Sun.COM } 137210942STom.Pothier@Sun.COM } 1373