1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate /* 30*7c478bd9Sstevel@tonic-gate * Fault Management Architecture (FMA) Resource and Protocol Support 31*7c478bd9Sstevel@tonic-gate * 32*7c478bd9Sstevel@tonic-gate * The routines contained herein provide services to support kernel subsystems 33*7c478bd9Sstevel@tonic-gate * in publishing fault management telemetry (see PSARC 2002/412 and 2003/089). 34*7c478bd9Sstevel@tonic-gate * 35*7c478bd9Sstevel@tonic-gate * Name-Value Pair Lists 36*7c478bd9Sstevel@tonic-gate * 37*7c478bd9Sstevel@tonic-gate * The embodiment of an FMA protocol element (event, fmri or authority) is a 38*7c478bd9Sstevel@tonic-gate * name-value pair list (nvlist_t). FMA-specific nvlist construtor and 39*7c478bd9Sstevel@tonic-gate * destructor functions, fm_nvlist_create() and fm_nvlist_destroy(), are used 40*7c478bd9Sstevel@tonic-gate * to create an nvpair list using custom allocators. Callers may choose to 41*7c478bd9Sstevel@tonic-gate * allocate either from the kernel memory allocator, or from a preallocated 42*7c478bd9Sstevel@tonic-gate * buffer, useful in constrained contexts like high-level interrupt routines. 43*7c478bd9Sstevel@tonic-gate * 44*7c478bd9Sstevel@tonic-gate * Protocol Event and FMRI Construction 45*7c478bd9Sstevel@tonic-gate * 46*7c478bd9Sstevel@tonic-gate * Convenience routines are provided to construct nvlist events according to 47*7c478bd9Sstevel@tonic-gate * the FMA Event Protocol and Naming Schema specification for ereports and 48*7c478bd9Sstevel@tonic-gate * FMRIs for the dev, cpu, hc, mem, legacy hc and de schemes. 49*7c478bd9Sstevel@tonic-gate * 50*7c478bd9Sstevel@tonic-gate * ENA Manipulation 51*7c478bd9Sstevel@tonic-gate * 52*7c478bd9Sstevel@tonic-gate * Routines to generate ENA formats 0, 1 and 2 are available as well as 53*7c478bd9Sstevel@tonic-gate * routines to increment formats 1 and 2. Individual fields within the 54*7c478bd9Sstevel@tonic-gate * ENA are extractable via fm_ena_time_get(), fm_ena_id_get(), 55*7c478bd9Sstevel@tonic-gate * fm_ena_format_get() and fm_ena_gen_get(). 56*7c478bd9Sstevel@tonic-gate */ 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 59*7c478bd9Sstevel@tonic-gate #include <sys/time.h> 60*7c478bd9Sstevel@tonic-gate #include <sys/sysevent.h> 61*7c478bd9Sstevel@tonic-gate #include <sys/sysevent_impl.h> 62*7c478bd9Sstevel@tonic-gate #include <sys/nvpair.h> 63*7c478bd9Sstevel@tonic-gate #include <sys/nvpair_impl.h> 64*7c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 65*7c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 66*7c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 67*7c478bd9Sstevel@tonic-gate #include <sys/systm.h> 68*7c478bd9Sstevel@tonic-gate #include <sys/ddifm.h> 69*7c478bd9Sstevel@tonic-gate #include <sys/ddifm_impl.h> 70*7c478bd9Sstevel@tonic-gate #include <sys/spl.h> 71*7c478bd9Sstevel@tonic-gate #include <sys/dumphdr.h> 72*7c478bd9Sstevel@tonic-gate #include <sys/compress.h> 73*7c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 74*7c478bd9Sstevel@tonic-gate #include <sys/console.h> 75*7c478bd9Sstevel@tonic-gate #include <sys/panic.h> 76*7c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h> 77*7c478bd9Sstevel@tonic-gate #include <sys/sysevent/eventdefs.h> 78*7c478bd9Sstevel@tonic-gate #include <sys/fm/util.h> 79*7c478bd9Sstevel@tonic-gate #include <sys/fm/protocol.h> 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate /* 82*7c478bd9Sstevel@tonic-gate * URL and SUNW-MSG-ID value to display for fm_panic(), defined below. These 83*7c478bd9Sstevel@tonic-gate * values must be kept in sync with the FMA source code in usr/src/cmd/fm. 84*7c478bd9Sstevel@tonic-gate */ 85*7c478bd9Sstevel@tonic-gate static const char *fm_url = "http://www.sun.com/msg"; 86*7c478bd9Sstevel@tonic-gate static const char *fm_msgid = "SUNOS-8000-0G"; 87*7c478bd9Sstevel@tonic-gate static char *volatile fm_panicstr = NULL; 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate errorq_t *ereport_errorq; 90*7c478bd9Sstevel@tonic-gate void *ereport_dumpbuf; 91*7c478bd9Sstevel@tonic-gate size_t ereport_dumplen; 92*7c478bd9Sstevel@tonic-gate 93*7c478bd9Sstevel@tonic-gate static uint_t ereport_chanlen = ERPT_EVCH_MAX; 94*7c478bd9Sstevel@tonic-gate static evchan_t *ereport_chan = NULL; 95*7c478bd9Sstevel@tonic-gate static ulong_t ereport_qlen = 0; 96*7c478bd9Sstevel@tonic-gate static size_t ereport_size = 0; 97*7c478bd9Sstevel@tonic-gate static int ereport_cols = 80; 98*7c478bd9Sstevel@tonic-gate 99*7c478bd9Sstevel@tonic-gate /* 100*7c478bd9Sstevel@tonic-gate * Common fault management kstats to record ereport generation 101*7c478bd9Sstevel@tonic-gate * failures 102*7c478bd9Sstevel@tonic-gate */ 103*7c478bd9Sstevel@tonic-gate 104*7c478bd9Sstevel@tonic-gate struct erpt_kstat { 105*7c478bd9Sstevel@tonic-gate kstat_named_t erpt_dropped; /* num erpts dropped on post */ 106*7c478bd9Sstevel@tonic-gate kstat_named_t erpt_set_failed; /* num erpt set failures */ 107*7c478bd9Sstevel@tonic-gate kstat_named_t fmri_set_failed; /* num fmri set failures */ 108*7c478bd9Sstevel@tonic-gate kstat_named_t payload_set_failed; /* num payload set failures */ 109*7c478bd9Sstevel@tonic-gate }; 110*7c478bd9Sstevel@tonic-gate 111*7c478bd9Sstevel@tonic-gate static struct erpt_kstat erpt_kstat_data = { 112*7c478bd9Sstevel@tonic-gate { "erpt-dropped", KSTAT_DATA_UINT64 }, 113*7c478bd9Sstevel@tonic-gate { "erpt-set-failed", KSTAT_DATA_UINT64 }, 114*7c478bd9Sstevel@tonic-gate { "fmri-set-failed", KSTAT_DATA_UINT64 }, 115*7c478bd9Sstevel@tonic-gate { "payload-set-failed", KSTAT_DATA_UINT64 } 116*7c478bd9Sstevel@tonic-gate }; 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 119*7c478bd9Sstevel@tonic-gate static void 120*7c478bd9Sstevel@tonic-gate fm_drain(void *private, void *data, errorq_elem_t *eep) 121*7c478bd9Sstevel@tonic-gate { 122*7c478bd9Sstevel@tonic-gate nvlist_t *nvl = errorq_elem_nvl(ereport_errorq, eep); 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate if (!panicstr) 125*7c478bd9Sstevel@tonic-gate (void) fm_ereport_post(nvl, EVCH_TRYHARD); 126*7c478bd9Sstevel@tonic-gate else 127*7c478bd9Sstevel@tonic-gate fm_nvprint(nvl); 128*7c478bd9Sstevel@tonic-gate } 129*7c478bd9Sstevel@tonic-gate 130*7c478bd9Sstevel@tonic-gate void 131*7c478bd9Sstevel@tonic-gate fm_init(void) 132*7c478bd9Sstevel@tonic-gate { 133*7c478bd9Sstevel@tonic-gate kstat_t *ksp; 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate (void) sysevent_evc_bind(FM_ERROR_CHAN, 136*7c478bd9Sstevel@tonic-gate &ereport_chan, EVCH_CREAT | EVCH_HOLD_PEND); 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate (void) sysevent_evc_control(ereport_chan, 139*7c478bd9Sstevel@tonic-gate EVCH_SET_CHAN_LEN, &ereport_chanlen); 140*7c478bd9Sstevel@tonic-gate 141*7c478bd9Sstevel@tonic-gate if (ereport_qlen == 0) 142*7c478bd9Sstevel@tonic-gate ereport_qlen = ERPT_MAX_ERRS * MAX(max_ncpus, 4); 143*7c478bd9Sstevel@tonic-gate 144*7c478bd9Sstevel@tonic-gate if (ereport_size == 0) 145*7c478bd9Sstevel@tonic-gate ereport_size = ERPT_DATA_SZ; 146*7c478bd9Sstevel@tonic-gate 147*7c478bd9Sstevel@tonic-gate ereport_errorq = errorq_nvcreate("fm_ereport_queue", 148*7c478bd9Sstevel@tonic-gate (errorq_func_t)fm_drain, NULL, ereport_qlen, ereport_size, 149*7c478bd9Sstevel@tonic-gate FM_ERR_PIL, ERRORQ_VITAL); 150*7c478bd9Sstevel@tonic-gate if (ereport_errorq == NULL) 151*7c478bd9Sstevel@tonic-gate panic("failed to create required ereport error queue"); 152*7c478bd9Sstevel@tonic-gate 153*7c478bd9Sstevel@tonic-gate ereport_dumpbuf = kmem_alloc(ereport_size, KM_SLEEP); 154*7c478bd9Sstevel@tonic-gate ereport_dumplen = ereport_size; 155*7c478bd9Sstevel@tonic-gate 156*7c478bd9Sstevel@tonic-gate /* Initialize ereport allocation and generation kstats */ 157*7c478bd9Sstevel@tonic-gate ksp = kstat_create("unix", 0, "fm", "misc", KSTAT_TYPE_NAMED, 158*7c478bd9Sstevel@tonic-gate sizeof (struct erpt_kstat) / sizeof (kstat_named_t), 159*7c478bd9Sstevel@tonic-gate KSTAT_FLAG_VIRTUAL); 160*7c478bd9Sstevel@tonic-gate 161*7c478bd9Sstevel@tonic-gate if (ksp != NULL) { 162*7c478bd9Sstevel@tonic-gate ksp->ks_data = &erpt_kstat_data; 163*7c478bd9Sstevel@tonic-gate kstat_install(ksp); 164*7c478bd9Sstevel@tonic-gate } else { 165*7c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "failed to create fm/misc kstat\n"); 166*7c478bd9Sstevel@tonic-gate 167*7c478bd9Sstevel@tonic-gate } 168*7c478bd9Sstevel@tonic-gate } 169*7c478bd9Sstevel@tonic-gate 170*7c478bd9Sstevel@tonic-gate /* 171*7c478bd9Sstevel@tonic-gate * Formatting utility function for fm_nvprintr. We attempt to wrap chunks of 172*7c478bd9Sstevel@tonic-gate * output so they aren't split across console lines, and return the end column. 173*7c478bd9Sstevel@tonic-gate */ 174*7c478bd9Sstevel@tonic-gate /*PRINTFLIKE4*/ 175*7c478bd9Sstevel@tonic-gate static int 176*7c478bd9Sstevel@tonic-gate fm_printf(int depth, int c, int cols, const char *format, ...) 177*7c478bd9Sstevel@tonic-gate { 178*7c478bd9Sstevel@tonic-gate va_list ap; 179*7c478bd9Sstevel@tonic-gate int width; 180*7c478bd9Sstevel@tonic-gate char c1; 181*7c478bd9Sstevel@tonic-gate 182*7c478bd9Sstevel@tonic-gate va_start(ap, format); 183*7c478bd9Sstevel@tonic-gate width = vsnprintf(&c1, sizeof (c1), format, ap); 184*7c478bd9Sstevel@tonic-gate va_end(ap); 185*7c478bd9Sstevel@tonic-gate 186*7c478bd9Sstevel@tonic-gate if (c + width >= cols) { 187*7c478bd9Sstevel@tonic-gate console_printf("\n\r"); 188*7c478bd9Sstevel@tonic-gate c = 0; 189*7c478bd9Sstevel@tonic-gate if (format[0] != ' ' && depth > 0) { 190*7c478bd9Sstevel@tonic-gate console_printf(" "); 191*7c478bd9Sstevel@tonic-gate c++; 192*7c478bd9Sstevel@tonic-gate } 193*7c478bd9Sstevel@tonic-gate } 194*7c478bd9Sstevel@tonic-gate 195*7c478bd9Sstevel@tonic-gate va_start(ap, format); 196*7c478bd9Sstevel@tonic-gate console_vprintf(format, ap); 197*7c478bd9Sstevel@tonic-gate va_end(ap); 198*7c478bd9Sstevel@tonic-gate 199*7c478bd9Sstevel@tonic-gate return ((c + width) % cols); 200*7c478bd9Sstevel@tonic-gate } 201*7c478bd9Sstevel@tonic-gate 202*7c478bd9Sstevel@tonic-gate /* 203*7c478bd9Sstevel@tonic-gate * Recursively print a nvlist in the specified column width and return the 204*7c478bd9Sstevel@tonic-gate * column we end up in. This function is called recursively by fm_nvprint(), 205*7c478bd9Sstevel@tonic-gate * below. We generically format the entire nvpair using hexadecimal 206*7c478bd9Sstevel@tonic-gate * integers and strings, and elide any integer arrays. Arrays are basically 207*7c478bd9Sstevel@tonic-gate * used for cache dumps right now, so we suppress them so as not to overwhelm 208*7c478bd9Sstevel@tonic-gate * the amount of console output we produce at panic time. This can be further 209*7c478bd9Sstevel@tonic-gate * enhanced as FMA technology grows based upon the needs of consumers. All 210*7c478bd9Sstevel@tonic-gate * FMA telemetry is logged using the dump device transport, so the console 211*7c478bd9Sstevel@tonic-gate * output serves only as a fallback in case this procedure is unsuccessful. 212*7c478bd9Sstevel@tonic-gate */ 213*7c478bd9Sstevel@tonic-gate static int 214*7c478bd9Sstevel@tonic-gate fm_nvprintr(nvlist_t *nvl, int d, int c, int cols) 215*7c478bd9Sstevel@tonic-gate { 216*7c478bd9Sstevel@tonic-gate nvpair_t *nvp; 217*7c478bd9Sstevel@tonic-gate 218*7c478bd9Sstevel@tonic-gate for (nvp = nvlist_next_nvpair(nvl, NULL); 219*7c478bd9Sstevel@tonic-gate nvp != NULL; nvp = nvlist_next_nvpair(nvl, nvp)) { 220*7c478bd9Sstevel@tonic-gate 221*7c478bd9Sstevel@tonic-gate data_type_t type = nvpair_type(nvp); 222*7c478bd9Sstevel@tonic-gate const char *name = nvpair_name(nvp); 223*7c478bd9Sstevel@tonic-gate 224*7c478bd9Sstevel@tonic-gate boolean_t b; 225*7c478bd9Sstevel@tonic-gate uint8_t i8; 226*7c478bd9Sstevel@tonic-gate uint16_t i16; 227*7c478bd9Sstevel@tonic-gate uint32_t i32; 228*7c478bd9Sstevel@tonic-gate uint64_t i64; 229*7c478bd9Sstevel@tonic-gate char *str; 230*7c478bd9Sstevel@tonic-gate nvlist_t *cnv; 231*7c478bd9Sstevel@tonic-gate 232*7c478bd9Sstevel@tonic-gate if (strcmp(name, FM_CLASS) == 0) 233*7c478bd9Sstevel@tonic-gate continue; /* already printed by caller */ 234*7c478bd9Sstevel@tonic-gate 235*7c478bd9Sstevel@tonic-gate c = fm_printf(d, c, cols, " %s=", name); 236*7c478bd9Sstevel@tonic-gate 237*7c478bd9Sstevel@tonic-gate switch (type) { 238*7c478bd9Sstevel@tonic-gate case DATA_TYPE_BOOLEAN: 239*7c478bd9Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, " 1"); 240*7c478bd9Sstevel@tonic-gate break; 241*7c478bd9Sstevel@tonic-gate 242*7c478bd9Sstevel@tonic-gate case DATA_TYPE_BOOLEAN_VALUE: 243*7c478bd9Sstevel@tonic-gate (void) nvpair_value_boolean_value(nvp, &b); 244*7c478bd9Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, b ? "1" : "0"); 245*7c478bd9Sstevel@tonic-gate break; 246*7c478bd9Sstevel@tonic-gate 247*7c478bd9Sstevel@tonic-gate case DATA_TYPE_BYTE: 248*7c478bd9Sstevel@tonic-gate (void) nvpair_value_byte(nvp, &i8); 249*7c478bd9Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%x", i8); 250*7c478bd9Sstevel@tonic-gate break; 251*7c478bd9Sstevel@tonic-gate 252*7c478bd9Sstevel@tonic-gate case DATA_TYPE_INT8: 253*7c478bd9Sstevel@tonic-gate (void) nvpair_value_int8(nvp, (void *)&i8); 254*7c478bd9Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%x", i8); 255*7c478bd9Sstevel@tonic-gate break; 256*7c478bd9Sstevel@tonic-gate 257*7c478bd9Sstevel@tonic-gate case DATA_TYPE_UINT8: 258*7c478bd9Sstevel@tonic-gate (void) nvpair_value_uint8(nvp, &i8); 259*7c478bd9Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%x", i8); 260*7c478bd9Sstevel@tonic-gate break; 261*7c478bd9Sstevel@tonic-gate 262*7c478bd9Sstevel@tonic-gate case DATA_TYPE_INT16: 263*7c478bd9Sstevel@tonic-gate (void) nvpair_value_int16(nvp, (void *)&i16); 264*7c478bd9Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%x", i16); 265*7c478bd9Sstevel@tonic-gate break; 266*7c478bd9Sstevel@tonic-gate 267*7c478bd9Sstevel@tonic-gate case DATA_TYPE_UINT16: 268*7c478bd9Sstevel@tonic-gate (void) nvpair_value_uint16(nvp, &i16); 269*7c478bd9Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%x", i16); 270*7c478bd9Sstevel@tonic-gate break; 271*7c478bd9Sstevel@tonic-gate 272*7c478bd9Sstevel@tonic-gate case DATA_TYPE_INT32: 273*7c478bd9Sstevel@tonic-gate (void) nvpair_value_int32(nvp, (void *)&i32); 274*7c478bd9Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%x", i32); 275*7c478bd9Sstevel@tonic-gate break; 276*7c478bd9Sstevel@tonic-gate 277*7c478bd9Sstevel@tonic-gate case DATA_TYPE_UINT32: 278*7c478bd9Sstevel@tonic-gate (void) nvpair_value_uint32(nvp, &i32); 279*7c478bd9Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%x", i32); 280*7c478bd9Sstevel@tonic-gate break; 281*7c478bd9Sstevel@tonic-gate 282*7c478bd9Sstevel@tonic-gate case DATA_TYPE_INT64: 283*7c478bd9Sstevel@tonic-gate (void) nvpair_value_int64(nvp, (void *)&i64); 284*7c478bd9Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%llx", 285*7c478bd9Sstevel@tonic-gate (u_longlong_t)i64); 286*7c478bd9Sstevel@tonic-gate break; 287*7c478bd9Sstevel@tonic-gate 288*7c478bd9Sstevel@tonic-gate case DATA_TYPE_UINT64: 289*7c478bd9Sstevel@tonic-gate (void) nvpair_value_uint64(nvp, &i64); 290*7c478bd9Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%llx", 291*7c478bd9Sstevel@tonic-gate (u_longlong_t)i64); 292*7c478bd9Sstevel@tonic-gate break; 293*7c478bd9Sstevel@tonic-gate 294*7c478bd9Sstevel@tonic-gate case DATA_TYPE_HRTIME: 295*7c478bd9Sstevel@tonic-gate (void) nvpair_value_hrtime(nvp, (void *)&i64); 296*7c478bd9Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "%llx", 297*7c478bd9Sstevel@tonic-gate (u_longlong_t)i64); 298*7c478bd9Sstevel@tonic-gate break; 299*7c478bd9Sstevel@tonic-gate 300*7c478bd9Sstevel@tonic-gate case DATA_TYPE_STRING: 301*7c478bd9Sstevel@tonic-gate (void) nvpair_value_string(nvp, &str); 302*7c478bd9Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "\"%s\"", 303*7c478bd9Sstevel@tonic-gate str ? str : "<NULL>"); 304*7c478bd9Sstevel@tonic-gate break; 305*7c478bd9Sstevel@tonic-gate 306*7c478bd9Sstevel@tonic-gate case DATA_TYPE_NVLIST: 307*7c478bd9Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "["); 308*7c478bd9Sstevel@tonic-gate (void) nvpair_value_nvlist(nvp, &cnv); 309*7c478bd9Sstevel@tonic-gate c = fm_nvprintr(cnv, d + 1, c, cols); 310*7c478bd9Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, " ]"); 311*7c478bd9Sstevel@tonic-gate break; 312*7c478bd9Sstevel@tonic-gate 313*7c478bd9Sstevel@tonic-gate case DATA_TYPE_BOOLEAN_ARRAY: 314*7c478bd9Sstevel@tonic-gate case DATA_TYPE_BYTE_ARRAY: 315*7c478bd9Sstevel@tonic-gate case DATA_TYPE_INT8_ARRAY: 316*7c478bd9Sstevel@tonic-gate case DATA_TYPE_UINT8_ARRAY: 317*7c478bd9Sstevel@tonic-gate case DATA_TYPE_INT16_ARRAY: 318*7c478bd9Sstevel@tonic-gate case DATA_TYPE_UINT16_ARRAY: 319*7c478bd9Sstevel@tonic-gate case DATA_TYPE_INT32_ARRAY: 320*7c478bd9Sstevel@tonic-gate case DATA_TYPE_UINT32_ARRAY: 321*7c478bd9Sstevel@tonic-gate case DATA_TYPE_INT64_ARRAY: 322*7c478bd9Sstevel@tonic-gate case DATA_TYPE_UINT64_ARRAY: 323*7c478bd9Sstevel@tonic-gate case DATA_TYPE_STRING_ARRAY: 324*7c478bd9Sstevel@tonic-gate case DATA_TYPE_NVLIST_ARRAY: 325*7c478bd9Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "[...]"); 326*7c478bd9Sstevel@tonic-gate break; 327*7c478bd9Sstevel@tonic-gate case DATA_TYPE_UNKNOWN: 328*7c478bd9Sstevel@tonic-gate c = fm_printf(d + 1, c, cols, "<unknown>"); 329*7c478bd9Sstevel@tonic-gate break; 330*7c478bd9Sstevel@tonic-gate } 331*7c478bd9Sstevel@tonic-gate } 332*7c478bd9Sstevel@tonic-gate 333*7c478bd9Sstevel@tonic-gate return (c); 334*7c478bd9Sstevel@tonic-gate } 335*7c478bd9Sstevel@tonic-gate 336*7c478bd9Sstevel@tonic-gate void 337*7c478bd9Sstevel@tonic-gate fm_nvprint(nvlist_t *nvl) 338*7c478bd9Sstevel@tonic-gate { 339*7c478bd9Sstevel@tonic-gate char *class; 340*7c478bd9Sstevel@tonic-gate int c = 0; 341*7c478bd9Sstevel@tonic-gate 342*7c478bd9Sstevel@tonic-gate console_printf("\r"); 343*7c478bd9Sstevel@tonic-gate 344*7c478bd9Sstevel@tonic-gate if (nvlist_lookup_string(nvl, FM_CLASS, &class) == 0) 345*7c478bd9Sstevel@tonic-gate c = fm_printf(0, c, ereport_cols, "%s", class); 346*7c478bd9Sstevel@tonic-gate 347*7c478bd9Sstevel@tonic-gate if (fm_nvprintr(nvl, 0, c, ereport_cols) != 0) 348*7c478bd9Sstevel@tonic-gate console_printf("\n"); 349*7c478bd9Sstevel@tonic-gate 350*7c478bd9Sstevel@tonic-gate console_printf("\n"); 351*7c478bd9Sstevel@tonic-gate } 352*7c478bd9Sstevel@tonic-gate 353*7c478bd9Sstevel@tonic-gate /* 354*7c478bd9Sstevel@tonic-gate * Wrapper for panic() that first produces an FMA-style message for admins. 355*7c478bd9Sstevel@tonic-gate * Normally such messages are generated by fmd(1M)'s syslog-msgs agent: this 356*7c478bd9Sstevel@tonic-gate * is the one exception to that rule and the only error that gets messaged. 357*7c478bd9Sstevel@tonic-gate * This function is intended for use by subsystems that have detected a fatal 358*7c478bd9Sstevel@tonic-gate * error and enqueued appropriate ereports and wish to then force a panic. 359*7c478bd9Sstevel@tonic-gate */ 360*7c478bd9Sstevel@tonic-gate /*PRINTFLIKE1*/ 361*7c478bd9Sstevel@tonic-gate void 362*7c478bd9Sstevel@tonic-gate fm_panic(const char *format, ...) 363*7c478bd9Sstevel@tonic-gate { 364*7c478bd9Sstevel@tonic-gate va_list ap; 365*7c478bd9Sstevel@tonic-gate 366*7c478bd9Sstevel@tonic-gate (void) casptr((void *)&fm_panicstr, NULL, (void *)format); 367*7c478bd9Sstevel@tonic-gate va_start(ap, format); 368*7c478bd9Sstevel@tonic-gate vpanic(format, ap); 369*7c478bd9Sstevel@tonic-gate va_end(ap); 370*7c478bd9Sstevel@tonic-gate } 371*7c478bd9Sstevel@tonic-gate 372*7c478bd9Sstevel@tonic-gate /* 373*7c478bd9Sstevel@tonic-gate * Print any appropriate FMA banner message before the panic message. This 374*7c478bd9Sstevel@tonic-gate * function is called by panicsys() and prints the message for fm_panic(). 375*7c478bd9Sstevel@tonic-gate * We print the message here so that it comes after the system is quiesced. 376*7c478bd9Sstevel@tonic-gate * A one-line summary is recorded in the log only (cmn_err(9F) with "!" prefix). 377*7c478bd9Sstevel@tonic-gate * The rest of the message is for the console only and not needed in the log, 378*7c478bd9Sstevel@tonic-gate * so it is printed using console_printf(). We break it up into multiple 379*7c478bd9Sstevel@tonic-gate * chunks so as to avoid overflowing any small legacy prom_printf() buffers. 380*7c478bd9Sstevel@tonic-gate */ 381*7c478bd9Sstevel@tonic-gate void 382*7c478bd9Sstevel@tonic-gate fm_banner(void) 383*7c478bd9Sstevel@tonic-gate { 384*7c478bd9Sstevel@tonic-gate timespec_t tod; 385*7c478bd9Sstevel@tonic-gate hrtime_t now; 386*7c478bd9Sstevel@tonic-gate 387*7c478bd9Sstevel@tonic-gate if (!fm_panicstr) 388*7c478bd9Sstevel@tonic-gate return; /* panic was not initiated by fm_panic(); do nothing */ 389*7c478bd9Sstevel@tonic-gate 390*7c478bd9Sstevel@tonic-gate if (panicstr) { 391*7c478bd9Sstevel@tonic-gate tod = panic_hrestime; 392*7c478bd9Sstevel@tonic-gate now = panic_hrtime; 393*7c478bd9Sstevel@tonic-gate } else { 394*7c478bd9Sstevel@tonic-gate gethrestime(&tod); 395*7c478bd9Sstevel@tonic-gate now = gethrtime_waitfree(); 396*7c478bd9Sstevel@tonic-gate } 397*7c478bd9Sstevel@tonic-gate 398*7c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "!SUNW-MSG-ID: %s, " 399*7c478bd9Sstevel@tonic-gate "TYPE: Error, VER: 1, SEVERITY: Major\n", fm_msgid); 400*7c478bd9Sstevel@tonic-gate 401*7c478bd9Sstevel@tonic-gate console_printf( 402*7c478bd9Sstevel@tonic-gate "\n\rSUNW-MSG-ID: %s, TYPE: Error, VER: 1, SEVERITY: Major\n" 403*7c478bd9Sstevel@tonic-gate "EVENT-TIME: 0x%lx.0x%lx (0x%llx)\n", 404*7c478bd9Sstevel@tonic-gate fm_msgid, tod.tv_sec, tod.tv_nsec, (u_longlong_t)now); 405*7c478bd9Sstevel@tonic-gate 406*7c478bd9Sstevel@tonic-gate console_printf( 407*7c478bd9Sstevel@tonic-gate "PLATFORM: %s, CSN: -, HOSTNAME: %s\n" 408*7c478bd9Sstevel@tonic-gate "SOURCE: %s, REV: %s %s\n", 409*7c478bd9Sstevel@tonic-gate platform, utsname.nodename, utsname.sysname, 410*7c478bd9Sstevel@tonic-gate utsname.release, utsname.version); 411*7c478bd9Sstevel@tonic-gate 412*7c478bd9Sstevel@tonic-gate console_printf( 413*7c478bd9Sstevel@tonic-gate "DESC: Errors have been detected that require a reboot to ensure system\n" 414*7c478bd9Sstevel@tonic-gate "integrity. See %s/%s for more information.\n", 415*7c478bd9Sstevel@tonic-gate fm_url, fm_msgid); 416*7c478bd9Sstevel@tonic-gate 417*7c478bd9Sstevel@tonic-gate console_printf( 418*7c478bd9Sstevel@tonic-gate "AUTO-RESPONSE: Solaris will attempt to save and diagnose the error telemetry\n" 419*7c478bd9Sstevel@tonic-gate "IMPACT: The system will sync files, save a crash dump if needed, and reboot\n" 420*7c478bd9Sstevel@tonic-gate "REC-ACTION: Save the error summary below in case telemetry cannot be saved\n"); 421*7c478bd9Sstevel@tonic-gate 422*7c478bd9Sstevel@tonic-gate console_printf("\n"); 423*7c478bd9Sstevel@tonic-gate } 424*7c478bd9Sstevel@tonic-gate 425*7c478bd9Sstevel@tonic-gate /* 426*7c478bd9Sstevel@tonic-gate * Utility function to write all of the pending ereports to the dump device. 427*7c478bd9Sstevel@tonic-gate * This function is called at either normal reboot or panic time, and simply 428*7c478bd9Sstevel@tonic-gate * iterates over the in-transit messages in the ereport sysevent channel. 429*7c478bd9Sstevel@tonic-gate */ 430*7c478bd9Sstevel@tonic-gate void 431*7c478bd9Sstevel@tonic-gate fm_ereport_dump(void) 432*7c478bd9Sstevel@tonic-gate { 433*7c478bd9Sstevel@tonic-gate evchanq_t *chq; 434*7c478bd9Sstevel@tonic-gate sysevent_t *sep; 435*7c478bd9Sstevel@tonic-gate erpt_dump_t ed; 436*7c478bd9Sstevel@tonic-gate 437*7c478bd9Sstevel@tonic-gate timespec_t tod; 438*7c478bd9Sstevel@tonic-gate hrtime_t now; 439*7c478bd9Sstevel@tonic-gate char *buf; 440*7c478bd9Sstevel@tonic-gate size_t len; 441*7c478bd9Sstevel@tonic-gate 442*7c478bd9Sstevel@tonic-gate if (panicstr) { 443*7c478bd9Sstevel@tonic-gate tod = panic_hrestime; 444*7c478bd9Sstevel@tonic-gate now = panic_hrtime; 445*7c478bd9Sstevel@tonic-gate } else { 446*7c478bd9Sstevel@tonic-gate if (ereport_errorq != NULL) 447*7c478bd9Sstevel@tonic-gate errorq_drain(ereport_errorq); 448*7c478bd9Sstevel@tonic-gate gethrestime(&tod); 449*7c478bd9Sstevel@tonic-gate now = gethrtime_waitfree(); 450*7c478bd9Sstevel@tonic-gate } 451*7c478bd9Sstevel@tonic-gate 452*7c478bd9Sstevel@tonic-gate /* 453*7c478bd9Sstevel@tonic-gate * In the panic case, sysevent_evc_walk_init() will return NULL. 454*7c478bd9Sstevel@tonic-gate */ 455*7c478bd9Sstevel@tonic-gate if ((chq = sysevent_evc_walk_init(ereport_chan, NULL)) == NULL && 456*7c478bd9Sstevel@tonic-gate !panicstr) 457*7c478bd9Sstevel@tonic-gate return; /* event channel isn't initialized yet */ 458*7c478bd9Sstevel@tonic-gate 459*7c478bd9Sstevel@tonic-gate while ((sep = sysevent_evc_walk_step(chq)) != NULL) { 460*7c478bd9Sstevel@tonic-gate if ((buf = sysevent_evc_event_attr(sep, &len)) == NULL) 461*7c478bd9Sstevel@tonic-gate break; 462*7c478bd9Sstevel@tonic-gate 463*7c478bd9Sstevel@tonic-gate ed.ed_magic = ERPT_MAGIC; 464*7c478bd9Sstevel@tonic-gate ed.ed_chksum = checksum32(buf, len); 465*7c478bd9Sstevel@tonic-gate ed.ed_size = (uint32_t)len; 466*7c478bd9Sstevel@tonic-gate ed.ed_pad = 0; 467*7c478bd9Sstevel@tonic-gate ed.ed_hrt_nsec = SE_TIME(sep); 468*7c478bd9Sstevel@tonic-gate ed.ed_hrt_base = now; 469*7c478bd9Sstevel@tonic-gate ed.ed_tod_base.sec = tod.tv_sec; 470*7c478bd9Sstevel@tonic-gate ed.ed_tod_base.nsec = tod.tv_nsec; 471*7c478bd9Sstevel@tonic-gate 472*7c478bd9Sstevel@tonic-gate dumpvp_write(&ed, sizeof (ed)); 473*7c478bd9Sstevel@tonic-gate dumpvp_write(buf, len); 474*7c478bd9Sstevel@tonic-gate } 475*7c478bd9Sstevel@tonic-gate 476*7c478bd9Sstevel@tonic-gate sysevent_evc_walk_fini(chq); 477*7c478bd9Sstevel@tonic-gate } 478*7c478bd9Sstevel@tonic-gate 479*7c478bd9Sstevel@tonic-gate /* 480*7c478bd9Sstevel@tonic-gate * Post an error report (ereport) to the sysevent error channel. The error 481*7c478bd9Sstevel@tonic-gate * channel must be established with a prior call to sysevent_evc_create() 482*7c478bd9Sstevel@tonic-gate * before publication may occur. 483*7c478bd9Sstevel@tonic-gate */ 484*7c478bd9Sstevel@tonic-gate void 485*7c478bd9Sstevel@tonic-gate fm_ereport_post(nvlist_t *ereport, int evc_flag) 486*7c478bd9Sstevel@tonic-gate { 487*7c478bd9Sstevel@tonic-gate size_t nvl_size = 0; 488*7c478bd9Sstevel@tonic-gate evchan_t *error_chan; 489*7c478bd9Sstevel@tonic-gate 490*7c478bd9Sstevel@tonic-gate (void) nvlist_size(ereport, &nvl_size, NV_ENCODE_NATIVE); 491*7c478bd9Sstevel@tonic-gate if (nvl_size > ERPT_DATA_SZ || nvl_size == 0) { 492*7c478bd9Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.erpt_dropped.value.ui64, 1); 493*7c478bd9Sstevel@tonic-gate return; 494*7c478bd9Sstevel@tonic-gate } 495*7c478bd9Sstevel@tonic-gate 496*7c478bd9Sstevel@tonic-gate if (sysevent_evc_bind(FM_ERROR_CHAN, &error_chan, 497*7c478bd9Sstevel@tonic-gate EVCH_CREAT|EVCH_HOLD_PEND) != 0) { 498*7c478bd9Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.erpt_dropped.value.ui64, 1); 499*7c478bd9Sstevel@tonic-gate return; 500*7c478bd9Sstevel@tonic-gate } 501*7c478bd9Sstevel@tonic-gate 502*7c478bd9Sstevel@tonic-gate if (sysevent_evc_publish(error_chan, EC_FM, ESC_FM_ERROR, 503*7c478bd9Sstevel@tonic-gate SUNW_VENDOR, FM_PUB, ereport, evc_flag) != 0) { 504*7c478bd9Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.erpt_dropped.value.ui64, 1); 505*7c478bd9Sstevel@tonic-gate sysevent_evc_unbind(error_chan); 506*7c478bd9Sstevel@tonic-gate return; 507*7c478bd9Sstevel@tonic-gate } 508*7c478bd9Sstevel@tonic-gate sysevent_evc_unbind(error_chan); 509*7c478bd9Sstevel@tonic-gate } 510*7c478bd9Sstevel@tonic-gate 511*7c478bd9Sstevel@tonic-gate /* 512*7c478bd9Sstevel@tonic-gate * Wrapppers for FM nvlist allocators 513*7c478bd9Sstevel@tonic-gate */ 514*7c478bd9Sstevel@tonic-gate /* ARGSUSED */ 515*7c478bd9Sstevel@tonic-gate static void * 516*7c478bd9Sstevel@tonic-gate i_fm_alloc(nv_alloc_t *nva, size_t size) 517*7c478bd9Sstevel@tonic-gate { 518*7c478bd9Sstevel@tonic-gate return (kmem_zalloc(size, KM_SLEEP)); 519*7c478bd9Sstevel@tonic-gate } 520*7c478bd9Sstevel@tonic-gate 521*7c478bd9Sstevel@tonic-gate /* ARGSUSED */ 522*7c478bd9Sstevel@tonic-gate static void 523*7c478bd9Sstevel@tonic-gate i_fm_free(nv_alloc_t *nva, void *buf, size_t size) 524*7c478bd9Sstevel@tonic-gate { 525*7c478bd9Sstevel@tonic-gate kmem_free(buf, size); 526*7c478bd9Sstevel@tonic-gate } 527*7c478bd9Sstevel@tonic-gate 528*7c478bd9Sstevel@tonic-gate const nv_alloc_ops_t fm_mem_alloc_ops = { 529*7c478bd9Sstevel@tonic-gate NULL, 530*7c478bd9Sstevel@tonic-gate NULL, 531*7c478bd9Sstevel@tonic-gate i_fm_alloc, 532*7c478bd9Sstevel@tonic-gate i_fm_free, 533*7c478bd9Sstevel@tonic-gate NULL 534*7c478bd9Sstevel@tonic-gate }; 535*7c478bd9Sstevel@tonic-gate 536*7c478bd9Sstevel@tonic-gate /* 537*7c478bd9Sstevel@tonic-gate * Create and initialize a new nv_alloc_t for a fixed buffer, buf. A pointer 538*7c478bd9Sstevel@tonic-gate * to the newly allocated nv_alloc_t structure is returned upon success or NULL 539*7c478bd9Sstevel@tonic-gate * is returned to indicate that the nv_alloc structure could not be created. 540*7c478bd9Sstevel@tonic-gate */ 541*7c478bd9Sstevel@tonic-gate nv_alloc_t * 542*7c478bd9Sstevel@tonic-gate fm_nva_xcreate(char *buf, size_t bufsz) 543*7c478bd9Sstevel@tonic-gate { 544*7c478bd9Sstevel@tonic-gate nv_alloc_t *nvhdl = kmem_zalloc(sizeof (nv_alloc_t), KM_SLEEP); 545*7c478bd9Sstevel@tonic-gate 546*7c478bd9Sstevel@tonic-gate if (bufsz == 0 || nv_alloc_init(nvhdl, nv_fixed_ops, buf, bufsz) != 0) { 547*7c478bd9Sstevel@tonic-gate kmem_free(nvhdl, sizeof (nv_alloc_t)); 548*7c478bd9Sstevel@tonic-gate return (NULL); 549*7c478bd9Sstevel@tonic-gate } 550*7c478bd9Sstevel@tonic-gate 551*7c478bd9Sstevel@tonic-gate return (nvhdl); 552*7c478bd9Sstevel@tonic-gate } 553*7c478bd9Sstevel@tonic-gate 554*7c478bd9Sstevel@tonic-gate /* 555*7c478bd9Sstevel@tonic-gate * Destroy a previously allocated nv_alloc structure. The fixed buffer 556*7c478bd9Sstevel@tonic-gate * associated with nva must be freed by the caller. 557*7c478bd9Sstevel@tonic-gate */ 558*7c478bd9Sstevel@tonic-gate void 559*7c478bd9Sstevel@tonic-gate fm_nva_xdestroy(nv_alloc_t *nva) 560*7c478bd9Sstevel@tonic-gate { 561*7c478bd9Sstevel@tonic-gate nv_alloc_fini(nva); 562*7c478bd9Sstevel@tonic-gate kmem_free(nva, sizeof (nv_alloc_t)); 563*7c478bd9Sstevel@tonic-gate } 564*7c478bd9Sstevel@tonic-gate 565*7c478bd9Sstevel@tonic-gate /* 566*7c478bd9Sstevel@tonic-gate * Create a new nv list. A pointer to a new nv list structure is returned 567*7c478bd9Sstevel@tonic-gate * upon success or NULL is returned to indicate that the structure could 568*7c478bd9Sstevel@tonic-gate * not be created. The newly created nv list is created and managed by the 569*7c478bd9Sstevel@tonic-gate * operations installed in nva. If nva is NULL, the default FMA nva 570*7c478bd9Sstevel@tonic-gate * operations are installed and used. 571*7c478bd9Sstevel@tonic-gate * 572*7c478bd9Sstevel@tonic-gate * When called from the kernel and nva == NULL, this function must be called 573*7c478bd9Sstevel@tonic-gate * from passive kernel context with no locks held that can prevent a 574*7c478bd9Sstevel@tonic-gate * sleeping memory allocation from occurring. Otherwise, this function may 575*7c478bd9Sstevel@tonic-gate * be called from other kernel contexts as long a valid nva created via 576*7c478bd9Sstevel@tonic-gate * fm_nva_create() is supplied. 577*7c478bd9Sstevel@tonic-gate */ 578*7c478bd9Sstevel@tonic-gate nvlist_t * 579*7c478bd9Sstevel@tonic-gate fm_nvlist_create(nv_alloc_t *nva) 580*7c478bd9Sstevel@tonic-gate { 581*7c478bd9Sstevel@tonic-gate int hdl_alloced = 0; 582*7c478bd9Sstevel@tonic-gate nvlist_t *nvl; 583*7c478bd9Sstevel@tonic-gate nv_alloc_t *nvhdl; 584*7c478bd9Sstevel@tonic-gate 585*7c478bd9Sstevel@tonic-gate if (nva == NULL) { 586*7c478bd9Sstevel@tonic-gate nvhdl = kmem_zalloc(sizeof (nv_alloc_t), KM_SLEEP); 587*7c478bd9Sstevel@tonic-gate 588*7c478bd9Sstevel@tonic-gate if (nv_alloc_init(nvhdl, &fm_mem_alloc_ops, NULL, 0) != 0) { 589*7c478bd9Sstevel@tonic-gate kmem_free(nvhdl, sizeof (nv_alloc_t)); 590*7c478bd9Sstevel@tonic-gate return (NULL); 591*7c478bd9Sstevel@tonic-gate } 592*7c478bd9Sstevel@tonic-gate hdl_alloced = 1; 593*7c478bd9Sstevel@tonic-gate } else { 594*7c478bd9Sstevel@tonic-gate nvhdl = nva; 595*7c478bd9Sstevel@tonic-gate } 596*7c478bd9Sstevel@tonic-gate 597*7c478bd9Sstevel@tonic-gate if (nvlist_xalloc(&nvl, NV_UNIQUE_NAME, nvhdl) != 0) { 598*7c478bd9Sstevel@tonic-gate if (hdl_alloced) { 599*7c478bd9Sstevel@tonic-gate kmem_free(nvhdl, sizeof (nv_alloc_t)); 600*7c478bd9Sstevel@tonic-gate nv_alloc_fini(nvhdl); 601*7c478bd9Sstevel@tonic-gate } 602*7c478bd9Sstevel@tonic-gate return (NULL); 603*7c478bd9Sstevel@tonic-gate } 604*7c478bd9Sstevel@tonic-gate 605*7c478bd9Sstevel@tonic-gate return (nvl); 606*7c478bd9Sstevel@tonic-gate } 607*7c478bd9Sstevel@tonic-gate 608*7c478bd9Sstevel@tonic-gate /* 609*7c478bd9Sstevel@tonic-gate * Destroy a previously allocated nvlist structure. flag indicates whether 610*7c478bd9Sstevel@tonic-gate * or not the associated nva structure should be freed (FM_NVA_FREE) or 611*7c478bd9Sstevel@tonic-gate * retained (FM_NVA_RETAIN). Retaining the nv alloc structure allows 612*7c478bd9Sstevel@tonic-gate * it to be re-used for future nvlist creation operations. 613*7c478bd9Sstevel@tonic-gate */ 614*7c478bd9Sstevel@tonic-gate void 615*7c478bd9Sstevel@tonic-gate fm_nvlist_destroy(nvlist_t *nvl, int flag) 616*7c478bd9Sstevel@tonic-gate { 617*7c478bd9Sstevel@tonic-gate nv_alloc_t *nvhdl; 618*7c478bd9Sstevel@tonic-gate 619*7c478bd9Sstevel@tonic-gate nvhdl = ((nvpriv_t *)(uintptr_t)nvl->nvl_priv)->nvp_nva; 620*7c478bd9Sstevel@tonic-gate 621*7c478bd9Sstevel@tonic-gate nvlist_free(nvl); 622*7c478bd9Sstevel@tonic-gate 623*7c478bd9Sstevel@tonic-gate if (nvhdl != NULL) { 624*7c478bd9Sstevel@tonic-gate if (flag == FM_NVA_FREE) 625*7c478bd9Sstevel@tonic-gate fm_nva_xdestroy(nvhdl); 626*7c478bd9Sstevel@tonic-gate } 627*7c478bd9Sstevel@tonic-gate } 628*7c478bd9Sstevel@tonic-gate 629*7c478bd9Sstevel@tonic-gate int 630*7c478bd9Sstevel@tonic-gate i_fm_payload_set(nvlist_t *payload, const char *name, va_list ap) 631*7c478bd9Sstevel@tonic-gate { 632*7c478bd9Sstevel@tonic-gate int nelem, ret = 0; 633*7c478bd9Sstevel@tonic-gate data_type_t type; 634*7c478bd9Sstevel@tonic-gate 635*7c478bd9Sstevel@tonic-gate while (ret == 0 && name != NULL) { 636*7c478bd9Sstevel@tonic-gate type = va_arg(ap, data_type_t); 637*7c478bd9Sstevel@tonic-gate switch (type) { 638*7c478bd9Sstevel@tonic-gate case DATA_TYPE_BYTE: 639*7c478bd9Sstevel@tonic-gate ret = nvlist_add_byte(payload, name, 640*7c478bd9Sstevel@tonic-gate va_arg(ap, uint_t)); 641*7c478bd9Sstevel@tonic-gate break; 642*7c478bd9Sstevel@tonic-gate case DATA_TYPE_BYTE_ARRAY: 643*7c478bd9Sstevel@tonic-gate nelem = va_arg(ap, int); 644*7c478bd9Sstevel@tonic-gate ret = nvlist_add_byte_array(payload, name, 645*7c478bd9Sstevel@tonic-gate va_arg(ap, uchar_t *), nelem); 646*7c478bd9Sstevel@tonic-gate break; 647*7c478bd9Sstevel@tonic-gate case DATA_TYPE_BOOLEAN_VALUE: 648*7c478bd9Sstevel@tonic-gate ret = nvlist_add_boolean_value(payload, name, 649*7c478bd9Sstevel@tonic-gate va_arg(ap, boolean_t)); 650*7c478bd9Sstevel@tonic-gate break; 651*7c478bd9Sstevel@tonic-gate case DATA_TYPE_BOOLEAN_ARRAY: 652*7c478bd9Sstevel@tonic-gate nelem = va_arg(ap, int); 653*7c478bd9Sstevel@tonic-gate ret = nvlist_add_boolean_array(payload, name, 654*7c478bd9Sstevel@tonic-gate va_arg(ap, boolean_t *), nelem); 655*7c478bd9Sstevel@tonic-gate break; 656*7c478bd9Sstevel@tonic-gate case DATA_TYPE_INT8: 657*7c478bd9Sstevel@tonic-gate ret = nvlist_add_int8(payload, name, 658*7c478bd9Sstevel@tonic-gate va_arg(ap, int)); 659*7c478bd9Sstevel@tonic-gate break; 660*7c478bd9Sstevel@tonic-gate case DATA_TYPE_INT8_ARRAY: 661*7c478bd9Sstevel@tonic-gate nelem = va_arg(ap, int); 662*7c478bd9Sstevel@tonic-gate ret = nvlist_add_int8_array(payload, name, 663*7c478bd9Sstevel@tonic-gate va_arg(ap, int8_t *), nelem); 664*7c478bd9Sstevel@tonic-gate break; 665*7c478bd9Sstevel@tonic-gate case DATA_TYPE_UINT8: 666*7c478bd9Sstevel@tonic-gate ret = nvlist_add_uint8(payload, name, 667*7c478bd9Sstevel@tonic-gate va_arg(ap, uint_t)); 668*7c478bd9Sstevel@tonic-gate break; 669*7c478bd9Sstevel@tonic-gate case DATA_TYPE_UINT8_ARRAY: 670*7c478bd9Sstevel@tonic-gate nelem = va_arg(ap, int); 671*7c478bd9Sstevel@tonic-gate ret = nvlist_add_uint8_array(payload, name, 672*7c478bd9Sstevel@tonic-gate va_arg(ap, uint8_t *), nelem); 673*7c478bd9Sstevel@tonic-gate break; 674*7c478bd9Sstevel@tonic-gate case DATA_TYPE_INT16: 675*7c478bd9Sstevel@tonic-gate ret = nvlist_add_int16(payload, name, 676*7c478bd9Sstevel@tonic-gate va_arg(ap, int)); 677*7c478bd9Sstevel@tonic-gate break; 678*7c478bd9Sstevel@tonic-gate case DATA_TYPE_INT16_ARRAY: 679*7c478bd9Sstevel@tonic-gate nelem = va_arg(ap, int); 680*7c478bd9Sstevel@tonic-gate ret = nvlist_add_int16_array(payload, name, 681*7c478bd9Sstevel@tonic-gate va_arg(ap, int16_t *), nelem); 682*7c478bd9Sstevel@tonic-gate break; 683*7c478bd9Sstevel@tonic-gate case DATA_TYPE_UINT16: 684*7c478bd9Sstevel@tonic-gate ret = nvlist_add_uint16(payload, name, 685*7c478bd9Sstevel@tonic-gate va_arg(ap, uint_t)); 686*7c478bd9Sstevel@tonic-gate break; 687*7c478bd9Sstevel@tonic-gate case DATA_TYPE_UINT16_ARRAY: 688*7c478bd9Sstevel@tonic-gate nelem = va_arg(ap, int); 689*7c478bd9Sstevel@tonic-gate ret = nvlist_add_uint16_array(payload, name, 690*7c478bd9Sstevel@tonic-gate va_arg(ap, uint16_t *), nelem); 691*7c478bd9Sstevel@tonic-gate break; 692*7c478bd9Sstevel@tonic-gate case DATA_TYPE_INT32: 693*7c478bd9Sstevel@tonic-gate ret = nvlist_add_int32(payload, name, 694*7c478bd9Sstevel@tonic-gate va_arg(ap, int32_t)); 695*7c478bd9Sstevel@tonic-gate break; 696*7c478bd9Sstevel@tonic-gate case DATA_TYPE_INT32_ARRAY: 697*7c478bd9Sstevel@tonic-gate nelem = va_arg(ap, int); 698*7c478bd9Sstevel@tonic-gate ret = nvlist_add_int32_array(payload, name, 699*7c478bd9Sstevel@tonic-gate va_arg(ap, int32_t *), nelem); 700*7c478bd9Sstevel@tonic-gate break; 701*7c478bd9Sstevel@tonic-gate case DATA_TYPE_UINT32: 702*7c478bd9Sstevel@tonic-gate ret = nvlist_add_uint32(payload, name, 703*7c478bd9Sstevel@tonic-gate va_arg(ap, uint32_t)); 704*7c478bd9Sstevel@tonic-gate break; 705*7c478bd9Sstevel@tonic-gate case DATA_TYPE_UINT32_ARRAY: 706*7c478bd9Sstevel@tonic-gate nelem = va_arg(ap, int); 707*7c478bd9Sstevel@tonic-gate ret = nvlist_add_uint32_array(payload, name, 708*7c478bd9Sstevel@tonic-gate va_arg(ap, uint32_t *), nelem); 709*7c478bd9Sstevel@tonic-gate break; 710*7c478bd9Sstevel@tonic-gate case DATA_TYPE_INT64: 711*7c478bd9Sstevel@tonic-gate ret = nvlist_add_int64(payload, name, 712*7c478bd9Sstevel@tonic-gate va_arg(ap, int64_t)); 713*7c478bd9Sstevel@tonic-gate break; 714*7c478bd9Sstevel@tonic-gate case DATA_TYPE_INT64_ARRAY: 715*7c478bd9Sstevel@tonic-gate nelem = va_arg(ap, int); 716*7c478bd9Sstevel@tonic-gate ret = nvlist_add_int64_array(payload, name, 717*7c478bd9Sstevel@tonic-gate va_arg(ap, int64_t *), nelem); 718*7c478bd9Sstevel@tonic-gate break; 719*7c478bd9Sstevel@tonic-gate case DATA_TYPE_UINT64: 720*7c478bd9Sstevel@tonic-gate ret = nvlist_add_uint64(payload, name, 721*7c478bd9Sstevel@tonic-gate va_arg(ap, uint64_t)); 722*7c478bd9Sstevel@tonic-gate break; 723*7c478bd9Sstevel@tonic-gate case DATA_TYPE_UINT64_ARRAY: 724*7c478bd9Sstevel@tonic-gate nelem = va_arg(ap, int); 725*7c478bd9Sstevel@tonic-gate ret = nvlist_add_uint64_array(payload, name, 726*7c478bd9Sstevel@tonic-gate va_arg(ap, uint64_t *), nelem); 727*7c478bd9Sstevel@tonic-gate break; 728*7c478bd9Sstevel@tonic-gate case DATA_TYPE_STRING: 729*7c478bd9Sstevel@tonic-gate ret = nvlist_add_string(payload, name, 730*7c478bd9Sstevel@tonic-gate va_arg(ap, char *)); 731*7c478bd9Sstevel@tonic-gate break; 732*7c478bd9Sstevel@tonic-gate case DATA_TYPE_STRING_ARRAY: 733*7c478bd9Sstevel@tonic-gate nelem = va_arg(ap, int); 734*7c478bd9Sstevel@tonic-gate ret = nvlist_add_string_array(payload, name, 735*7c478bd9Sstevel@tonic-gate va_arg(ap, char **), nelem); 736*7c478bd9Sstevel@tonic-gate break; 737*7c478bd9Sstevel@tonic-gate case DATA_TYPE_NVLIST: 738*7c478bd9Sstevel@tonic-gate ret = nvlist_add_nvlist(payload, name, 739*7c478bd9Sstevel@tonic-gate va_arg(ap, nvlist_t *)); 740*7c478bd9Sstevel@tonic-gate break; 741*7c478bd9Sstevel@tonic-gate case DATA_TYPE_NVLIST_ARRAY: 742*7c478bd9Sstevel@tonic-gate nelem = va_arg(ap, int); 743*7c478bd9Sstevel@tonic-gate ret = nvlist_add_nvlist_array(payload, name, 744*7c478bd9Sstevel@tonic-gate va_arg(ap, nvlist_t **), nelem); 745*7c478bd9Sstevel@tonic-gate break; 746*7c478bd9Sstevel@tonic-gate default: 747*7c478bd9Sstevel@tonic-gate ret = EINVAL; 748*7c478bd9Sstevel@tonic-gate } 749*7c478bd9Sstevel@tonic-gate 750*7c478bd9Sstevel@tonic-gate name = va_arg(ap, char *); 751*7c478bd9Sstevel@tonic-gate } 752*7c478bd9Sstevel@tonic-gate return (ret); 753*7c478bd9Sstevel@tonic-gate } 754*7c478bd9Sstevel@tonic-gate 755*7c478bd9Sstevel@tonic-gate void 756*7c478bd9Sstevel@tonic-gate fm_payload_set(nvlist_t *payload, ...) 757*7c478bd9Sstevel@tonic-gate { 758*7c478bd9Sstevel@tonic-gate int ret; 759*7c478bd9Sstevel@tonic-gate const char *name; 760*7c478bd9Sstevel@tonic-gate va_list ap; 761*7c478bd9Sstevel@tonic-gate 762*7c478bd9Sstevel@tonic-gate va_start(ap, payload); 763*7c478bd9Sstevel@tonic-gate name = va_arg(ap, char *); 764*7c478bd9Sstevel@tonic-gate ret = i_fm_payload_set(payload, name, ap); 765*7c478bd9Sstevel@tonic-gate va_end(ap); 766*7c478bd9Sstevel@tonic-gate 767*7c478bd9Sstevel@tonic-gate if (ret) 768*7c478bd9Sstevel@tonic-gate atomic_add_64( 769*7c478bd9Sstevel@tonic-gate &erpt_kstat_data.payload_set_failed.value.ui64, 1); 770*7c478bd9Sstevel@tonic-gate } 771*7c478bd9Sstevel@tonic-gate 772*7c478bd9Sstevel@tonic-gate /* 773*7c478bd9Sstevel@tonic-gate * Set-up and validate the members of an ereport event according to: 774*7c478bd9Sstevel@tonic-gate * 775*7c478bd9Sstevel@tonic-gate * Member name Type Value 776*7c478bd9Sstevel@tonic-gate * ==================================================== 777*7c478bd9Sstevel@tonic-gate * class string ereport 778*7c478bd9Sstevel@tonic-gate * version uint8_t 0 779*7c478bd9Sstevel@tonic-gate * ena uint64_t <ena> 780*7c478bd9Sstevel@tonic-gate * detector nvlist_t <detector> 781*7c478bd9Sstevel@tonic-gate * ereport-payload nvlist_t <var args> 782*7c478bd9Sstevel@tonic-gate * 783*7c478bd9Sstevel@tonic-gate */ 784*7c478bd9Sstevel@tonic-gate void 785*7c478bd9Sstevel@tonic-gate fm_ereport_set(nvlist_t *ereport, int version, const char *erpt_class, 786*7c478bd9Sstevel@tonic-gate uint64_t ena, const nvlist_t *detector, ...) 787*7c478bd9Sstevel@tonic-gate { 788*7c478bd9Sstevel@tonic-gate char ereport_class[FM_MAX_CLASS]; 789*7c478bd9Sstevel@tonic-gate const char *name; 790*7c478bd9Sstevel@tonic-gate va_list ap; 791*7c478bd9Sstevel@tonic-gate int ret; 792*7c478bd9Sstevel@tonic-gate 793*7c478bd9Sstevel@tonic-gate if (version != FM_EREPORT_VERS0) { 794*7c478bd9Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1); 795*7c478bd9Sstevel@tonic-gate return; 796*7c478bd9Sstevel@tonic-gate } 797*7c478bd9Sstevel@tonic-gate 798*7c478bd9Sstevel@tonic-gate (void) snprintf(ereport_class, FM_MAX_CLASS, "%s.%s", 799*7c478bd9Sstevel@tonic-gate FM_EREPORT_CLASS, erpt_class); 800*7c478bd9Sstevel@tonic-gate if (nvlist_add_string(ereport, FM_CLASS, ereport_class) != 0) { 801*7c478bd9Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1); 802*7c478bd9Sstevel@tonic-gate return; 803*7c478bd9Sstevel@tonic-gate } 804*7c478bd9Sstevel@tonic-gate 805*7c478bd9Sstevel@tonic-gate if (nvlist_add_uint64(ereport, FM_EREPORT_ENA, ena)) { 806*7c478bd9Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1); 807*7c478bd9Sstevel@tonic-gate } 808*7c478bd9Sstevel@tonic-gate 809*7c478bd9Sstevel@tonic-gate if (nvlist_add_nvlist(ereport, FM_EREPORT_DETECTOR, 810*7c478bd9Sstevel@tonic-gate (nvlist_t *)detector) != 0) { 811*7c478bd9Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1); 812*7c478bd9Sstevel@tonic-gate } 813*7c478bd9Sstevel@tonic-gate 814*7c478bd9Sstevel@tonic-gate va_start(ap, detector); 815*7c478bd9Sstevel@tonic-gate name = va_arg(ap, const char *); 816*7c478bd9Sstevel@tonic-gate ret = i_fm_payload_set(ereport, name, ap); 817*7c478bd9Sstevel@tonic-gate va_end(ap); 818*7c478bd9Sstevel@tonic-gate 819*7c478bd9Sstevel@tonic-gate if (ret) 820*7c478bd9Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1); 821*7c478bd9Sstevel@tonic-gate } 822*7c478bd9Sstevel@tonic-gate 823*7c478bd9Sstevel@tonic-gate static int 824*7c478bd9Sstevel@tonic-gate i_fm_fmri_hc_set_v0(nvlist_t *hc, uint32_t size, va_list ap) 825*7c478bd9Sstevel@tonic-gate { 826*7c478bd9Sstevel@tonic-gate int i, ret; 827*7c478bd9Sstevel@tonic-gate const char *name, *id; 828*7c478bd9Sstevel@tonic-gate nvlist_t **hc_nvl; 829*7c478bd9Sstevel@tonic-gate 830*7c478bd9Sstevel@tonic-gate if (size <= 0) 831*7c478bd9Sstevel@tonic-gate return (0); 832*7c478bd9Sstevel@tonic-gate 833*7c478bd9Sstevel@tonic-gate hc_nvl = kmem_zalloc(size * sizeof (nvlist_t *), KM_SLEEP); 834*7c478bd9Sstevel@tonic-gate 835*7c478bd9Sstevel@tonic-gate for (i = 0; i < size; ++i) { 836*7c478bd9Sstevel@tonic-gate name = va_arg(ap, const char *); 837*7c478bd9Sstevel@tonic-gate if (name == NULL) { 838*7c478bd9Sstevel@tonic-gate ret = EINVAL; 839*7c478bd9Sstevel@tonic-gate goto fail; 840*7c478bd9Sstevel@tonic-gate } 841*7c478bd9Sstevel@tonic-gate id = va_arg(ap, const char *); 842*7c478bd9Sstevel@tonic-gate if ((hc_nvl[i] = fm_nvlist_create( 843*7c478bd9Sstevel@tonic-gate ((nvpriv_t *)(uintptr_t)hc->nvl_priv)->nvp_nva)) == NULL) { 844*7c478bd9Sstevel@tonic-gate ret = ENOMEM; 845*7c478bd9Sstevel@tonic-gate goto fail; 846*7c478bd9Sstevel@tonic-gate } 847*7c478bd9Sstevel@tonic-gate if ((ret = nvlist_add_string(hc_nvl[i], FM_FMRI_HC_NAME, 848*7c478bd9Sstevel@tonic-gate name)) != 0) 849*7c478bd9Sstevel@tonic-gate goto fail; 850*7c478bd9Sstevel@tonic-gate if ((ret = nvlist_add_string(hc_nvl[i], FM_FMRI_HC_ID, 851*7c478bd9Sstevel@tonic-gate id)) != 0) 852*7c478bd9Sstevel@tonic-gate goto fail; 853*7c478bd9Sstevel@tonic-gate } 854*7c478bd9Sstevel@tonic-gate 855*7c478bd9Sstevel@tonic-gate if ((ret = nvlist_add_nvlist_array(hc, FM_FMRI_HC_LIST, hc_nvl, 856*7c478bd9Sstevel@tonic-gate size)) != 0) 857*7c478bd9Sstevel@tonic-gate goto fail; 858*7c478bd9Sstevel@tonic-gate 859*7c478bd9Sstevel@tonic-gate kmem_free(hc_nvl, size * sizeof (nvlist_t *)); 860*7c478bd9Sstevel@tonic-gate return (0); 861*7c478bd9Sstevel@tonic-gate 862*7c478bd9Sstevel@tonic-gate fail: 863*7c478bd9Sstevel@tonic-gate for (i = 0; i < size; ++i) { 864*7c478bd9Sstevel@tonic-gate if (hc_nvl[i] != NULL) 865*7c478bd9Sstevel@tonic-gate fm_nvlist_destroy(hc_nvl[i], FM_NVA_RETAIN); 866*7c478bd9Sstevel@tonic-gate } 867*7c478bd9Sstevel@tonic-gate 868*7c478bd9Sstevel@tonic-gate kmem_free(hc_nvl, size * sizeof (nvlist_t *)); 869*7c478bd9Sstevel@tonic-gate return (ret); 870*7c478bd9Sstevel@tonic-gate } 871*7c478bd9Sstevel@tonic-gate 872*7c478bd9Sstevel@tonic-gate /* 873*7c478bd9Sstevel@tonic-gate * Set-up and validate the members of an dev fmri according to: 874*7c478bd9Sstevel@tonic-gate * 875*7c478bd9Sstevel@tonic-gate * Member name Type Value 876*7c478bd9Sstevel@tonic-gate * ==================================================== 877*7c478bd9Sstevel@tonic-gate * version uint8_t 0 878*7c478bd9Sstevel@tonic-gate * auth nvlist_t <auth> 879*7c478bd9Sstevel@tonic-gate * devpath string <devpath> 880*7c478bd9Sstevel@tonic-gate * devid string <devid> 881*7c478bd9Sstevel@tonic-gate * 882*7c478bd9Sstevel@tonic-gate * Note that auth and devid are optional members. 883*7c478bd9Sstevel@tonic-gate */ 884*7c478bd9Sstevel@tonic-gate void 885*7c478bd9Sstevel@tonic-gate fm_fmri_dev_set(nvlist_t *fmri_dev, int version, const nvlist_t *auth, 886*7c478bd9Sstevel@tonic-gate const char *devpath, const char *devid) 887*7c478bd9Sstevel@tonic-gate { 888*7c478bd9Sstevel@tonic-gate if (version != DEV_SCHEME_VERSION0) { 889*7c478bd9Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 890*7c478bd9Sstevel@tonic-gate return; 891*7c478bd9Sstevel@tonic-gate } 892*7c478bd9Sstevel@tonic-gate 893*7c478bd9Sstevel@tonic-gate if (nvlist_add_uint8(fmri_dev, FM_VERSION, version) != 0) { 894*7c478bd9Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 895*7c478bd9Sstevel@tonic-gate return; 896*7c478bd9Sstevel@tonic-gate } 897*7c478bd9Sstevel@tonic-gate 898*7c478bd9Sstevel@tonic-gate if (nvlist_add_string(fmri_dev, FM_FMRI_SCHEME, 899*7c478bd9Sstevel@tonic-gate FM_FMRI_SCHEME_DEV) != 0) { 900*7c478bd9Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 901*7c478bd9Sstevel@tonic-gate return; 902*7c478bd9Sstevel@tonic-gate } 903*7c478bd9Sstevel@tonic-gate 904*7c478bd9Sstevel@tonic-gate if (auth != NULL) { 905*7c478bd9Sstevel@tonic-gate if (nvlist_add_nvlist(fmri_dev, FM_FMRI_AUTHORITY, 906*7c478bd9Sstevel@tonic-gate (nvlist_t *)auth) != 0) { 907*7c478bd9Sstevel@tonic-gate atomic_add_64( 908*7c478bd9Sstevel@tonic-gate &erpt_kstat_data.fmri_set_failed.value.ui64, 1); 909*7c478bd9Sstevel@tonic-gate } 910*7c478bd9Sstevel@tonic-gate } 911*7c478bd9Sstevel@tonic-gate 912*7c478bd9Sstevel@tonic-gate if (nvlist_add_string(fmri_dev, FM_FMRI_DEV_PATH, devpath) != 0) { 913*7c478bd9Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 914*7c478bd9Sstevel@tonic-gate } 915*7c478bd9Sstevel@tonic-gate 916*7c478bd9Sstevel@tonic-gate if (devid != NULL) 917*7c478bd9Sstevel@tonic-gate if (nvlist_add_string(fmri_dev, FM_FMRI_DEV_ID, devid) != 0) 918*7c478bd9Sstevel@tonic-gate atomic_add_64( 919*7c478bd9Sstevel@tonic-gate &erpt_kstat_data.fmri_set_failed.value.ui64, 1); 920*7c478bd9Sstevel@tonic-gate } 921*7c478bd9Sstevel@tonic-gate 922*7c478bd9Sstevel@tonic-gate /* 923*7c478bd9Sstevel@tonic-gate * Set-up and validate the members of an cpu fmri according to: 924*7c478bd9Sstevel@tonic-gate * 925*7c478bd9Sstevel@tonic-gate * Member name Type Value 926*7c478bd9Sstevel@tonic-gate * ==================================================== 927*7c478bd9Sstevel@tonic-gate * version uint8_t 0 928*7c478bd9Sstevel@tonic-gate * auth nvlist_t <auth> 929*7c478bd9Sstevel@tonic-gate * cpuid uint32_t <cpu_id> 930*7c478bd9Sstevel@tonic-gate * cpumask uint8_t <cpu_mask> 931*7c478bd9Sstevel@tonic-gate * serial uint64_t <serial_id> 932*7c478bd9Sstevel@tonic-gate * 933*7c478bd9Sstevel@tonic-gate * Note that auth is an optional member. 934*7c478bd9Sstevel@tonic-gate * 935*7c478bd9Sstevel@tonic-gate */ 936*7c478bd9Sstevel@tonic-gate void 937*7c478bd9Sstevel@tonic-gate fm_fmri_cpu_set(nvlist_t *fmri_cpu, int version, const nvlist_t *auth, 938*7c478bd9Sstevel@tonic-gate uint32_t cpu_id, uint8_t cpu_mask, uint64_t serial_id) 939*7c478bd9Sstevel@tonic-gate { 940*7c478bd9Sstevel@tonic-gate if (version != CPU_SCHEME_VERSION0) { 941*7c478bd9Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 942*7c478bd9Sstevel@tonic-gate return; 943*7c478bd9Sstevel@tonic-gate } 944*7c478bd9Sstevel@tonic-gate 945*7c478bd9Sstevel@tonic-gate if (nvlist_add_uint8(fmri_cpu, FM_VERSION, version) != 0) { 946*7c478bd9Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 947*7c478bd9Sstevel@tonic-gate return; 948*7c478bd9Sstevel@tonic-gate } 949*7c478bd9Sstevel@tonic-gate 950*7c478bd9Sstevel@tonic-gate if (nvlist_add_string(fmri_cpu, FM_FMRI_SCHEME, 951*7c478bd9Sstevel@tonic-gate FM_FMRI_SCHEME_CPU) != 0) { 952*7c478bd9Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 953*7c478bd9Sstevel@tonic-gate return; 954*7c478bd9Sstevel@tonic-gate } 955*7c478bd9Sstevel@tonic-gate 956*7c478bd9Sstevel@tonic-gate if (auth != NULL) 957*7c478bd9Sstevel@tonic-gate if (nvlist_add_nvlist(fmri_cpu, FM_FMRI_AUTHORITY, 958*7c478bd9Sstevel@tonic-gate (nvlist_t *)auth) != 0) { 959*7c478bd9Sstevel@tonic-gate atomic_add_64( 960*7c478bd9Sstevel@tonic-gate &erpt_kstat_data.fmri_set_failed.value.ui64, 1); 961*7c478bd9Sstevel@tonic-gate } 962*7c478bd9Sstevel@tonic-gate 963*7c478bd9Sstevel@tonic-gate if (nvlist_add_uint32(fmri_cpu, FM_FMRI_CPU_ID, cpu_id) != 0) { 964*7c478bd9Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 965*7c478bd9Sstevel@tonic-gate } 966*7c478bd9Sstevel@tonic-gate 967*7c478bd9Sstevel@tonic-gate if (nvlist_add_uint8(fmri_cpu, FM_FMRI_CPU_MASK, cpu_mask) != 0) { 968*7c478bd9Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 969*7c478bd9Sstevel@tonic-gate } 970*7c478bd9Sstevel@tonic-gate 971*7c478bd9Sstevel@tonic-gate if (nvlist_add_uint64(fmri_cpu, FM_FMRI_CPU_SERIAL_ID, serial_id) 972*7c478bd9Sstevel@tonic-gate != 0) 973*7c478bd9Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 974*7c478bd9Sstevel@tonic-gate } 975*7c478bd9Sstevel@tonic-gate 976*7c478bd9Sstevel@tonic-gate /* 977*7c478bd9Sstevel@tonic-gate * Set-up and validate the members of a mem according to: 978*7c478bd9Sstevel@tonic-gate * 979*7c478bd9Sstevel@tonic-gate * Member name Type Value 980*7c478bd9Sstevel@tonic-gate * ==================================================== 981*7c478bd9Sstevel@tonic-gate * version uint8_t 0 982*7c478bd9Sstevel@tonic-gate * auth nvlist_t <auth> [optional] 983*7c478bd9Sstevel@tonic-gate * unum string <unum> 984*7c478bd9Sstevel@tonic-gate * serial string <serial> [optional] 985*7c478bd9Sstevel@tonic-gate * 986*7c478bd9Sstevel@tonic-gate */ 987*7c478bd9Sstevel@tonic-gate void 988*7c478bd9Sstevel@tonic-gate fm_fmri_mem_set(nvlist_t *fmri, int version, const nvlist_t *auth, 989*7c478bd9Sstevel@tonic-gate const char *unum, const char *serial) 990*7c478bd9Sstevel@tonic-gate { 991*7c478bd9Sstevel@tonic-gate if (version != MEM_SCHEME_VERSION0) { 992*7c478bd9Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 993*7c478bd9Sstevel@tonic-gate return; 994*7c478bd9Sstevel@tonic-gate } 995*7c478bd9Sstevel@tonic-gate 996*7c478bd9Sstevel@tonic-gate if (nvlist_add_uint8(fmri, FM_VERSION, version) != 0) { 997*7c478bd9Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 998*7c478bd9Sstevel@tonic-gate return; 999*7c478bd9Sstevel@tonic-gate } 1000*7c478bd9Sstevel@tonic-gate 1001*7c478bd9Sstevel@tonic-gate if (nvlist_add_string(fmri, FM_FMRI_SCHEME, FM_FMRI_SCHEME_MEM) != 0) { 1002*7c478bd9Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 1003*7c478bd9Sstevel@tonic-gate return; 1004*7c478bd9Sstevel@tonic-gate } 1005*7c478bd9Sstevel@tonic-gate 1006*7c478bd9Sstevel@tonic-gate if (auth != NULL) { 1007*7c478bd9Sstevel@tonic-gate if (nvlist_add_nvlist(fmri, FM_FMRI_AUTHORITY, 1008*7c478bd9Sstevel@tonic-gate (nvlist_t *)auth) != 0) { 1009*7c478bd9Sstevel@tonic-gate atomic_add_64( 1010*7c478bd9Sstevel@tonic-gate &erpt_kstat_data.fmri_set_failed.value.ui64, 1); 1011*7c478bd9Sstevel@tonic-gate } 1012*7c478bd9Sstevel@tonic-gate } 1013*7c478bd9Sstevel@tonic-gate 1014*7c478bd9Sstevel@tonic-gate if (nvlist_add_string(fmri, FM_FMRI_MEM_UNUM, unum) != 0) { 1015*7c478bd9Sstevel@tonic-gate atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); 1016*7c478bd9Sstevel@tonic-gate } 1017*7c478bd9Sstevel@tonic-gate 1018*7c478bd9Sstevel@tonic-gate if (serial != NULL) { 1019*7c478bd9Sstevel@tonic-gate if (nvlist_add_string_array(fmri, FM_FMRI_MEM_SERIAL_ID, 1020*7c478bd9Sstevel@tonic-gate (char **)&serial, 1) != 0) { 1021*7c478bd9Sstevel@tonic-gate atomic_add_64( 1022*7c478bd9Sstevel@tonic-gate &erpt_kstat_data.fmri_set_failed.value.ui64, 1); 1023*7c478bd9Sstevel@tonic-gate } 1024*7c478bd9Sstevel@tonic-gate } 1025*7c478bd9Sstevel@tonic-gate } 1026*7c478bd9Sstevel@tonic-gate 1027*7c478bd9Sstevel@tonic-gate uint64_t 1028*7c478bd9Sstevel@tonic-gate fm_ena_increment(uint64_t ena) 1029*7c478bd9Sstevel@tonic-gate { 1030*7c478bd9Sstevel@tonic-gate uint64_t new_ena; 1031*7c478bd9Sstevel@tonic-gate 1032*7c478bd9Sstevel@tonic-gate switch (ENA_FORMAT(ena)) { 1033*7c478bd9Sstevel@tonic-gate case FM_ENA_FMT1: 1034*7c478bd9Sstevel@tonic-gate new_ena = ena + (1 << ENA_FMT1_GEN_SHFT); 1035*7c478bd9Sstevel@tonic-gate break; 1036*7c478bd9Sstevel@tonic-gate case FM_ENA_FMT2: 1037*7c478bd9Sstevel@tonic-gate new_ena = ena + (1 << ENA_FMT2_GEN_SHFT); 1038*7c478bd9Sstevel@tonic-gate break; 1039*7c478bd9Sstevel@tonic-gate default: 1040*7c478bd9Sstevel@tonic-gate new_ena = 0; 1041*7c478bd9Sstevel@tonic-gate } 1042*7c478bd9Sstevel@tonic-gate 1043*7c478bd9Sstevel@tonic-gate return (new_ena); 1044*7c478bd9Sstevel@tonic-gate } 1045*7c478bd9Sstevel@tonic-gate 1046*7c478bd9Sstevel@tonic-gate uint64_t 1047*7c478bd9Sstevel@tonic-gate fm_ena_generate_cpu(uint64_t timestamp, processorid_t cpuid, uchar_t format) 1048*7c478bd9Sstevel@tonic-gate { 1049*7c478bd9Sstevel@tonic-gate uint64_t ena = 0; 1050*7c478bd9Sstevel@tonic-gate 1051*7c478bd9Sstevel@tonic-gate switch (format) { 1052*7c478bd9Sstevel@tonic-gate case FM_ENA_FMT1: 1053*7c478bd9Sstevel@tonic-gate if (timestamp) { 1054*7c478bd9Sstevel@tonic-gate ena = (uint64_t)((format & ENA_FORMAT_MASK) | 1055*7c478bd9Sstevel@tonic-gate ((cpuid << ENA_FMT1_CPUID_SHFT) & 1056*7c478bd9Sstevel@tonic-gate ENA_FMT1_CPUID_MASK) | 1057*7c478bd9Sstevel@tonic-gate ((timestamp << ENA_FMT1_TIME_SHFT) & 1058*7c478bd9Sstevel@tonic-gate ENA_FMT1_TIME_MASK)); 1059*7c478bd9Sstevel@tonic-gate } else { 1060*7c478bd9Sstevel@tonic-gate ena = (uint64_t)((format & ENA_FORMAT_MASK) | 1061*7c478bd9Sstevel@tonic-gate ((cpuid << ENA_FMT1_CPUID_SHFT) & 1062*7c478bd9Sstevel@tonic-gate ENA_FMT1_CPUID_MASK) | 1063*7c478bd9Sstevel@tonic-gate ((gethrtime_waitfree() << ENA_FMT1_TIME_SHFT) & 1064*7c478bd9Sstevel@tonic-gate ENA_FMT1_TIME_MASK)); 1065*7c478bd9Sstevel@tonic-gate } 1066*7c478bd9Sstevel@tonic-gate break; 1067*7c478bd9Sstevel@tonic-gate case FM_ENA_FMT2: 1068*7c478bd9Sstevel@tonic-gate ena = (uint64_t)((format & ENA_FORMAT_MASK) | 1069*7c478bd9Sstevel@tonic-gate ((timestamp << ENA_FMT2_TIME_SHFT) & ENA_FMT2_TIME_MASK)); 1070*7c478bd9Sstevel@tonic-gate break; 1071*7c478bd9Sstevel@tonic-gate default: 1072*7c478bd9Sstevel@tonic-gate break; 1073*7c478bd9Sstevel@tonic-gate } 1074*7c478bd9Sstevel@tonic-gate 1075*7c478bd9Sstevel@tonic-gate return (ena); 1076*7c478bd9Sstevel@tonic-gate } 1077*7c478bd9Sstevel@tonic-gate 1078*7c478bd9Sstevel@tonic-gate uint64_t 1079*7c478bd9Sstevel@tonic-gate fm_ena_generate(uint64_t timestamp, uchar_t format) 1080*7c478bd9Sstevel@tonic-gate { 1081*7c478bd9Sstevel@tonic-gate return (fm_ena_generate_cpu(timestamp, CPU->cpu_id, format)); 1082*7c478bd9Sstevel@tonic-gate } 1083*7c478bd9Sstevel@tonic-gate 1084*7c478bd9Sstevel@tonic-gate uint64_t 1085*7c478bd9Sstevel@tonic-gate fm_ena_generation_get(uint64_t ena) 1086*7c478bd9Sstevel@tonic-gate { 1087*7c478bd9Sstevel@tonic-gate uint64_t gen; 1088*7c478bd9Sstevel@tonic-gate 1089*7c478bd9Sstevel@tonic-gate switch (ENA_FORMAT(ena)) { 1090*7c478bd9Sstevel@tonic-gate case FM_ENA_FMT1: 1091*7c478bd9Sstevel@tonic-gate gen = (ena & ENA_FMT1_GEN_MASK) >> ENA_FMT1_GEN_SHFT; 1092*7c478bd9Sstevel@tonic-gate break; 1093*7c478bd9Sstevel@tonic-gate case FM_ENA_FMT2: 1094*7c478bd9Sstevel@tonic-gate gen = (ena & ENA_FMT2_GEN_MASK) >> ENA_FMT2_GEN_SHFT; 1095*7c478bd9Sstevel@tonic-gate break; 1096*7c478bd9Sstevel@tonic-gate default: 1097*7c478bd9Sstevel@tonic-gate gen = 0; 1098*7c478bd9Sstevel@tonic-gate break; 1099*7c478bd9Sstevel@tonic-gate } 1100*7c478bd9Sstevel@tonic-gate 1101*7c478bd9Sstevel@tonic-gate return (gen); 1102*7c478bd9Sstevel@tonic-gate } 1103*7c478bd9Sstevel@tonic-gate 1104*7c478bd9Sstevel@tonic-gate uchar_t 1105*7c478bd9Sstevel@tonic-gate fm_ena_format_get(uint64_t ena) 1106*7c478bd9Sstevel@tonic-gate { 1107*7c478bd9Sstevel@tonic-gate 1108*7c478bd9Sstevel@tonic-gate return (ENA_FORMAT(ena)); 1109*7c478bd9Sstevel@tonic-gate } 1110*7c478bd9Sstevel@tonic-gate 1111*7c478bd9Sstevel@tonic-gate uint64_t 1112*7c478bd9Sstevel@tonic-gate fm_ena_id_get(uint64_t ena) 1113*7c478bd9Sstevel@tonic-gate { 1114*7c478bd9Sstevel@tonic-gate uint64_t id; 1115*7c478bd9Sstevel@tonic-gate 1116*7c478bd9Sstevel@tonic-gate switch (ENA_FORMAT(ena)) { 1117*7c478bd9Sstevel@tonic-gate case FM_ENA_FMT1: 1118*7c478bd9Sstevel@tonic-gate id = (ena & ENA_FMT1_ID_MASK) >> ENA_FMT1_ID_SHFT; 1119*7c478bd9Sstevel@tonic-gate break; 1120*7c478bd9Sstevel@tonic-gate case FM_ENA_FMT2: 1121*7c478bd9Sstevel@tonic-gate id = (ena & ENA_FMT2_ID_MASK) >> ENA_FMT2_ID_SHFT; 1122*7c478bd9Sstevel@tonic-gate break; 1123*7c478bd9Sstevel@tonic-gate default: 1124*7c478bd9Sstevel@tonic-gate id = 0; 1125*7c478bd9Sstevel@tonic-gate } 1126*7c478bd9Sstevel@tonic-gate 1127*7c478bd9Sstevel@tonic-gate return (id); 1128*7c478bd9Sstevel@tonic-gate } 1129*7c478bd9Sstevel@tonic-gate 1130*7c478bd9Sstevel@tonic-gate uint64_t 1131*7c478bd9Sstevel@tonic-gate fm_ena_time_get(uint64_t ena) 1132*7c478bd9Sstevel@tonic-gate { 1133*7c478bd9Sstevel@tonic-gate uint64_t time; 1134*7c478bd9Sstevel@tonic-gate 1135*7c478bd9Sstevel@tonic-gate switch (ENA_FORMAT(ena)) { 1136*7c478bd9Sstevel@tonic-gate case FM_ENA_FMT1: 1137*7c478bd9Sstevel@tonic-gate time = (ena & ENA_FMT1_TIME_MASK) >> ENA_FMT1_TIME_SHFT; 1138*7c478bd9Sstevel@tonic-gate break; 1139*7c478bd9Sstevel@tonic-gate case FM_ENA_FMT2: 1140*7c478bd9Sstevel@tonic-gate time = (ena & ENA_FMT2_TIME_MASK) >> ENA_FMT2_TIME_SHFT; 1141*7c478bd9Sstevel@tonic-gate break; 1142*7c478bd9Sstevel@tonic-gate default: 1143*7c478bd9Sstevel@tonic-gate time = 0; 1144*7c478bd9Sstevel@tonic-gate } 1145*7c478bd9Sstevel@tonic-gate 1146*7c478bd9Sstevel@tonic-gate return (time); 1147*7c478bd9Sstevel@tonic-gate } 1148