10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
210Sstevel@tonic-gate */
220Sstevel@tonic-gate /*
23457Sbmc * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
280Sstevel@tonic-gate
290Sstevel@tonic-gate #include <stdarg.h>
300Sstevel@tonic-gate #include <sys/param.h>
310Sstevel@tonic-gate #include <errno.h>
320Sstevel@tonic-gate #include <string.h>
330Sstevel@tonic-gate #include <unistd.h>
340Sstevel@tonic-gate #include <strings.h>
350Sstevel@tonic-gate #include <kstat.h>
360Sstevel@tonic-gate #include <fm/fmd_api.h>
370Sstevel@tonic-gate #include <sys/fm/protocol.h>
380Sstevel@tonic-gate #include <sys/async.h>
390Sstevel@tonic-gate
400Sstevel@tonic-gate #define IOD_STAT_BUMP(name) iod.iod_stats->name.fmds_value.ui64++
410Sstevel@tonic-gate
420Sstevel@tonic-gate /*
430Sstevel@tonic-gate * USII-io-diagnosis:
440Sstevel@tonic-gate *
450Sstevel@tonic-gate * This diagnosis engine consumes the Psycho based IO UEs and CEs
460Sstevel@tonic-gate * which are generated due to DMA Reads or Writes.
470Sstevel@tonic-gate *
480Sstevel@tonic-gate * When a UE is received it will generate the appropriate fault
490Sstevel@tonic-gate * (defect.ultraSPARC-II.memory.nodiag). This is because we do not plan
500Sstevel@tonic-gate * to currently add greater diagnosis capabilities for USII systems.
510Sstevel@tonic-gate *
520Sstevel@tonic-gate * When a CE is received we allow the legacy in kernel SERD do it's job
530Sstevel@tonic-gate * and we just bump a counter here. The legacy SERD algorithm will print
540Sstevel@tonic-gate * out a message and retire pages when the SERD threshold is reached.
550Sstevel@tonic-gate *
560Sstevel@tonic-gate */
570Sstevel@tonic-gate static void iod_recv(fmd_hdl_t *, fmd_event_t *, nvlist_t *, const char *);
580Sstevel@tonic-gate
590Sstevel@tonic-gate typedef struct iod_stat {
600Sstevel@tonic-gate fmd_stat_t ue; /* # of UEs received */
610Sstevel@tonic-gate fmd_stat_t ce; /* # of CEs received */
620Sstevel@tonic-gate } iod_stat_t;
630Sstevel@tonic-gate
640Sstevel@tonic-gate typedef struct iod {
650Sstevel@tonic-gate iod_stat_t *iod_stats; /* Module statistics */
660Sstevel@tonic-gate } iod_t;
670Sstevel@tonic-gate
680Sstevel@tonic-gate static const fmd_hdl_ops_t fmd_ops = {
690Sstevel@tonic-gate iod_recv, /* fmdo_recv */
700Sstevel@tonic-gate NULL, /* fmdo_timeout */
710Sstevel@tonic-gate NULL, /* fmdo_close */
720Sstevel@tonic-gate NULL, /* fmdo_stats */
730Sstevel@tonic-gate NULL /* fmdo_gc */
740Sstevel@tonic-gate };
750Sstevel@tonic-gate
760Sstevel@tonic-gate static const fmd_hdl_info_t fmd_info = {
770Sstevel@tonic-gate "UltraSPARC-II I/O Diagnosis", IOD_VERSION, &fmd_ops, NULL
780Sstevel@tonic-gate };
790Sstevel@tonic-gate
800Sstevel@tonic-gate static const iod_stat_t iod_stat = {
810Sstevel@tonic-gate { "ue", FMD_TYPE_UINT64, "number of received IO UEs" },
820Sstevel@tonic-gate { "ce", FMD_TYPE_UINT64, "number of received IO CEs" }
830Sstevel@tonic-gate };
840Sstevel@tonic-gate
850Sstevel@tonic-gate iod_t iod;
860Sstevel@tonic-gate
870Sstevel@tonic-gate /*ARGSUSED*/
880Sstevel@tonic-gate static void
iod_recv(fmd_hdl_t * hdl,fmd_event_t * ep,nvlist_t * nvl,const char * class)890Sstevel@tonic-gate iod_recv(fmd_hdl_t *hdl, fmd_event_t *ep, nvlist_t *nvl, const char *class)
900Sstevel@tonic-gate {
910Sstevel@tonic-gate fmd_case_t *cp;
920Sstevel@tonic-gate nvlist_t *fault;
930Sstevel@tonic-gate char flt[] = "defect.ultraSPARC-II.memory.nodiag";
940Sstevel@tonic-gate
950Sstevel@tonic-gate if (fmd_nvl_class_match(hdl, nvl, "*ue")) {
960Sstevel@tonic-gate IOD_STAT_BUMP(ue);
970Sstevel@tonic-gate cp = fmd_case_open(hdl, NULL);
980Sstevel@tonic-gate fault = fmd_nvl_create_fault(hdl, flt, 100, NULL, NULL, NULL);
99*933Strevtom fmd_case_add_ereport(hdl, cp, ep);
1000Sstevel@tonic-gate fmd_case_add_suspect(hdl, cp, fault);
1010Sstevel@tonic-gate fmd_case_solve(hdl, cp);
1020Sstevel@tonic-gate } else if (fmd_nvl_class_match(hdl, nvl, "*ce")) {
1030Sstevel@tonic-gate IOD_STAT_BUMP(ce);
1040Sstevel@tonic-gate }
1050Sstevel@tonic-gate }
1060Sstevel@tonic-gate
1070Sstevel@tonic-gate int
iod_cpu_check_support(void)1080Sstevel@tonic-gate iod_cpu_check_support(void)
1090Sstevel@tonic-gate {
1100Sstevel@tonic-gate kstat_named_t *kn;
1110Sstevel@tonic-gate kstat_ctl_t *kc;
1120Sstevel@tonic-gate kstat_t *ksp;
1130Sstevel@tonic-gate int i;
1140Sstevel@tonic-gate
1150Sstevel@tonic-gate if ((kc = kstat_open()) == NULL)
1160Sstevel@tonic-gate return (0);
1170Sstevel@tonic-gate
1180Sstevel@tonic-gate for (ksp = kc->kc_chain; ksp != NULL; ksp = ksp->ks_next) {
1190Sstevel@tonic-gate if (strcmp(ksp->ks_module, "cpu_info") != 0)
1200Sstevel@tonic-gate continue;
1210Sstevel@tonic-gate
1220Sstevel@tonic-gate if (kstat_read(kc, ksp, NULL) == -1) {
1230Sstevel@tonic-gate (void) kstat_close(kc);
1240Sstevel@tonic-gate return (0);
1250Sstevel@tonic-gate }
1260Sstevel@tonic-gate
1270Sstevel@tonic-gate for (kn = ksp->ks_data, i = 0; i < ksp->ks_ndata; i++, kn++) {
1280Sstevel@tonic-gate if (strcmp(kn->name, "implementation") != 0)
1290Sstevel@tonic-gate continue;
1300Sstevel@tonic-gate
131457Sbmc if (strncmp(KSTAT_NAMED_STR_PTR(kn), "UltraSPARC-II",
1320Sstevel@tonic-gate sizeof ("UltraSPARC-II") - 1) == 0 &&
133457Sbmc strncmp(KSTAT_NAMED_STR_PTR(kn), "UltraSPARC-III",
1340Sstevel@tonic-gate sizeof ("UltraSPARC-III") - 1) != 0) {
1350Sstevel@tonic-gate (void) kstat_close(kc);
1360Sstevel@tonic-gate return (1);
1370Sstevel@tonic-gate }
1380Sstevel@tonic-gate }
1390Sstevel@tonic-gate }
1400Sstevel@tonic-gate
1410Sstevel@tonic-gate (void) kstat_close(kc);
1420Sstevel@tonic-gate return (0);
1430Sstevel@tonic-gate }
1440Sstevel@tonic-gate
1450Sstevel@tonic-gate void
_fmd_init(fmd_hdl_t * hdl)1460Sstevel@tonic-gate _fmd_init(fmd_hdl_t *hdl)
1470Sstevel@tonic-gate {
1480Sstevel@tonic-gate if (fmd_hdl_register(hdl, FMD_API_VERSION, &fmd_info) != 0)
1490Sstevel@tonic-gate return; /* error in configuration file or fmd_info */
1500Sstevel@tonic-gate
1510Sstevel@tonic-gate if (!iod_cpu_check_support()) {
1520Sstevel@tonic-gate fmd_hdl_debug(hdl, "no supported CPUs found");
1530Sstevel@tonic-gate fmd_hdl_unregister(hdl);
1540Sstevel@tonic-gate return;
1550Sstevel@tonic-gate }
1560Sstevel@tonic-gate
1570Sstevel@tonic-gate fmd_hdl_subscribe(hdl, "ereport.io.psy.ecc.drue");
1580Sstevel@tonic-gate fmd_hdl_subscribe(hdl, "ereport.io.psy.ecc.s-drue");
1590Sstevel@tonic-gate fmd_hdl_subscribe(hdl, "ereport.io.psy.ecc.dwue");
1600Sstevel@tonic-gate fmd_hdl_subscribe(hdl, "ereport.io.psy.ecc.s-dwue");
1610Sstevel@tonic-gate fmd_hdl_subscribe(hdl, "ereport.io.psy.ecc.drce");
1620Sstevel@tonic-gate fmd_hdl_subscribe(hdl, "ereport.io.psy.ecc.s-drce");
1630Sstevel@tonic-gate fmd_hdl_subscribe(hdl, "ereport.io.psy.ecc.dwce");
1640Sstevel@tonic-gate fmd_hdl_subscribe(hdl, "ereport.io.psy.ecc.s-dwce");
1650Sstevel@tonic-gate
1660Sstevel@tonic-gate bzero(&iod, sizeof (iod_t));
1670Sstevel@tonic-gate
1680Sstevel@tonic-gate iod.iod_stats = (iod_stat_t *)fmd_stat_create(hdl, FMD_STAT_NOALLOC,
1690Sstevel@tonic-gate sizeof (iod_stat) / sizeof (fmd_stat_t), (fmd_stat_t *)&iod_stat);
1700Sstevel@tonic-gate }
171