fm: remove sparc-only modules
[unleashed.git] / usr / src / lib / libprtdiag / common / display_sun4v.c
blobf6b04e2e776e5ce40686096f413c97d7892f97ad
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <alloca.h>
28 #include <unistd.h>
29 #include <ctype.h>
30 #include <string.h>
31 #include <kvm.h>
32 #include <varargs.h>
33 #include <time.h>
34 #include <dirent.h>
35 #include <fcntl.h>
36 #include <sys/param.h>
37 #include <sys/stat.h>
38 #include <sys/types.h>
39 #include <sys/utsname.h>
40 #include <sys/openpromio.h>
41 #include <libintl.h>
42 #include <syslog.h>
43 #include <sys/dkio.h>
44 #include <sys/systeminfo.h>
45 #include <picldefs.h>
46 #include <math.h>
47 #include <errno.h>
48 #include "pdevinfo.h"
49 #include "display.h"
50 #include "display_sun4v.h"
51 #include "libprtdiag.h"
53 #if !defined(TEXT_DOMAIN)
54 #define TEXT_DOMAIN "SYS_TEST"
55 #endif
57 #define MOTHERBOARD "MB"
58 #define NETWORK "network"
59 #define SUN4V_MACHINE "sun4v"
60 #define PARENT_NAMES 10
63 * Additional OBP properties
65 #define OBP_PROP_COMPATIBLE "compatible"
66 #define OBP_PROP_MODEL "model"
67 #define OBP_PROP_SLOT_NAMES "slot-names"
68 #define OBP_PROP_VERSION "version"
70 #define PICL_NODE_PHYSICAL_PLATFORM "physical-platform"
71 #define PICL_NODE_CHASSIS "chassis"
72 #define MEMORY_SIZE_FIELD 11
73 #define INVALID_THRESHOLD 1000000
76 * Additional picl classes
78 #ifndef PICL_CLASS_SUN4V
79 #define PICL_CLASS_SUN4V "sun4v"
80 #endif
82 #ifndef PICL_PROP_NAC
83 #define PICL_PROP_NAC "nac"
84 #endif
86 extern int sys_clk;
87 extern picl_errno_t sun4v_get_node_by_name(picl_nodehdl_t, char *,
88 picl_nodehdl_t *);
90 static picl_nodehdl_t rooth = 0, phyplatformh = 0;
91 static picl_nodehdl_t chassish = 0;
92 static int class_node_found;
93 static int syserrlog;
94 static int all_status_ok;
96 /* local functions */
97 static int sun4v_get_first_compatible_value(picl_nodehdl_t, char **);
98 static void sun4v_display_memory_conf(picl_nodehdl_t);
99 static int sun4v_disp_env_status();
100 static void sun4v_env_print_fan_sensors();
101 static void sun4v_env_print_fan_indicators();
102 static void sun4v_env_print_temp_sensors();
103 static void sun4v_env_print_temp_indicators();
104 static void sun4v_env_print_current_sensors();
105 static void sun4v_env_print_current_indicators();
106 static void sun4v_env_print_voltage_sensors();
107 static void sun4v_env_print_voltage_indicators();
108 static void sun4v_env_print_LEDs();
109 static void sun4v_print_fru_status();
110 static int is_fru_absent(picl_nodehdl_t);
111 static void sun4v_print_fw_rev();
112 static void sun4v_print_chassis_serial_no();
113 static int openprom_callback(picl_nodehdl_t openpromh, void *arg);
114 static void sun4v_print_openprom_rev();
117 sun4v_display(Sys_tree *tree, Prom_node *root, int log,
118 picl_nodehdl_t plafh)
120 void *value; /* used for opaque PROM data */
121 struct mem_total memory_total; /* Total memory in system */
122 struct grp_info grps; /* Info on all groups in system */
123 char machine[MAXSTRLEN];
124 int exit_code = 0;
126 if (sysinfo(SI_MACHINE, machine, sizeof (machine)) == -1)
127 return (1);
128 if (strncmp(machine, SUN4V_MACHINE, strlen(SUN4V_MACHINE)) != 0)
129 return (1);
131 sys_clk = -1; /* System clock freq. (in MHz) */
134 * Now display the machine's configuration. We do this if we
135 * are not logging.
137 if (!logging) {
138 struct utsname uts_buf;
141 * Display system banner
143 (void) uname(&uts_buf);
145 log_printf(dgettext(TEXT_DOMAIN, "System Configuration: "
146 "Oracle Corporation %s %s\n"), uts_buf.machine,
147 get_prop_val(find_prop(root, "banner-name")), 0);
149 /* display system clock frequency */
150 value = get_prop_val(find_prop(root, "clock-frequency"));
151 if (value != NULL) {
152 sys_clk = ((*((int *)value)) + 500000) / 1000000;
153 log_printf(dgettext(TEXT_DOMAIN, "System clock "
154 "frequency: %d MHz\n"), sys_clk, 0);
157 /* Display the Memory Size */
158 display_memorysize(tree, NULL, &grps, &memory_total);
160 /* Display the CPU devices */
161 sun4v_display_cpu_devices(plafh);
163 /* Display the Memory configuration */
164 class_node_found = 0;
165 sun4v_display_memory_conf(plafh);
167 /* Display all the IO cards. */
168 (void) sun4v_display_pci(plafh);
169 sun4v_display_diaginfo((log || (logging)), root, plafh);
171 if (picl_get_root(&rooth) != PICL_SUCCESS)
172 return (1);
175 * The physical-platform node may be missing on systems with
176 * older firmware so don't consider that an error.
178 if (sun4v_get_node_by_name(rooth, PICL_NODE_PHYSICAL_PLATFORM,
179 &phyplatformh) != PICL_SUCCESS)
180 return (0);
182 if (picl_find_node(phyplatformh, PICL_PROP_CLASSNAME,
183 PICL_PTYPE_CHARSTRING, (void *)PICL_CLASS_CHASSIS,
184 strlen(PICL_CLASS_CHASSIS), &chassish) != PICL_SUCCESS)
185 return (1);
187 syserrlog = log;
188 exit_code = sun4v_disp_env_status();
190 return (exit_code);
194 * The binding-name property encodes the bus type.
196 static void
197 get_bus_type(picl_nodehdl_t nodeh, struct io_card *card)
199 char val[PICL_PROPNAMELEN_MAX], *p, *q;
201 card->bus_type[0] = '\0';
203 if (picl_get_propval_by_name(nodeh, PICL_PROP_BINDING_NAME, val,
204 sizeof (val)) == PICL_SUCCESS) {
205 if (strstr(val, PICL_CLASS_PCIEX))
206 (void) strlcpy(card->bus_type, "PCIE",
207 sizeof (card->bus_type));
208 else if (strstr(val, PICL_CLASS_PCI))
209 (void) strlcpy(card->bus_type, "PCIX",
210 sizeof (card->bus_type));
211 else {
213 * Not perfect: process the binding-name until
214 * we encounter something that we don't think would
215 * be part of a bus type. This may get confused a bit
216 * if a device or vendor id is encoded right after
217 * the bus class since there's no delimiter. If the
218 * id number begins with a hex digit [abcdef] then
219 * this will become part of the bus type string
220 * reported by prtdiag. This is all an effort to
221 * print something potentially useful for bus types
222 * other than PCI/PCIe.
224 * We do this because this code will get called for
225 * non-PCI class devices like the xaui (class sun4v.)
227 if (strstr(val, "SUNW,") != NULL)
228 p = strchr(val, ',') + 1;
229 else
230 p = val;
231 q = p;
232 while (*p != '\0') {
233 if (isdigit((char)*p) || ispunct((char)*p)) {
234 *p = '\0';
235 break;
237 *p = (char)_toupper((int)*p);
238 ++p;
240 (void) strlcpy(card->bus_type, q,
241 sizeof (card->bus_type));
247 * Fetch the Label property for this device. If none is found then
248 * search all the siblings with the same device ID for a
249 * Label and return that Label. The plug-in can only match the canonical
250 * path from the PRI with a specific devfs path. So we take care of
251 * devices with multiple functions here. A leaf device downstream of
252 * a bridge should fall out of here with PICL_PROPNOTFOUND, and the
253 * caller can walk back up the tree in search of the slot's Label.
255 static picl_errno_t
256 get_slot_label(picl_nodehdl_t nodeh, struct io_card *card)
258 char val[PICL_PROPNAMELEN_MAX];
259 picl_errno_t err;
260 picl_nodehdl_t pnodeh;
261 uint32_t devid, sib_devid;
262 int32_t instance;
265 * If there's a Label at this node then return it - we're
266 * done.
268 err = picl_get_propval_by_name(nodeh, PICL_PROP_LABEL, val,
269 sizeof (val));
270 if (err == PICL_SUCCESS) {
271 (void) strlcpy(card->slot_str, val, sizeof (card->slot_str));
272 return (err);
273 } else if (err != PICL_PROPNOTFOUND)
274 return (err);
277 * At this point we're starting to extrapolate what the Label
278 * should be since there is none at this specific node.
279 * Note that until the value of "err" is overwritten in the
280 * loop below, its value should be PICL_PROPNOTFOUND.
284 * The device must be attached, and we can figure that out if
285 * the instance number is present and is not equal to -1.
286 * This will prevent is from returning a Label for a sibling
287 * node when the node passed in would have a unique Label if the
288 * device were attached. But if the device is downstream of a
289 * node with a Label then pci_callback() will still find that
290 * and use it.
292 if (picl_get_propval_by_name(nodeh, PICL_PROP_INSTANCE, &instance,
293 sizeof (instance)) != PICL_SUCCESS)
294 return (err);
295 if (instance == -1)
296 return (err);
299 * Narrow the search to just the one device ID.
301 if (picl_get_propval_by_name(nodeh, PICL_PROP_DEVICE_ID, &devid,
302 sizeof (devid)) != PICL_SUCCESS)
303 return (err);
306 * Go find the first child of the parent so we can search
307 * all of the siblings.
309 if (picl_get_propval_by_name(nodeh, PICL_PROP_PARENT, &pnodeh,
310 sizeof (pnodeh)) != PICL_SUCCESS)
311 return (err);
312 if (picl_get_propval_by_name(pnodeh, PICL_PROP_CHILD, &pnodeh,
313 sizeof (pnodeh)) != PICL_SUCCESS)
314 return (err);
317 * If the child's device ID matches, then fetch the Label and
318 * return it. The first child/device ID should have a Label
319 * associated with it.
321 do {
322 if (picl_get_propval_by_name(pnodeh, PICL_PROP_DEVICE_ID,
323 &sib_devid, sizeof (sib_devid)) == PICL_SUCCESS) {
324 if (sib_devid == devid) {
325 if ((err = picl_get_propval_by_name(pnodeh,
326 PICL_PROP_LABEL, val, sizeof (val))) ==
327 PICL_SUCCESS) {
328 (void) strlcpy(card->slot_str, val,
329 sizeof (card->slot_str));
330 break;
334 } while (picl_get_propval_by_name(pnodeh, PICL_PROP_PEER, &pnodeh,
335 sizeof (pnodeh)) == PICL_SUCCESS);
337 return (err);
340 static void
341 get_slot_number(picl_nodehdl_t nodeh, struct io_card *card)
343 picl_errno_t err;
344 picl_prophdl_t proph;
345 picl_propinfo_t pinfo;
346 picl_nodehdl_t pnodeh;
347 uint8_t *pval;
348 uint32_t dev_mask;
349 char uaddr[MAXSTRLEN];
350 int i;
352 err = PICL_SUCCESS;
353 while (err == PICL_SUCCESS) {
354 if (picl_get_propval_by_name(nodeh, PICL_PROP_PARENT, &pnodeh,
355 sizeof (pnodeh)) != PICL_SUCCESS) {
356 (void) strlcpy(card->slot_str, MOTHERBOARD,
357 sizeof (card->slot_str));
358 card->slot = -1;
359 return;
361 if (picl_get_propinfo_by_name(pnodeh, OBP_PROP_SLOT_NAMES,
362 &pinfo, &proph) == PICL_SUCCESS) {
363 break;
365 nodeh = pnodeh;
367 if (picl_get_propval_by_name(nodeh, PICL_PROP_UNIT_ADDRESS, uaddr,
368 sizeof (uaddr)) != PICL_SUCCESS) {
369 (void) strlcpy(card->slot_str, MOTHERBOARD,
370 sizeof (card->slot_str));
371 card->slot = -1;
372 return;
374 pval = (uint8_t *)malloc(pinfo.size);
375 if (!pval) {
376 (void) strlcpy(card->slot_str, MOTHERBOARD,
377 sizeof (card->slot_str));
378 card->slot = -1;
379 return;
381 if (picl_get_propval(proph, pval, pinfo.size) != PICL_SUCCESS) {
382 (void) strlcpy(card->slot_str, MOTHERBOARD,
383 sizeof (card->slot_str));
384 card->slot = -1;
385 free(pval);
386 return;
389 dev_mask = 0;
390 for (i = 0; i < sizeof (dev_mask); i++)
391 dev_mask |= (*(pval+i) << 8*(sizeof (dev_mask)-1-i));
392 for (i = 0; i < sizeof (uaddr) && uaddr[i] != '\0'; i++) {
393 if (uaddr[i] == ',') {
394 uaddr[i] = '\0';
395 break;
398 card->slot = atol(uaddr);
399 if (((1 << card->slot) & dev_mask) == 0) {
400 (void) strlcpy(card->slot_str, MOTHERBOARD,
401 sizeof (card->slot_str));
402 card->slot = -1;
403 } else {
404 char *p = (char *)(pval+sizeof (dev_mask));
405 int shift = sizeof (uint32_t)*8-1-card->slot;
406 uint32_t x = (dev_mask << shift) >> shift;
407 int count = 0; /* count # of 1's in x */
408 int i = 0;
409 while (x != 0) {
410 count++;
411 x &= x-1;
413 while (count > 1) {
414 while (p[i++] != '\0')
416 count--;
418 (void) strlcpy(card->slot_str, (char *)(p+i),
419 sizeof (card->slot_str));
421 free(pval);
425 * add all io devices under pci in io list
427 /* ARGSUSED */
428 static int
429 sun4v_pci_callback(picl_nodehdl_t pcih, void *args)
431 char path[PICL_PROPNAMELEN_MAX];
432 char class[PICL_CLASSNAMELEN_MAX];
433 char name[PICL_PROPNAMELEN_MAX];
434 char model[PICL_PROPNAMELEN_MAX];
435 char binding_name[PICL_PROPNAMELEN_MAX];
436 char val[PICL_PROPNAMELEN_MAX];
437 char *compatible;
438 picl_errno_t err;
439 picl_nodehdl_t nodeh, pnodeh;
440 struct io_card pci_card;
442 /* Walk through the children */
444 err = picl_get_propval_by_name(pcih, PICL_PROP_CHILD, &nodeh,
445 sizeof (picl_nodehdl_t));
447 while (err == PICL_SUCCESS) {
448 err = picl_get_propval_by_name(nodeh, PICL_PROP_CLASSNAME,
449 class, sizeof (class));
450 if (err != PICL_SUCCESS)
451 return (err);
453 if (args) {
454 char *val = args;
455 if (strcmp(class, val) == 0) {
456 err = picl_get_propval_by_name(nodeh,
457 PICL_PROP_PEER, &nodeh,
458 sizeof (picl_nodehdl_t));
459 continue;
460 } else if (strcmp(val, PICL_CLASS_PCIEX) == 0 &&
461 strcmp(class, PICL_CLASS_PCI) == 0) {
462 err = picl_get_propval_by_name(nodeh,
463 PICL_PROP_PEER, &nodeh,
464 sizeof (picl_nodehdl_t));
465 continue;
466 } else if (strcmp(val, PICL_CLASS_PCI) == 0 &&
467 strcmp(class, PICL_CLASS_PCIEX) == 0) {
468 err = picl_get_propval_by_name(nodeh,
469 PICL_PROP_PEER, &nodeh,
470 sizeof (picl_nodehdl_t));
471 continue;
475 err = picl_get_propval_by_name(nodeh, PICL_PROP_DEVFS_PATH,
476 path, sizeof (path));
477 if (err != PICL_SUCCESS)
478 return (err);
480 (void) strlcpy(pci_card.notes, path, sizeof (pci_card.notes));
482 pnodeh = nodeh;
483 err = get_slot_label(nodeh, &pci_card);
486 * No Label at this node, maybe we're looking at a device
487 * downstream of a bridge. Walk back up and find a Label and
488 * record that node in "pnodeh".
490 while (err != PICL_SUCCESS) {
491 if (err != PICL_PROPNOTFOUND)
492 break;
493 else if (picl_get_propval_by_name(pnodeh,
494 PICL_PROP_PARENT, &pnodeh, sizeof (pnodeh)) ==
495 PICL_SUCCESS)
496 err = get_slot_label(pnodeh, &pci_card);
497 else
498 break;
502 * Can't find a Label for this device in the PCI heirarchy.
503 * Try to synthesize a slot name from atoms. This depends
504 * on the OBP slot_names property being implemented, and this
505 * so far doesn't seem to be on sun4v. But just in case that
506 * is resurrected, the code is here.
508 if (err != PICL_SUCCESS) {
509 pnodeh = nodeh;
510 get_slot_number(nodeh, &pci_card);
514 * Passing in pnodeh instead of nodeh will cause prtdiag
515 * to display the type of IO slot for the leaf node. For
516 * built-in devices and a lot of IO cards these will be
517 * the same thing. But for IO cards with bridge chips or
518 * for things like expansion chassis, prtdiag will report
519 * the bus type of the IO slot and not the leaf, which
520 * could be different things.
522 get_bus_type(pnodeh, &pci_card);
524 err = picl_get_propval_by_name(nodeh, PICL_PROP_NAME, name,
525 sizeof (name));
526 if (err == PICL_PROPNOTFOUND)
527 (void) strlcpy(name, "", sizeof (name));
528 else if (err != PICL_SUCCESS)
529 return (err);
531 err = picl_get_propval_by_name(nodeh, PICL_PROP_STATUS, val,
532 sizeof (val));
533 if (err == PICL_PROPNOTFOUND)
534 (void) strlcpy(val, "", sizeof (val));
535 else if (err != PICL_SUCCESS)
536 return (err);
538 (void) snprintf(pci_card.status, sizeof (pci_card.status),
539 "%s", pci_card.slot_str);
542 * Get the name of this card. If binding_name is found,
543 * name will be <nodename>-<binding_name>.
545 err = picl_get_propval_by_name(nodeh, PICL_PROP_BINDING_NAME,
546 binding_name, sizeof (binding_name));
547 if (err == PICL_SUCCESS) {
548 if (strcmp(name, binding_name) != 0) {
549 (void) strlcat(name, "-", sizeof (name));
550 (void) strlcat(name, binding_name,
551 sizeof (name));
553 } else if (err == PICL_PROPNOTFOUND) {
555 * if compatible prop is not found, name will be
556 * <nodename>-<compatible>
558 err = sun4v_get_first_compatible_value(nodeh,
559 &compatible);
560 if (err == PICL_SUCCESS) {
561 (void) strlcat(name, "-", sizeof (name));
562 (void) strlcat(name, compatible,
563 sizeof (name));
564 free(compatible);
566 } else
567 return (err);
569 (void) strlcpy(pci_card.name, name, sizeof (pci_card.name));
571 /* Get the model of this card */
573 err = picl_get_propval_by_name(nodeh, OBP_PROP_MODEL,
574 model, sizeof (model));
575 if (err == PICL_PROPNOTFOUND)
576 (void) strlcpy(model, "", sizeof (model));
577 else if (err != PICL_SUCCESS)
578 return (err);
579 (void) strlcpy(pci_card.model, model, sizeof (pci_card.model));
581 /* Print NAC name */
582 log_printf("%-18s", pci_card.status);
583 /* Print IO Type */
584 log_printf("%-6s", pci_card.bus_type);
585 /* Printf Card Name */
586 log_printf("%-34s", pci_card.name);
587 /* Print Card Model */
588 log_printf("%-8s", pci_card.model);
589 log_printf("\n");
590 /* Print Status */
591 log_printf("%-18s", val);
592 /* Print IO Type */
593 log_printf("%-6s", "");
594 /* Print Parent Path */
595 log_printf("%-44s", pci_card.notes);
596 log_printf("\n");
598 err = picl_get_propval_by_name(nodeh, PICL_PROP_PEER, &nodeh,
599 sizeof (picl_nodehdl_t));
601 return (PICL_WALK_CONTINUE);
605 * display_pci
606 * Display all the PCI IO cards on this board.
608 void
609 sun4v_display_pci(picl_nodehdl_t plafh)
611 char *fmt = "%-17s %-5s %-33s %-8s";
612 /* Have we printed the column headings? */
613 static int banner = FALSE;
615 if (banner == FALSE) {
616 log_printf("\n");
617 log_printf("================================");
618 log_printf(" IO Devices ");
619 log_printf("================================");
620 log_printf("\n");
621 log_printf(fmt, "Slot +", "Bus", "Name +", "Model", 0);
622 log_printf("\n");
623 log_printf(fmt, "Status", "Type", "Path", "", 0);
624 log_printf("\n");
625 log_printf("---------------------------------"
626 "-------------------------------------------\n");
627 banner = TRUE;
630 (void) picl_walk_tree_by_class(plafh, PICL_CLASS_PCIEX,
631 PICL_CLASS_PCIEX, sun4v_pci_callback);
632 (void) picl_walk_tree_by_class(plafh, PICL_CLASS_PCI,
633 PICL_CLASS_PCI, sun4v_pci_callback);
634 (void) picl_walk_tree_by_class(plafh, PICL_CLASS_SUN4V,
635 PICL_CLASS_SUN4V, sun4v_pci_callback);
639 * return the first compatible value
641 static int
642 sun4v_get_first_compatible_value(picl_nodehdl_t nodeh, char **outbuf)
644 picl_errno_t err;
645 picl_prophdl_t proph;
646 picl_propinfo_t pinfo;
647 picl_prophdl_t tblh;
648 picl_prophdl_t rowproph;
649 char *pval;
651 err = picl_get_propinfo_by_name(nodeh, OBP_PROP_COMPATIBLE,
652 &pinfo, &proph);
653 if (err != PICL_SUCCESS)
654 return (err);
656 if (pinfo.type == PICL_PTYPE_CHARSTRING) {
657 pval = malloc(pinfo.size);
658 if (pval == NULL)
659 return (PICL_FAILURE);
660 err = picl_get_propval(proph, pval, pinfo.size);
661 if (err != PICL_SUCCESS) {
662 free(pval);
663 return (err);
665 *outbuf = pval;
666 return (PICL_SUCCESS);
669 if (pinfo.type != PICL_PTYPE_TABLE)
670 return (PICL_FAILURE);
672 /* get first string from table */
673 err = picl_get_propval(proph, &tblh, pinfo.size);
674 if (err != PICL_SUCCESS)
675 return (err);
677 err = picl_get_next_by_row(tblh, &rowproph);
678 if (err != PICL_SUCCESS)
679 return (err);
681 err = picl_get_propinfo(rowproph, &pinfo);
682 if (err != PICL_SUCCESS)
683 return (err);
685 pval = malloc(pinfo.size);
686 if (pval == NULL)
687 return (PICL_FAILURE);
689 err = picl_get_propval(rowproph, pval, pinfo.size);
690 if (err != PICL_SUCCESS) {
691 free(pval);
692 return (err);
695 *outbuf = pval;
696 return (PICL_SUCCESS);
700 * print size of a memory segment
702 static void
703 print_memory_segment_size(uint64_t size)
705 uint64_t kbyte = 1024;
706 uint64_t mbyte = kbyte * kbyte;
707 uint64_t gbyte = kbyte * mbyte;
708 uint64_t tbyte = kbyte * gbyte;
709 char buf[MEMORY_SIZE_FIELD];
711 if (size >= tbyte) {
712 if (size % tbyte == 0)
713 (void) snprintf(buf, sizeof (buf), "%d TB",
714 (int)(size / tbyte));
715 else
716 (void) snprintf(buf, sizeof (buf), "%.2f TB",
717 (float)size / tbyte);
718 } else if (size >= gbyte) {
719 if (size % gbyte == 0)
720 (void) snprintf(buf, sizeof (buf), "%d GB",
721 (int)(size / gbyte));
722 else
723 (void) snprintf(buf, sizeof (buf), "%.2f GB",
724 (float)size / gbyte);
725 } else if (size >= mbyte) {
726 if (size % mbyte == 0)
727 (void) snprintf(buf, sizeof (buf), "%d MB",
728 (int)(size / mbyte));
729 else
730 (void) snprintf(buf, sizeof (buf), "%.2f MB",
731 (float)size / mbyte);
732 } else {
733 if (size % kbyte == 0)
734 (void) snprintf(buf, sizeof (buf), "%d KB",
735 (int)(size / kbyte));
736 else
737 (void) snprintf(buf, sizeof (buf), "%.2f KB",
738 (float)size / kbyte);
740 log_printf("%-9s", buf);
744 * Enumerate banks and dimms within a memory segment. We're handed
745 * the first bank within the segment - we assume there are dimms
746 * (memory-module) nodes underneath.
748 static void
749 print_memory_segment_contain(picl_nodehdl_t bank_nodeh)
751 char val[PICL_PROPNAMELEN_MAX];
752 picl_nodehdl_t module_nodeh;
753 int flag = 0;
754 uint64_t size;
756 do {
757 if (picl_get_propval_by_name(bank_nodeh, PICL_PROP_CHILD,
758 &module_nodeh, sizeof (picl_nodehdl_t)) != PICL_SUCCESS)
759 continue;
760 if (picl_get_propval_by_name(bank_nodeh, PICL_PROP_SIZE,
761 &size, sizeof (size)) == PICL_SUCCESS) {
762 if (!flag) {
763 print_memory_segment_size(size);
764 } else {
765 log_printf(" "
766 " ");
767 print_memory_segment_size(size);
768 flag = 0;
771 do {
772 if (picl_get_propval_by_name(module_nodeh,
773 PICL_PROP_NAC, val, sizeof (val)) !=
774 PICL_SUCCESS)
775 continue;
776 else {
777 if (!flag) {
778 log_printf("%s\n", val);
779 flag = 1;
780 } else {
781 log_printf("%s%s\n",
783 " ",
784 val);
787 } while (picl_get_propval_by_name(module_nodeh, PICL_PROP_PEER,
788 &module_nodeh, sizeof (picl_nodehdl_t)) ==
789 PICL_SUCCESS);
790 } while (picl_get_propval_by_name(bank_nodeh, PICL_PROP_PEER,
791 &bank_nodeh, sizeof (picl_nodehdl_t)) == PICL_SUCCESS);
795 * Search node where _class=="memory-segment"
796 * print "Base Address", "Size", etc
798 /*ARGSUSED*/
799 static int
800 sun4v_memory_conf_callback(picl_nodehdl_t nodeh, void *args)
802 uint64_t base;
803 uint64_t size;
804 uint64_t ifactor;
805 picl_errno_t err = PICL_SUCCESS;
807 if (class_node_found == 0) {
808 class_node_found = 1;
809 return (PICL_WALK_TERMINATE);
811 while (err == PICL_SUCCESS) {
812 err = picl_get_propval_by_name(nodeh, PICL_PROP_BASEADDRESS,
813 &base, sizeof (base));
814 if (err != PICL_SUCCESS)
815 break;
816 err = picl_get_propval_by_name(nodeh, PICL_PROP_SIZE,
817 &size, sizeof (size));
818 if (err != PICL_SUCCESS)
819 break;
820 err = picl_get_propval_by_name(nodeh,
821 PICL_PROP_INTERLEAVE_FACTOR, &ifactor,
822 sizeof (ifactor));
823 if (err != PICL_SUCCESS)
824 break;
825 log_printf("0x%-13llx", base);
826 print_memory_segment_size(size);
827 log_printf("%-12lld", ifactor);
828 err = picl_get_propval_by_name(nodeh, PICL_PROP_CHILD,
829 &nodeh, sizeof (nodeh));
830 if (err == PICL_SUCCESS)
831 print_memory_segment_contain(nodeh);
832 log_printf("\n");
833 err = picl_get_propval_by_name(nodeh, PICL_PROP_PEER, &nodeh,
834 sizeof (picl_nodehdl_t));
837 return (PICL_WALK_CONTINUE);
840 /*ARGSUSED*/
841 void
842 sun4v_display_memory_conf(picl_nodehdl_t plafh)
844 char *fmt = "%-14s %-8s %-11s %-8s %-s";
845 (void) picl_walk_tree_by_class(plafh, PICL_CLASS_MEMORY_SEGMENT,
846 NULL, sun4v_memory_conf_callback);
847 if (class_node_found == 0)
848 return;
849 log_printf("\n");
850 log_printf("=======================");
851 log_printf(" Physical Memory Configuration ");
852 log_printf("========================");
853 log_printf("\n");
854 log_printf("Segment Table:\n");
855 log_printf(
856 "--------------------------------------------------------------\n");
857 log_printf(fmt, "Base", "Segment", "Interleave", "Bank", "Contains", 0);
858 log_printf("\n");
859 log_printf(fmt, "Address", "Size", "Factor", "Size", "Modules", 0);
860 log_printf("\n");
861 log_printf(
862 "--------------------------------------------------------------\n");
863 (void) picl_walk_tree_by_class(plafh, PICL_CLASS_MEMORY_SEGMENT,
864 NULL, sun4v_memory_conf_callback);
867 void
868 sun4v_display_cpu_devices(picl_nodehdl_t plafh)
870 char *fmt = "%-6s %-9s %-22s %-6s";
873 * Display the table header for CPUs . Then display the CPU
874 * frequency, cache size, and processor revision of all cpus.
876 log_printf(dgettext(TEXT_DOMAIN,
877 "\n"
878 "================================"
879 " Virtual CPUs "
880 "================================"
881 "\n"
882 "\n"));
883 log_printf("\n");
884 log_printf(fmt, "CPU ID", "Frequency", "Implementation",
885 "Status", 0);
886 log_printf("\n");
887 log_printf(fmt, "------", "---------",
888 "----------------------", "-------", 0);
889 log_printf("\n");
891 (void) picl_walk_tree_by_class(plafh, PICL_CLASS_CPU, PICL_CLASS_CPU,
892 sun4v_display_cpus);
896 * Display the CPUs present on this board.
898 /*ARGSUSED*/
900 sun4v_display_cpus(picl_nodehdl_t cpuh, void* args)
902 int status;
903 picl_prophdl_t proph;
904 picl_prophdl_t tblh;
905 picl_prophdl_t rowproph;
906 picl_propinfo_t propinfo;
907 int *int_value;
908 int cpuid;
909 char *comp_value;
910 char *no_prop_value = " ";
911 char freq_str[MAXSTRLEN];
912 char state[MAXSTRLEN];
915 * Get cpuid property and print it and the NAC name
917 status = picl_get_propinfo_by_name(cpuh, OBP_PROP_CPUID, &propinfo,
918 &proph);
919 if (status == PICL_SUCCESS) {
920 status = picl_get_propval(proph, &cpuid, sizeof (cpuid));
921 if (status != PICL_SUCCESS) {
922 log_printf("%-7s", no_prop_value);
923 } else {
924 log_printf("%-7d", cpuid);
926 } else {
927 log_printf("%-7s", no_prop_value);
930 clock_freq:
931 status = picl_get_propinfo_by_name(cpuh, "clock-frequency", &propinfo,
932 &proph);
933 if (status == PICL_SUCCESS) {
934 int_value = malloc(propinfo.size);
935 if (int_value == NULL) {
936 log_printf("%-10s", no_prop_value);
937 goto compatible;
939 status = picl_get_propval(proph, int_value, propinfo.size);
940 if (status != PICL_SUCCESS) {
941 log_printf("%-10s", no_prop_value);
942 } else {
943 /* Running frequency */
944 (void) snprintf(freq_str, sizeof (freq_str), "%d MHz",
945 CLK_FREQ_TO_MHZ(*int_value));
946 log_printf("%-10s", freq_str);
948 free(int_value);
949 } else
950 log_printf("%-10s", no_prop_value);
952 compatible:
953 status = picl_get_propinfo_by_name(cpuh, "compatible", &propinfo,
954 &proph);
955 if (status == PICL_SUCCESS) {
956 if (propinfo.type == PICL_PTYPE_CHARSTRING) {
958 * Compatible Property only has 1 value
960 comp_value = malloc(propinfo.size);
961 if (comp_value == NULL) {
962 log_printf("%-23s", no_prop_value, 0);
963 goto state;
965 status = picl_get_propval(proph, comp_value,
966 propinfo.size);
967 if (status != PICL_SUCCESS)
968 log_printf("%-23s", no_prop_value, 0);
969 else
970 log_printf("%-23s", comp_value, 0);
971 free(comp_value);
972 } else if (propinfo.type == PICL_PTYPE_TABLE) {
974 * Compatible Property has multiple values
976 status = picl_get_propval(proph, &tblh, propinfo.size);
977 if (status != PICL_SUCCESS) {
978 log_printf("%-23s", no_prop_value, 0);
979 goto state;
981 status = picl_get_next_by_row(tblh, &rowproph);
982 if (status != PICL_SUCCESS) {
983 log_printf("%-23s", no_prop_value, 0);
984 goto state;
987 status = picl_get_propinfo(rowproph, &propinfo);
988 if (status != PICL_SUCCESS) {
989 log_printf("%-23s", no_prop_value, 0);
990 goto state;
993 comp_value = malloc(propinfo.size);
994 if (comp_value == NULL) {
995 log_printf("%-23s", no_prop_value, 0);
996 goto state;
998 status = picl_get_propval(rowproph, comp_value,
999 propinfo.size);
1000 if (status != PICL_SUCCESS)
1001 log_printf("%-23s", no_prop_value, 0);
1002 else
1003 log_printf("%-23s", comp_value, 0);
1004 free(comp_value);
1006 } else
1007 log_printf("%-23s", no_prop_value, 0);
1009 state:
1010 status = picl_get_propinfo_by_name(cpuh, PICL_PROP_STATE,
1011 &propinfo, &proph);
1012 if (status == PICL_SUCCESS) {
1013 status = picl_get_propval(proph, state, sizeof (state));
1014 if (status != PICL_SUCCESS) {
1015 log_printf("%-9s", no_prop_value);
1016 } else {
1017 log_printf("%-9s", state);
1019 } else
1020 log_printf("%-9s", no_prop_value);
1022 done:
1023 log_printf("\n");
1024 return (PICL_WALK_CONTINUE);
1027 void
1028 sun4v_display_diaginfo(int flag, Prom_node *root, picl_nodehdl_t plafh)
1031 * This function is intentionally empty
1035 void
1036 display_boardnum(int num)
1038 log_printf("%2d ", num, 0);
1041 static int
1042 sun4v_disp_env_status()
1044 int exit_code = 0;
1046 if (phyplatformh == 0)
1047 return (0);
1048 log_printf("\n");
1049 log_printf("============================");
1050 log_printf(" Environmental Status ");
1051 log_printf("============================");
1052 log_printf("\n");
1054 class_node_found = 0;
1055 all_status_ok = 1;
1056 sun4v_env_print_fan_sensors();
1057 exit_code |= (!all_status_ok);
1059 class_node_found = 0;
1060 all_status_ok = 1;
1061 sun4v_env_print_fan_indicators();
1062 exit_code |= (!all_status_ok);
1064 class_node_found = 0;
1065 all_status_ok = 1;
1066 sun4v_env_print_temp_sensors();
1067 exit_code |= (!all_status_ok);
1069 class_node_found = 0;
1070 all_status_ok = 1;
1071 sun4v_env_print_temp_indicators();
1072 exit_code |= (!all_status_ok);
1074 class_node_found = 0;
1075 all_status_ok = 1;
1076 sun4v_env_print_current_sensors();
1077 exit_code |= (!all_status_ok);
1079 class_node_found = 0;
1080 all_status_ok = 1;
1081 sun4v_env_print_current_indicators();
1082 exit_code |= (!all_status_ok);
1084 class_node_found = 0;
1085 all_status_ok = 1;
1086 sun4v_env_print_voltage_sensors();
1087 exit_code |= (!all_status_ok);
1089 class_node_found = 0;
1090 all_status_ok = 1;
1091 sun4v_env_print_voltage_indicators();
1092 exit_code |= (!all_status_ok);
1094 class_node_found = 0;
1095 all_status_ok = 1;
1096 sun4v_env_print_LEDs();
1097 exit_code |= (!all_status_ok);
1099 class_node_found = 0;
1100 all_status_ok = 1;
1101 sun4v_print_fru_status();
1102 exit_code |= (!all_status_ok);
1104 class_node_found = 0;
1105 sun4v_print_fw_rev();
1107 class_node_found = 0;
1108 sun4v_print_openprom_rev();
1110 sun4v_print_chassis_serial_no();
1112 return (exit_code);
1115 /*ARGSUSED*/
1116 static int
1117 sun4v_env_print_sensor_callback(picl_nodehdl_t nodeh, void *args)
1119 char val[PICL_PROPNAMELEN_MAX];
1120 picl_nodehdl_t parenth;
1121 char *names[PARENT_NAMES];
1122 char *base_units[PICL_PROPNAMELEN_MAX];
1123 char *loc;
1124 int i;
1125 char *prop;
1126 picl_errno_t err;
1127 int32_t lo_warning, lo_shutdown, lo_poweroff;
1128 int32_t hi_warning, hi_shutdown, hi_poweroff;
1129 int32_t current_val;
1130 int32_t exponent;
1131 double display_val;
1132 typedef enum {SENSOR_OK, SENSOR_WARN, SENSOR_FAILED,
1133 SENSOR_DISABLED, SENSOR_UNKNOWN} sensor_status_t;
1134 sensor_status_t sensor_status = SENSOR_OK;
1136 if (class_node_found == 0) {
1137 class_node_found = 1;
1138 return (PICL_WALK_TERMINATE);
1141 prop = (char *)args;
1142 if (!prop) {
1143 sensor_status = SENSOR_UNKNOWN;
1144 all_status_ok = 0;
1145 } else {
1146 err = picl_get_propval_by_name(nodeh,
1147 PICL_PROP_OPERATIONAL_STATUS, val,
1148 sizeof (val));
1149 if (err == PICL_SUCCESS) {
1150 if (strcmp(val, "disabled") == 0) {
1151 sensor_status = SENSOR_DISABLED;
1156 if (sensor_status != SENSOR_DISABLED &&
1157 sensor_status != SENSOR_UNKNOWN) {
1158 if (picl_get_propval_by_name(nodeh, prop, &current_val,
1159 sizeof (current_val)) != PICL_SUCCESS) {
1160 sensor_status = SENSOR_UNKNOWN;
1161 } else {
1162 if (picl_get_propval_by_name(nodeh,
1163 PICL_PROP_LOW_WARNING,
1164 &lo_warning, sizeof (lo_warning)) != PICL_SUCCESS)
1165 lo_warning = INVALID_THRESHOLD;
1166 if (picl_get_propval_by_name(nodeh,
1167 PICL_PROP_LOW_SHUTDOWN,
1168 &lo_shutdown, sizeof (lo_shutdown)) != PICL_SUCCESS)
1169 lo_shutdown = INVALID_THRESHOLD;
1170 if (picl_get_propval_by_name(nodeh,
1171 PICL_PROP_LOW_POWER_OFF,
1172 &lo_poweroff, sizeof (lo_poweroff)) != PICL_SUCCESS)
1173 lo_poweroff = INVALID_THRESHOLD;
1174 if (picl_get_propval_by_name(nodeh,
1175 PICL_PROP_HIGH_WARNING,
1176 &hi_warning, sizeof (hi_warning)) != PICL_SUCCESS)
1177 hi_warning = INVALID_THRESHOLD;
1178 if (picl_get_propval_by_name(nodeh,
1179 PICL_PROP_HIGH_SHUTDOWN,
1180 &hi_shutdown, sizeof (hi_shutdown)) != PICL_SUCCESS)
1181 hi_shutdown = INVALID_THRESHOLD;
1182 if (picl_get_propval_by_name(nodeh,
1183 PICL_PROP_HIGH_POWER_OFF,
1184 &hi_poweroff, sizeof (hi_poweroff)) != PICL_SUCCESS)
1185 hi_poweroff = INVALID_THRESHOLD;
1187 if ((lo_poweroff != INVALID_THRESHOLD &&
1188 current_val <= lo_poweroff) ||
1189 (hi_poweroff != INVALID_THRESHOLD &&
1190 current_val >= hi_poweroff)) {
1191 sensor_status = SENSOR_FAILED;
1192 } else if ((lo_shutdown != INVALID_THRESHOLD &&
1193 current_val <= lo_shutdown) ||
1194 (hi_shutdown != INVALID_THRESHOLD &&
1195 current_val >= hi_shutdown)) {
1196 sensor_status = SENSOR_FAILED;
1197 } else if ((lo_warning != INVALID_THRESHOLD &&
1198 current_val <= lo_warning) ||
1199 (hi_warning != INVALID_THRESHOLD &&
1200 current_val >= hi_warning)) {
1201 sensor_status = SENSOR_WARN;
1202 } else {
1203 sensor_status = SENSOR_OK;
1208 if (syserrlog == 0) {
1209 if (sensor_status != SENSOR_OK && all_status_ok == 1) {
1210 all_status_ok = 0;
1211 return (PICL_WALK_TERMINATE);
1213 if (sensor_status == SENSOR_OK) {
1214 return (PICL_WALK_CONTINUE);
1216 } else {
1217 if (sensor_status != SENSOR_OK && all_status_ok == 1) {
1218 all_status_ok = 0;
1223 * If we're here then prtdiag was invoked with "-v" or we have
1224 * a sensor that is beyond a threshold, so give them a book to
1225 * read instead of the Cliff Notes.
1227 err = picl_get_propval_by_name(nodeh, PICL_PROP_PARENT, &parenth,
1228 sizeof (parenth));
1229 if (err != PICL_SUCCESS) {
1230 log_printf("\n");
1231 return (PICL_WALK_CONTINUE);
1234 /* gather up the path name for the sensor */
1235 if ((loc = (char *)malloc(PICL_PROPNAMELEN_MAX*PARENT_NAMES)) != NULL) {
1236 for (i = 0; i < PARENT_NAMES; i++) {
1237 if ((names[i] = (char *)malloc(PICL_PROPNAMELEN_MAX)) ==
1238 NULL) {
1239 while (--i > -1)
1240 free(names[i]);
1241 free(loc);
1242 loc = NULL;
1246 i = 0;
1247 if (loc != 0) {
1248 while (err == PICL_SUCCESS) {
1249 if (parenth == phyplatformh)
1250 break;
1251 err = picl_get_propval_by_name(parenth, PICL_PROP_NAME,
1252 names[i++], PICL_PROPNAMELEN_MAX);
1253 if (err != PICL_SUCCESS) {
1254 i--;
1255 break;
1257 if (i == PARENT_NAMES)
1258 break;
1259 err = picl_get_propval_by_name(parenth,
1260 PICL_PROP_PARENT, &parenth, sizeof (parenth));
1262 loc[0] = '\0';
1263 if (--i > -1) {
1264 (void) strlcat(loc, names[i],
1265 PICL_PROPNAMELEN_MAX * PARENT_NAMES);
1267 while (--i > -1) {
1268 (void) strlcat(loc, "/", PICL_PROPNAMELEN_MAX *
1269 PARENT_NAMES);
1270 (void) strlcat(loc, names[i],
1271 PICL_PROPNAMELEN_MAX * PARENT_NAMES);
1273 log_printf("%-35s", loc);
1274 for (i = 0; i < PARENT_NAMES; i++)
1275 free(names[i]);
1276 free(loc);
1277 } else {
1278 log_printf("%-35s", " ");
1280 err = picl_get_propval_by_name(nodeh, PICL_PROP_LABEL, val,
1281 sizeof (val));
1282 if (err == PICL_SUCCESS)
1283 log_printf("%-19s", val);
1286 * Get the exponent if present, and do a little math so that
1287 * if we need to we can print a normalized value for the
1288 * sensor reading.
1290 if (picl_get_propval_by_name(nodeh, PICL_PROP_EXPONENT,
1291 &exponent, sizeof (exponent)) != PICL_SUCCESS)
1292 exponent = 0;
1293 if (exponent == 0)
1294 display_val = (double)current_val;
1295 else {
1296 display_val = (double)current_val *
1297 pow((double)10, (double)exponent);
1300 * Sometimes ILOM will scale a sensor reading but
1301 * there will be nothing to the right of the decimal
1302 * once that value is normalized. Setting the
1303 * exponent to zero will prevent the printf below
1304 * from printing extraneous zeros. Otherwise a
1305 * negative exponent is used to set the precision
1306 * for the printf.
1308 if ((int)display_val == display_val || exponent > 0)
1309 exponent = 0;
1312 err = picl_get_propval_by_name(nodeh, PICL_PROP_BASE_UNITS,
1313 base_units, sizeof (base_units));
1314 if (err != PICL_SUCCESS)
1315 base_units[0] = '\0';
1317 switch (sensor_status) {
1318 case SENSOR_FAILED:
1319 log_printf("%-s", "failed (");
1320 log_printf("%-.*f", abs(exponent), display_val);
1321 log_printf("%-s %s", base_units, ")");
1322 break;
1323 case SENSOR_WARN:
1324 log_printf("%-s", "warning (");
1325 log_printf("%-.*f", abs(exponent), display_val);
1326 log_printf("%-s %s", base_units, ")");
1327 break;
1328 case SENSOR_DISABLED:
1329 log_printf("%-s", "disabled");
1330 break;
1331 case SENSOR_OK:
1332 log_printf("%-s", "ok");
1333 break;
1334 default:
1335 log_printf("%-s", "unknown");
1336 break;
1339 log_printf("\n");
1340 return (PICL_WALK_CONTINUE);
1343 /*ARGSUSED*/
1344 static int
1345 sun4v_env_print_indicator_callback(picl_nodehdl_t nodeh, void *args)
1347 char current_val[PICL_PROPNAMELEN_MAX];
1348 char expected_val[PICL_PROPNAMELEN_MAX];
1349 char label[PICL_PROPNAMELEN_MAX];
1350 picl_nodehdl_t parenth;
1351 char *names[PARENT_NAMES];
1352 char *loc;
1353 int i = 0;
1354 char *prop = (char *)args;
1355 picl_errno_t err = PICL_SUCCESS;
1356 typedef enum {SENSOR_OK, SENSOR_WARN, SENSOR_FAILED,
1357 SENSOR_DISABLED, SENSOR_UNKNOWN} sensor_status_t;
1358 sensor_status_t sensor_status = SENSOR_OK;
1360 if (class_node_found == 0) {
1361 class_node_found = 1;
1362 return (PICL_WALK_TERMINATE);
1365 prop = (char *)args;
1366 if (!prop) {
1367 sensor_status = SENSOR_UNKNOWN;
1368 all_status_ok = 0;
1369 } else {
1370 err = picl_get_propval_by_name(nodeh,
1371 PICL_PROP_OPERATIONAL_STATUS, current_val,
1372 sizeof (current_val));
1373 if (err == PICL_SUCCESS) {
1374 if (strcmp(current_val, "disabled") == 0) {
1375 sensor_status = SENSOR_DISABLED;
1380 if (sensor_status != SENSOR_DISABLED &&
1381 sensor_status != SENSOR_UNKNOWN) {
1382 if (picl_get_propval_by_name(nodeh, prop, &current_val,
1383 sizeof (current_val)) != PICL_SUCCESS) {
1384 (void) strlcpy(current_val, "unknown",
1385 sizeof (current_val));
1386 sensor_status = SENSOR_UNKNOWN;
1387 } else {
1388 if (picl_get_propval_by_name(nodeh, PICL_PROP_EXPECTED,
1389 &expected_val, sizeof (expected_val)) ==
1390 PICL_SUCCESS) {
1391 if (strncmp(current_val, expected_val,
1392 sizeof (current_val)) == 0) {
1393 sensor_status = SENSOR_OK;
1394 } else {
1395 sensor_status = SENSOR_FAILED;
1401 if (syserrlog == 0) {
1402 if (sensor_status != SENSOR_OK && all_status_ok == 1) {
1403 all_status_ok = 0;
1404 return (PICL_WALK_TERMINATE);
1406 if (sensor_status == SENSOR_OK) {
1407 return (PICL_WALK_CONTINUE);
1409 } else {
1410 if (sensor_status != SENSOR_OK && all_status_ok == 1) {
1411 all_status_ok = 0;
1416 * If we're here then prtdiag was invoked with "-v" or we have
1417 * a sensor that is beyond a threshold, so give them a book to
1418 * read instead of the Cliff Notes.
1420 err = picl_get_propval_by_name(nodeh, PICL_PROP_PARENT, &parenth,
1421 sizeof (parenth));
1422 if (err != PICL_SUCCESS) {
1423 log_printf("\n");
1424 return (PICL_WALK_CONTINUE);
1426 if ((loc = (char *)malloc(PICL_PROPNAMELEN_MAX*PARENT_NAMES)) != NULL) {
1427 for (i = 0; i < PARENT_NAMES; i++) {
1428 if ((names[i] = (char *)malloc(PICL_PROPNAMELEN_MAX)) ==
1429 NULL) {
1430 while (--i > -1)
1431 free(names[i]);
1432 free(loc);
1433 loc = NULL;
1437 i = 0;
1438 if (loc) {
1439 while (err == PICL_SUCCESS) {
1440 if (parenth == phyplatformh)
1441 break;
1442 err = picl_get_propval_by_name(parenth, PICL_PROP_NAME,
1443 names[i++], PICL_PROPNAMELEN_MAX);
1444 if (err != PICL_SUCCESS) {
1445 i--;
1446 break;
1448 if (i == PARENT_NAMES)
1449 break;
1450 err = picl_get_propval_by_name(parenth,
1451 PICL_PROP_PARENT, &parenth, sizeof (parenth));
1453 loc[0] = '\0';
1454 if (--i > -1) {
1455 (void) strlcat(loc, names[i],
1456 PICL_PROPNAMELEN_MAX * PARENT_NAMES);
1458 while (--i > -1) {
1459 (void) strlcat(loc, "/", PICL_PROPNAMELEN_MAX *
1460 PARENT_NAMES);
1461 (void) strlcat(loc, names[i],
1462 PICL_PROPNAMELEN_MAX * PARENT_NAMES);
1464 log_printf("%-35s", loc);
1465 for (i = 0; i < PARENT_NAMES; i++)
1466 free(names[i]);
1467 free(loc);
1468 } else {
1469 log_printf("%-35s", "");
1472 err = picl_get_propval_by_name(nodeh, PICL_PROP_LABEL, label,
1473 sizeof (label));
1474 if (err != PICL_SUCCESS)
1475 (void) strlcpy(label, "", sizeof (label));
1476 log_printf("%-19s", label);
1478 log_printf("%-8s", current_val);
1480 log_printf("\n");
1481 return (PICL_WALK_CONTINUE);
1484 static void
1485 sun4v_env_print_fan_sensors()
1487 char *fmt = "%-34s %-18s %-10s\n";
1489 * If there isn't any fan sensor node, return now.
1491 (void) picl_walk_tree_by_class(phyplatformh,
1492 PICL_CLASS_RPM_SENSOR, (void *)PICL_PROP_SPEED,
1493 sun4v_env_print_sensor_callback);
1494 if (!class_node_found)
1495 return;
1496 log_printf("Fan sensors:\n");
1497 if (syserrlog == 0) {
1498 (void) picl_walk_tree_by_class(phyplatformh,
1499 PICL_CLASS_RPM_SENSOR,
1500 PICL_PROP_SPEED, sun4v_env_print_sensor_callback);
1501 if (all_status_ok) {
1502 log_printf("All fan sensors are OK.\n");
1503 return;
1506 log_printf("-------------------------------------------------"
1507 "---------------\n");
1508 log_printf(fmt, "Location", "Sensor", "Status", 0);
1509 log_printf("-------------------------------------------------"
1510 "---------------\n");
1511 (void) picl_walk_tree_by_class(phyplatformh, PICL_CLASS_RPM_SENSOR,
1512 PICL_PROP_SPEED, sun4v_env_print_sensor_callback);
1515 static void
1516 sun4v_env_print_fan_indicators()
1518 char *fmt = "%-34s %-18s %-10s\n";
1519 (void) picl_walk_tree_by_class(phyplatformh,
1520 PICL_CLASS_RPM_INDICATOR, (void *)PICL_PROP_CONDITION,
1521 sun4v_env_print_indicator_callback);
1522 if (!class_node_found)
1523 return;
1524 log_printf("\nFan indicators:\n");
1525 if (syserrlog == 0) {
1526 (void) picl_walk_tree_by_class(phyplatformh,
1527 PICL_CLASS_RPM_INDICATOR,
1528 (void *)PICL_PROP_CONDITION,
1529 sun4v_env_print_indicator_callback);
1530 if (all_status_ok) {
1531 log_printf("All fan indicators are OK.\n");
1532 return;
1535 log_printf("-------------------------------------------------"
1536 "---------------\n");
1537 log_printf(fmt, "Location", "Sensor", "Condition", 0);
1538 log_printf("-------------------------------------------------"
1539 "---------------\n");
1540 (void) picl_walk_tree_by_class(phyplatformh, PICL_CLASS_RPM_INDICATOR,
1541 (void *)PICL_PROP_CONDITION, sun4v_env_print_indicator_callback);
1544 static void
1545 sun4v_env_print_temp_sensors()
1547 char *fmt = "%-34s %-18s %-10s\n";
1548 (void) picl_walk_tree_by_class(phyplatformh,
1549 PICL_CLASS_TEMPERATURE_SENSOR,
1550 (void *)PICL_PROP_TEMPERATURE,
1551 sun4v_env_print_sensor_callback);
1552 if (!class_node_found)
1553 return;
1555 log_printf("\nTemperature sensors:\n");
1556 if (syserrlog == 0) {
1557 (void) picl_walk_tree_by_class(phyplatformh,
1558 PICL_CLASS_TEMPERATURE_SENSOR,
1559 PICL_PROP_TEMPERATURE, sun4v_env_print_sensor_callback);
1560 if (all_status_ok) {
1561 log_printf("All temperature sensors are OK.\n");
1562 return;
1565 log_printf("-------------------------------------------------"
1566 "---------------\n");
1567 log_printf(fmt, "Location", "Sensor", "Status", 0);
1568 log_printf("-------------------------------------------------"
1569 "---------------\n");
1570 (void) picl_walk_tree_by_class(phyplatformh,
1571 PICL_CLASS_TEMPERATURE_SENSOR,
1572 (void *)PICL_PROP_TEMPERATURE, sun4v_env_print_sensor_callback);
1575 static void
1576 sun4v_env_print_temp_indicators()
1578 char *fmt = "%-34s %-18s %-8s\n";
1579 (void) picl_walk_tree_by_class(phyplatformh,
1580 PICL_CLASS_TEMPERATURE_INDICATOR, (void *)PICL_PROP_CONDITION,
1581 sun4v_env_print_indicator_callback);
1582 if (!class_node_found)
1583 return;
1584 log_printf("\nTemperature indicators:\n");
1585 if (syserrlog == 0) {
1586 (void) picl_walk_tree_by_class(phyplatformh,
1587 PICL_CLASS_TEMPERATURE_INDICATOR,
1588 (void *)PICL_PROP_CONDITION,
1589 sun4v_env_print_indicator_callback);
1590 if (all_status_ok) {
1591 log_printf("All temperature indicators are OK.\n");
1592 return;
1595 log_printf("-------------------------------------------------"
1596 "---------------\n");
1597 log_printf(fmt, "Location", "Indicator", "Condition", 0);
1598 log_printf("-------------------------------------------------"
1599 "---------------\n");
1600 (void) picl_walk_tree_by_class(phyplatformh,
1601 PICL_CLASS_TEMPERATURE_INDICATOR,
1602 (void *)PICL_PROP_CONDITION,
1603 sun4v_env_print_indicator_callback);
1606 static void
1607 sun4v_env_print_current_sensors()
1609 char *fmt = "%-34s %-18s %-10s\n";
1610 (void) picl_walk_tree_by_class(phyplatformh, PICL_CLASS_CURRENT_SENSOR,
1611 (void *)PICL_PROP_CURRENT, sun4v_env_print_sensor_callback);
1612 if (!class_node_found)
1613 return;
1614 log_printf("\nCurrent sensors:\n");
1615 if (syserrlog == 0) {
1616 (void) picl_walk_tree_by_class(phyplatformh,
1617 PICL_CLASS_CURRENT_SENSOR,
1618 PICL_PROP_CURRENT, sun4v_env_print_sensor_callback);
1619 if (all_status_ok) {
1620 log_printf("All current sensors are OK.\n");
1621 return;
1624 log_printf("-------------------------------------------------"
1625 "---------------\n");
1626 log_printf(fmt, "Location", "Sensor", "Status", 0);
1627 log_printf("-------------------------------------------------"
1628 "---------------\n");
1629 (void) picl_walk_tree_by_class(phyplatformh,
1630 PICL_CLASS_CURRENT_SENSOR, (void *)PICL_PROP_CURRENT,
1631 sun4v_env_print_sensor_callback);
1634 static void
1635 sun4v_env_print_current_indicators()
1637 char *fmt = "%-34s %-18s %-8s\n";
1638 (void) picl_walk_tree_by_class(phyplatformh,
1639 PICL_CLASS_CURRENT_INDICATOR,
1640 (void *)PICL_PROP_CONDITION,
1641 sun4v_env_print_indicator_callback);
1642 if (!class_node_found)
1643 return;
1644 log_printf("\nCurrent indicators:\n");
1645 if (syserrlog == 0) {
1646 (void) picl_walk_tree_by_class(phyplatformh,
1647 PICL_CLASS_CURRENT_INDICATOR, (void *)PICL_PROP_CONDITION,
1648 sun4v_env_print_indicator_callback);
1649 if (all_status_ok) {
1650 log_printf("All current indicators are OK.\n");
1651 return;
1654 log_printf("-------------------------------------------------"
1655 "---------------\n");
1656 log_printf(fmt, "Location", "Indicator", "Condition", 0);
1657 log_printf("-------------------------------------------------"
1658 "---------------\n");
1659 (void) picl_walk_tree_by_class(phyplatformh,
1660 PICL_CLASS_CURRENT_INDICATOR,
1661 (void *)PICL_PROP_CONDITION,
1662 sun4v_env_print_indicator_callback);
1665 static void
1666 sun4v_env_print_voltage_sensors()
1668 char *fmt = "%-34s %-18s %-10s\n";
1669 (void) picl_walk_tree_by_class(phyplatformh,
1670 PICL_CLASS_VOLTAGE_SENSOR,
1671 PICL_PROP_VOLTAGE,
1672 sun4v_env_print_sensor_callback);
1673 if (!class_node_found)
1674 return;
1675 log_printf("\nVoltage sensors:\n");
1676 if (syserrlog == 0) {
1677 (void) picl_walk_tree_by_class(phyplatformh,
1678 PICL_CLASS_VOLTAGE_SENSOR,
1679 PICL_PROP_VOLTAGE, sun4v_env_print_sensor_callback);
1680 if (all_status_ok) {
1681 log_printf("All voltage sensors are OK.\n");
1682 return;
1685 log_printf("-------------------------------------------------"
1686 "---------------\n");
1687 log_printf(fmt, "Location", "Sensor", "Status", 0);
1688 log_printf("-------------------------------------------------"
1689 "---------------\n");
1690 (void) picl_walk_tree_by_class(phyplatformh,
1691 PICL_CLASS_VOLTAGE_SENSOR,
1692 (void *)PICL_PROP_VOLTAGE,
1693 sun4v_env_print_sensor_callback);
1696 static void
1697 sun4v_env_print_voltage_indicators()
1699 char *fmt = "%-34s %-18s %-8s\n";
1700 (void) picl_walk_tree_by_class(phyplatformh,
1701 PICL_CLASS_VOLTAGE_INDICATOR,
1702 (void *)PICL_PROP_CONDITION,
1703 sun4v_env_print_indicator_callback);
1704 if (!class_node_found)
1705 return;
1706 log_printf("\nVoltage indicators:\n");
1707 if (syserrlog == 0) {
1708 (void) picl_walk_tree_by_class(phyplatformh,
1709 PICL_CLASS_VOLTAGE_INDICATOR, (void *)PICL_PROP_CONDITION,
1710 sun4v_env_print_indicator_callback);
1711 if (all_status_ok) {
1712 log_printf("All voltage indicators are OK.\n");
1713 return;
1716 log_printf("-------------------------------------------------"
1717 "---------------\n");
1718 log_printf(fmt, "Location", "Indicator", "Condition", 0);
1719 log_printf("-------------------------------------------------"
1720 "---------------\n");
1721 (void) picl_walk_tree_by_class(phyplatformh,
1722 PICL_CLASS_VOLTAGE_INDICATOR,
1723 (void *)PICL_PROP_CONDITION,
1724 sun4v_env_print_indicator_callback);
1727 static void
1728 sun4v_env_print_LEDs()
1730 char *fmt = "%-34s %-18s %-8s\n";
1731 if (syserrlog == 0)
1732 return;
1733 (void) picl_walk_tree_by_class(phyplatformh, PICL_CLASS_LED,
1734 (void *)PICL_PROP_STATE, sun4v_env_print_indicator_callback);
1735 if (!class_node_found)
1736 return;
1737 log_printf("\nLEDs:\n");
1738 log_printf("-------------------------------------------------"
1739 "---------------\n");
1740 log_printf(fmt, "Location", "LED", "State", 0);
1741 log_printf("-------------------------------------------------"
1742 "---------------\n");
1743 (void) picl_walk_tree_by_class(phyplatformh, PICL_CLASS_LED,
1744 (void *)PICL_PROP_STATE, sun4v_env_print_indicator_callback);
1747 /*ARGSUSED*/
1748 static int
1749 sun4v_print_fru_status_callback(picl_nodehdl_t nodeh, void *args)
1751 char label[PICL_PROPNAMELEN_MAX];
1752 char status[PICL_PROPNAMELEN_MAX];
1753 picl_errno_t err;
1754 picl_prophdl_t proph;
1755 picl_nodehdl_t parenth;
1756 char *names[PARENT_NAMES];
1757 char *loc;
1758 int i;
1760 if (!class_node_found) {
1761 class_node_found = 1;
1762 return (PICL_WALK_TERMINATE);
1764 err = picl_get_prop_by_name(nodeh, PICL_PROP_IS_FRU, &proph);
1765 if (err != PICL_SUCCESS)
1766 return (PICL_WALK_CONTINUE);
1767 err = picl_get_propval_by_name(nodeh, PICL_PROP_LABEL, label,
1768 sizeof (label));
1769 if (err != PICL_SUCCESS)
1770 return (PICL_WALK_CONTINUE);
1771 err = picl_get_propval_by_name(nodeh, PICL_PROP_OPERATIONAL_STATUS,
1772 status, sizeof (status));
1773 if (err != PICL_SUCCESS)
1774 return (PICL_WALK_CONTINUE);
1775 if (syserrlog == 0) {
1776 if (strcmp(status, "disabled") == 0) {
1777 if (all_status_ok) {
1778 all_status_ok = 0;
1779 return (PICL_WALK_TERMINATE);
1781 } else
1782 return (PICL_WALK_CONTINUE);
1783 } else {
1784 if (all_status_ok && (strcmp(status, "disabled") == 0)) {
1785 all_status_ok = 0;
1789 if (is_fru_absent(nodeh))
1790 strcpy(status, "Not present");
1792 err = picl_get_propval_by_name(nodeh, PICL_PROP_PARENT, &parenth,
1793 sizeof (parenth));
1794 if (err != PICL_SUCCESS) {
1795 log_printf("\n");
1796 return (PICL_WALK_CONTINUE);
1798 if ((loc = (char *)malloc(PICL_PROPNAMELEN_MAX*PARENT_NAMES)) == NULL)
1799 return (PICL_WALK_TERMINATE);
1800 for (i = 0; i < PARENT_NAMES; i++)
1801 if ((names[i] = (char *)malloc(PICL_PROPNAMELEN_MAX)) == NULL) {
1802 while (--i > -1)
1803 free(names[i]);
1804 free(loc);
1805 return (PICL_WALK_TERMINATE);
1807 i = 0;
1808 while (err == PICL_SUCCESS) {
1809 if (parenth == phyplatformh)
1810 break;
1811 err = picl_get_propval_by_name(parenth, PICL_PROP_NAME,
1812 names[i++], PICL_PROPNAMELEN_MAX);
1813 if (err != PICL_SUCCESS) {
1814 i--;
1815 break;
1817 if (i == PARENT_NAMES)
1818 break;
1819 err = picl_get_propval_by_name(parenth, PICL_PROP_PARENT,
1820 &parenth, sizeof (parenth));
1822 loc[0] = '\0';
1823 if (--i > -1) {
1824 (void) strlcat(loc, names[i],
1825 PICL_PROPNAMELEN_MAX * PARENT_NAMES);
1827 while (--i > -1) {
1828 (void) strlcat(loc, "/", PICL_PROPNAMELEN_MAX * PARENT_NAMES);
1829 (void) strlcat(loc, names[i],
1830 PICL_PROPNAMELEN_MAX * PARENT_NAMES);
1832 log_printf("%-35s", loc);
1833 for (i = 0; i < PARENT_NAMES; i++)
1834 free(names[i]);
1835 free(loc);
1836 log_printf("%-10s", label);
1837 log_printf("%-9s", status);
1838 log_printf("\n");
1839 return (PICL_WALK_CONTINUE);
1842 static void
1843 sun4v_print_fru_status()
1845 char *fmt = "%-34s %-9s %-8s\n";
1847 (void) picl_walk_tree_by_class(phyplatformh, NULL, NULL,
1848 sun4v_print_fru_status_callback);
1849 if (!class_node_found)
1850 return;
1852 log_printf("\n");
1853 log_printf("============================");
1854 log_printf(" FRU Status ");
1855 log_printf("============================");
1856 log_printf("\n");
1858 if (syserrlog == 0) {
1859 (void) picl_walk_tree_by_class(phyplatformh,
1860 NULL, NULL,
1861 sun4v_print_fru_status_callback);
1862 if (all_status_ok) {
1863 log_printf("All FRUs are enabled.\n");
1864 return;
1867 log_printf(fmt, "Location", "Name", "Status", 0);
1868 log_printf("------------------------------------------------------\n");
1869 (void) picl_walk_tree_by_class(phyplatformh, NULL, NULL,
1870 sun4v_print_fru_status_callback);
1873 /* Check the children of the FRU node for a presence indicator */
1874 static int
1875 is_fru_absent(picl_nodehdl_t fruh)
1877 char class [PICL_CLASSNAMELEN_MAX];
1878 char condition [PICL_PROPNAMELEN_MAX];
1879 picl_errno_t err;
1880 picl_nodehdl_t nodeh;
1882 err = picl_get_propval_by_name(fruh, PICL_PROP_CHILD, &nodeh,
1883 sizeof (picl_nodehdl_t));
1884 while (err == PICL_SUCCESS) {
1885 err = picl_get_propval_by_name(nodeh,
1886 PICL_PROP_CLASSNAME, class, sizeof (class));
1887 if (err == PICL_SUCCESS &&
1888 strcmp(class, "presence-indicator") == 0) {
1889 err = picl_get_propval_by_name(nodeh,
1890 PICL_PROP_CONDITION, condition,
1891 sizeof (condition));
1892 if (err == PICL_SUCCESS) {
1893 if (strcmp(condition, "Absent") == 0) {
1894 return (1);
1895 } else {
1896 return (0);
1900 err = picl_get_propval_by_name(nodeh, PICL_PROP_PEER,
1901 &nodeh, sizeof (picl_nodehdl_t));
1903 return (0);
1906 /*ARGSUSED*/
1907 static int
1908 sun4v_print_fw_rev_callback(picl_nodehdl_t nodeh, void *args)
1910 char rev[PICL_PROPNAMELEN_MAX];
1911 picl_errno_t err;
1913 if (!class_node_found) {
1914 class_node_found = 1;
1915 return (PICL_WALK_TERMINATE);
1918 err = picl_get_propval_by_name(nodeh, PICL_PROP_FW_REVISION, rev,
1919 sizeof (rev));
1920 if (err != PICL_SUCCESS)
1921 return (PICL_WALK_CONTINUE);
1922 if (strlen(rev) == 0)
1923 return (PICL_WALK_CONTINUE);
1924 log_printf("%s", rev);
1925 log_printf("\n");
1926 return (PICL_WALK_CONTINUE);
1929 static void
1930 sun4v_print_fw_rev()
1932 if (syserrlog == 0)
1933 return;
1935 (void) picl_walk_tree_by_class(phyplatformh, NULL, NULL,
1936 sun4v_print_fw_rev_callback);
1937 if (!class_node_found)
1938 return;
1940 log_printf("\n");
1941 log_printf("============================");
1942 log_printf(" FW Version ");
1943 log_printf("============================");
1944 log_printf("\n");
1945 log_printf("Version\n");
1946 log_printf("-------------------------------------------------"
1947 "-----------\n");
1948 (void) picl_walk_tree_by_class(phyplatformh, NULL, NULL,
1949 sun4v_print_fw_rev_callback);
1952 static void
1953 sun4v_print_openprom_rev()
1955 if (syserrlog == 0)
1956 return;
1958 (void) picl_walk_tree_by_class(rooth, "openprom", NULL,
1959 openprom_callback);
1960 if (!class_node_found)
1961 return;
1963 log_printf("\n");
1964 log_printf("======================");
1965 log_printf(" System PROM revisions ");
1966 log_printf("=======================");
1967 log_printf("\n");
1968 log_printf("Version\n");
1969 log_printf("-------------------------------------------------"
1970 "-----------\n");
1971 (void) picl_walk_tree_by_class(rooth, "openprom", NULL,
1972 openprom_callback);
1976 * display the OBP and POST prom revisions (if present)
1978 /* ARGSUSED */
1979 static int
1980 openprom_callback(picl_nodehdl_t openpromh, void *arg)
1982 picl_prophdl_t proph;
1983 picl_prophdl_t tblh;
1984 picl_prophdl_t rowproph;
1985 picl_propinfo_t pinfo;
1986 char *prom_version = NULL;
1987 char *obp_version = NULL;
1988 int err;
1990 if (!class_node_found) {
1991 class_node_found = 1;
1992 return (PICL_WALK_TERMINATE);
1995 err = picl_get_propinfo_by_name(openpromh, OBP_PROP_VERSION,
1996 &pinfo, &proph);
1997 if (err == PICL_PROPNOTFOUND)
1998 return (PICL_WALK_TERMINATE);
1999 else if (err != PICL_SUCCESS)
2000 return (err);
2003 * If it's a table prop, the first element is OBP revision
2004 * The second one is POST revision.
2005 * If it's a charstring prop, the value will be only OBP revision
2007 if (pinfo.type == PICL_PTYPE_CHARSTRING) {
2008 prom_version = (char *)alloca(pinfo.size);
2009 if (prom_version == NULL)
2010 return (PICL_FAILURE);
2011 err = picl_get_propval(proph, prom_version, pinfo.size);
2012 if (err != PICL_SUCCESS)
2013 return (err);
2014 log_printf("%s\n", prom_version);
2017 if (pinfo.type != PICL_PTYPE_TABLE) /* not supported type */
2018 return (PICL_WALK_TERMINATE);
2020 err = picl_get_propval(proph, &tblh, pinfo.size);
2021 if (err != PICL_SUCCESS)
2022 return (err);
2024 err = picl_get_next_by_row(tblh, &rowproph);
2025 if (err == PICL_SUCCESS) {
2026 /* get first row */
2027 err = picl_get_propinfo(rowproph, &pinfo);
2028 if (err != PICL_SUCCESS)
2029 return (err);
2031 prom_version = (char *)alloca(pinfo.size);
2032 if (prom_version == NULL)
2033 return (PICL_FAILURE);
2035 err = picl_get_propval(rowproph, prom_version, pinfo.size);
2036 if (err != PICL_SUCCESS)
2037 return (err);
2038 log_printf("%s\n", prom_version);
2040 /* get second row */
2041 err = picl_get_next_by_col(rowproph, &rowproph);
2042 if (err == PICL_SUCCESS) {
2043 err = picl_get_propinfo(rowproph, &pinfo);
2044 if (err != PICL_SUCCESS)
2045 return (err);
2047 obp_version = (char *)alloca(pinfo.size);
2048 if (obp_version == NULL)
2049 return (PICL_FAILURE);
2050 err = picl_get_propval(rowproph, obp_version,
2051 pinfo.size);
2052 if (err != PICL_SUCCESS)
2053 return (err);
2054 log_printf("%s\n", obp_version);
2058 return (PICL_WALK_TERMINATE);
2061 static void
2062 sun4v_print_chassis_serial_no()
2064 char val[PICL_PROPNAMELEN_MAX];
2065 picl_errno_t err;
2066 if (syserrlog == 0 || chassish == 0)
2067 return;
2069 log_printf("\n");
2070 log_printf("Chassis Serial Number");
2071 log_printf("\n");
2072 log_printf("---------------------\n");
2073 err = picl_get_propval_by_name(chassish, PICL_PROP_SERIAL_NUMBER,
2074 val, sizeof (val));
2075 if (err == PICL_SUCCESS)
2076 log_printf("%s", val);
2077 log_printf("\n");