103831d35Sstevel /*
203831d35Sstevel * CDDL HEADER START
303831d35Sstevel *
403831d35Sstevel * The contents of this file are subject to the terms of the
503831d35Sstevel * Common Development and Distribution License (the "License").
603831d35Sstevel * You may not use this file except in compliance with the License.
703831d35Sstevel *
803831d35Sstevel * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
903831d35Sstevel * or http://www.opensolaris.org/os/licensing.
1003831d35Sstevel * See the License for the specific language governing permissions
1103831d35Sstevel * and limitations under the License.
1203831d35Sstevel *
1303831d35Sstevel * When distributing Covered Code, include this CDDL HEADER in each
1403831d35Sstevel * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1503831d35Sstevel * If applicable, add the following below this CDDL HEADER, with the
1603831d35Sstevel * fields enclosed by brackets "[]" replaced with your own identifying
1703831d35Sstevel * information: Portions Copyright [yyyy] [name of copyright owner]
1803831d35Sstevel *
1903831d35Sstevel * CDDL HEADER END
2003831d35Sstevel */
2103831d35Sstevel /*
22*087113e1Smb158278 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
2303831d35Sstevel * Use is subject to license terms.
2403831d35Sstevel */
2503831d35Sstevel
2603831d35Sstevel /*
2703831d35Sstevel * Sun4v Platform specific functions.
2803831d35Sstevel *
2903831d35Sstevel * called when :
3003831d35Sstevel * machine_type == ontario
3103831d35Sstevel *
3203831d35Sstevel */
3303831d35Sstevel
3403831d35Sstevel #include <stdio.h>
3503831d35Sstevel #include <stdlib.h>
3603831d35Sstevel #include <unistd.h>
3703831d35Sstevel #include <kstat.h>
3803831d35Sstevel #include <fcntl.h>
3903831d35Sstevel #include <string.h>
4003831d35Sstevel #include <assert.h>
4103831d35Sstevel #include <libintl.h>
4203831d35Sstevel #include <note.h>
4303831d35Sstevel #include <sys/systeminfo.h>
4403831d35Sstevel #include <sys/openpromio.h>
4503831d35Sstevel #include <sys/sysmacros.h>
4603831d35Sstevel #include <picl.h>
4703831d35Sstevel #include "picldefs.h"
4803831d35Sstevel #include <pdevinfo.h>
4903831d35Sstevel #include <display.h>
5003831d35Sstevel #include <display_sun4v.h>
5103831d35Sstevel #include <libprtdiag.h>
5203831d35Sstevel #include "ontario.h"
5303831d35Sstevel #include "erie.h"
5403831d35Sstevel #include "pelton.h"
559ef7884dSanovick #include "stpaul.h"
5644961713Sgirish #include "huron.h"
5703831d35Sstevel
5803831d35Sstevel #if !defined(TEXT_DOMAIN)
5903831d35Sstevel #define TEXT_DOMAIN "SYS_TEST"
6003831d35Sstevel #endif
6103831d35Sstevel
6203831d35Sstevel /*
6303831d35Sstevel * these functions will overlay the symbol table of libprtdiag
6403831d35Sstevel * at runtime
6503831d35Sstevel */
6603831d35Sstevel void sun4v_display_pci(picl_nodehdl_t plafh);
6703831d35Sstevel void sun4v_display_diaginfo(int flag, Prom_node *root, picl_nodehdl_t plafh);
6803831d35Sstevel
6903831d35Sstevel
7003831d35Sstevel /* local functions */
7103831d35Sstevel static void sun4v_display_hw_revisions(Prom_node *root, picl_nodehdl_t plafh);
7203831d35Sstevel static int ontario_pci_callback(picl_nodehdl_t pcih, void *args);
7303831d35Sstevel static int ontario_get_first_compatible_value(picl_nodehdl_t nodeh,
7403831d35Sstevel char **outbuf);
7503831d35Sstevel static int64_t ontario_get_int_propval(picl_nodehdl_t modh, char *prop_name,
7603831d35Sstevel int *ret);
7703831d35Sstevel
7803831d35Sstevel static void
get_bus_type(char * path,struct io_card * card)7903831d35Sstevel get_bus_type(char *path, struct io_card *card)
8003831d35Sstevel {
8103831d35Sstevel if (strncmp(path, PCIX_SLOT0, PCIX_COMP_NUM) == 0) {
8203831d35Sstevel (void) strcpy(card->bus_type, "PCIX");
8303831d35Sstevel } else {
8403831d35Sstevel (void) strcpy(card->bus_type, "PCIE");
8503831d35Sstevel }
8603831d35Sstevel }
8703831d35Sstevel
8803831d35Sstevel static void
get_slot_number(picl_nodehdl_t nodeh,char * path,struct io_card * card)89e9589223Smb158278 get_slot_number(picl_nodehdl_t nodeh, char *path, struct io_card *card)
9003831d35Sstevel {
9103831d35Sstevel if (strncmp(path, PCIE_SLOT0, PCIE_COMP_NUM) == 0) {
9203831d35Sstevel (void) strcpy(card->slot_str, "0");
9303831d35Sstevel card->slot = 0;
9403831d35Sstevel } else if (strncmp(path, PCIE_SLOT1, PCIE_COMP_NUM) == 0) {
9503831d35Sstevel (void) strcpy(card->slot_str, "1");
9603831d35Sstevel card->slot = 1;
9703831d35Sstevel } else if (strncmp(path, PCIE_SLOT2, PCIE_COMP_NUM) == 0) {
9803831d35Sstevel (void) strcpy(card->slot_str, "2");
9903831d35Sstevel card->slot = 2;
100e9589223Smb158278 } else if ((strncmp(path, PCIX_SLOT1, strlen(PCIX_SLOT1)) == 0) ||
101e9589223Smb158278 (strncmp(path, PCIX_SLOT0, strlen(PCIX_SLOT0)) == 0)) {
102e9589223Smb158278 char ua[MAXSTRLEN];
103e9589223Smb158278 int err;
104e9589223Smb158278
10503831d35Sstevel (void) strcpy(card->slot_str, "PCIX");
10603831d35Sstevel card->slot = -1;
107e9589223Smb158278
108e9589223Smb158278 /*
109e9589223Smb158278 * PCIX_SLOT0 and PCIX_SLOT1 are actually the same path so
110e9589223Smb158278 * use the unit address to distinguish the slot number.
111e9589223Smb158278 */
112e9589223Smb158278 err = picl_get_propval_by_name(nodeh, PICL_PROP_UNIT_ADDRESS,
113e9589223Smb158278 ua, sizeof (ua));
114e9589223Smb158278 if (err == PICL_SUCCESS) {
115e9589223Smb158278 if (ua[0] == '2') {
116e9589223Smb158278 card->slot = 0;
117e9589223Smb158278 (void) strcpy(card->slot_str, "0");
118e9589223Smb158278 } else if (ua[0] == '1') {
119e9589223Smb158278 card->slot = 1;
120e9589223Smb158278 (void) strcpy(card->slot_str, "1");
121e9589223Smb158278 }
122e9589223Smb158278 }
12303831d35Sstevel } else {
12403831d35Sstevel (void) strcpy(card->slot_str, IOBOARD);
12503831d35Sstevel card->slot = -1;
12603831d35Sstevel }
12703831d35Sstevel }
12803831d35Sstevel
12903831d35Sstevel static int
ontario_get_network_instance(char * path)13003831d35Sstevel ontario_get_network_instance(char *path)
13103831d35Sstevel {
13203831d35Sstevel if (strncmp(path, NETWORK_1_PATH, strlen(NETWORK_1_PATH)) == 0) {
13303831d35Sstevel return (1);
13403831d35Sstevel } else if (strncmp(path, NETWORK_3_PATH, strlen(NETWORK_3_PATH)) == 0) {
13503831d35Sstevel return (3);
13603831d35Sstevel } else if (strncmp(path, NETWORK_0_PATH, strlen(NETWORK_0_PATH)) == 0) {
13703831d35Sstevel return (0);
13803831d35Sstevel } else if (strncmp(path, NETWORK_2_PATH, strlen(NETWORK_2_PATH)) == 0) {
13903831d35Sstevel return (2);
14003831d35Sstevel } else {
14103831d35Sstevel return (-1);
14203831d35Sstevel }
14303831d35Sstevel }
14403831d35Sstevel /*
14503831d35Sstevel * add all io devices under pci in io list
14603831d35Sstevel */
14703831d35Sstevel /* ARGSUSED */
14803831d35Sstevel static int
ontario_pci_callback(picl_nodehdl_t pcih,void * args)14903831d35Sstevel ontario_pci_callback(picl_nodehdl_t pcih, void *args)
15003831d35Sstevel {
15103831d35Sstevel int err = PICL_SUCCESS;
15203831d35Sstevel picl_nodehdl_t nodeh;
15303831d35Sstevel char path[MAXSTRLEN];
15403831d35Sstevel char parent_path[MAXSTRLEN];
15503831d35Sstevel char piclclass[PICL_CLASSNAMELEN_MAX];
15603831d35Sstevel char name[MAXSTRLEN];
15703831d35Sstevel char model[MAXSTRLEN];
15803831d35Sstevel char *compatible;
15903831d35Sstevel char binding_name[MAXSTRLEN];
16003831d35Sstevel struct io_card pci_card;
16103831d35Sstevel int32_t instance;
16203831d35Sstevel
16303831d35Sstevel err = picl_get_propval_by_name(pcih, PICL_PROP_DEVFS_PATH, parent_path,
16403831d35Sstevel sizeof (parent_path));
16503831d35Sstevel if (err != PICL_SUCCESS) {
16603831d35Sstevel return (err);
16703831d35Sstevel }
16803831d35Sstevel
16903831d35Sstevel /* Walk through the children */
17003831d35Sstevel
17103831d35Sstevel err = picl_get_propval_by_name(pcih, PICL_PROP_CHILD, &nodeh,
17203831d35Sstevel sizeof (picl_nodehdl_t));
17303831d35Sstevel
17403831d35Sstevel while (err == PICL_SUCCESS) {
17503831d35Sstevel err = picl_get_propval_by_name(nodeh, PICL_PROP_CLASSNAME,
17603831d35Sstevel piclclass, sizeof (piclclass));
17703831d35Sstevel if (err != PICL_SUCCESS)
17803831d35Sstevel return (err);
17903831d35Sstevel
180e9589223Smb158278 /*
181e9589223Smb158278 * Skip PCI and PCIEX devices because they will be processed
182e9589223Smb158278 * later in the picl tree walk.
183e9589223Smb158278 */
184e9589223Smb158278 if ((strcmp(piclclass, "pci") == 0) ||
185e9589223Smb158278 (strcmp(piclclass, "pciex") == 0)) {
18603831d35Sstevel err = picl_get_propval_by_name(nodeh, PICL_PROP_PEER,
18703831d35Sstevel &nodeh, sizeof (picl_nodehdl_t));
18803831d35Sstevel continue;
18903831d35Sstevel }
19003831d35Sstevel
19103831d35Sstevel err = picl_get_propval_by_name(nodeh, PICL_PROP_DEVFS_PATH,
19203831d35Sstevel path, sizeof (path));
19303831d35Sstevel if (err != PICL_SUCCESS) {
19403831d35Sstevel return (err);
19503831d35Sstevel }
19603831d35Sstevel
19703831d35Sstevel (void) strlcpy(pci_card.notes, path, sizeof (pci_card.notes));
19803831d35Sstevel
19903831d35Sstevel get_bus_type(parent_path, &pci_card);
20003831d35Sstevel
201e9589223Smb158278 get_slot_number(nodeh, parent_path, &pci_card);
20203831d35Sstevel
20303831d35Sstevel err = picl_get_propval_by_name(nodeh, PICL_PROP_NAME, &name,
20403831d35Sstevel sizeof (name));
20503831d35Sstevel if (err == PICL_PROPNOTFOUND)
20603831d35Sstevel (void) strcpy(name, "");
20703831d35Sstevel else if (err != PICL_SUCCESS)
20803831d35Sstevel return (err);
20903831d35Sstevel
21003831d35Sstevel /* Figure NAC name */
21103831d35Sstevel if ((strcmp(name, NETWORK) == 0) &&
21203831d35Sstevel (strcmp(pci_card.slot_str, IOBOARD) == 0)) {
21303831d35Sstevel instance = ontario_get_network_instance(path);
21403831d35Sstevel
21503831d35Sstevel (void) snprintf(pci_card.status,
21603831d35Sstevel sizeof (pci_card.status), "%s/%s%d", IOBOARD,
21703831d35Sstevel "NET", instance);
21803831d35Sstevel } else {
21903831d35Sstevel if (pci_card.slot != -1) {
22003831d35Sstevel (void) snprintf(pci_card.status,
22103831d35Sstevel sizeof (pci_card.status), "%s/%s%d",
22203831d35Sstevel IOBOARD, pci_card.bus_type, pci_card.slot);
22303831d35Sstevel } else {
22403831d35Sstevel (void) snprintf(pci_card.status,
22503831d35Sstevel sizeof (pci_card.status), "%s/%s", IOBOARD,
22603831d35Sstevel pci_card.bus_type);
22703831d35Sstevel }
22803831d35Sstevel }
22903831d35Sstevel
23003831d35Sstevel /*
23103831d35Sstevel * Get the name of this card. If binding_name is found,
23203831d35Sstevel * name will be <nodename>-<binding_name>
23303831d35Sstevel */
23403831d35Sstevel
23503831d35Sstevel err = picl_get_propval_by_name(nodeh, PICL_PROP_BINDING_NAME,
23603831d35Sstevel &binding_name, sizeof (binding_name));
23703831d35Sstevel if (err == PICL_PROPNOTFOUND) {
23803831d35Sstevel /*
23903831d35Sstevel * if compatible prop is found, name will be
24003831d35Sstevel * <nodename>-<compatible>
24103831d35Sstevel */
24203831d35Sstevel err = ontario_get_first_compatible_value(nodeh,
24303831d35Sstevel &compatible);
24403831d35Sstevel if (err == PICL_SUCCESS) {
24503831d35Sstevel (void) strlcat(name, "-", MAXSTRLEN);
24603831d35Sstevel (void) strlcat(name, compatible, MAXSTRLEN);
24703831d35Sstevel free(compatible);
24803831d35Sstevel } else if (err != PICL_PROPNOTFOUND) {
24903831d35Sstevel return (err);
25003831d35Sstevel }
25103831d35Sstevel } else if (err != PICL_SUCCESS) {
25203831d35Sstevel return (err);
25303831d35Sstevel } else if (strcmp(name, binding_name) != 0) {
25403831d35Sstevel (void) strlcat(name, "-", MAXSTRLEN);
25503831d35Sstevel (void) strlcat(name, binding_name, MAXSTRLEN);
25603831d35Sstevel }
25703831d35Sstevel
25803831d35Sstevel (void) strlcpy(pci_card.name, name, sizeof (pci_card.name));
25903831d35Sstevel
26003831d35Sstevel /* Get the model of this card */
26103831d35Sstevel
26203831d35Sstevel err = picl_get_propval_by_name(nodeh, OBP_PROP_MODEL,
26303831d35Sstevel &model, sizeof (model));
26403831d35Sstevel if (err == PICL_PROPNOTFOUND)
26503831d35Sstevel (void) strcpy(model, "");
26603831d35Sstevel else if (err != PICL_SUCCESS)
26703831d35Sstevel return (err);
26803831d35Sstevel (void) strlcpy(pci_card.model, model, sizeof (pci_card.model));
26903831d35Sstevel
27003831d35Sstevel /* Print NAC name */
27103831d35Sstevel log_printf("%-11s", pci_card.status);
27203831d35Sstevel /* Print IO Type */
27303831d35Sstevel log_printf("%6s", pci_card.bus_type);
27403831d35Sstevel /* Print Slot # */
27503831d35Sstevel log_printf("%5s", pci_card.slot_str);
27603831d35Sstevel /* Print Parent Path */
27703831d35Sstevel log_printf("%46.45s", pci_card.notes);
27803831d35Sstevel /* Printf Card Name */
279867ad6ccSjesusm if (strlen(pci_card.name) > 25)
28003831d35Sstevel log_printf("%25.24s+", pci_card.name);
28103831d35Sstevel else
28203831d35Sstevel log_printf("%26s", pci_card.name);
28303831d35Sstevel /* Print Card Model */
28403831d35Sstevel if (strlen(pci_card.model) > 10)
28503831d35Sstevel log_printf("%10.9s+", pci_card.model);
28603831d35Sstevel else
287867ad6ccSjesusm log_printf("%11s", pci_card.model);
28803831d35Sstevel log_printf("\n");
28903831d35Sstevel
29003831d35Sstevel err = picl_get_propval_by_name(nodeh, PICL_PROP_PEER, &nodeh,
29103831d35Sstevel sizeof (picl_nodehdl_t));
29203831d35Sstevel
29303831d35Sstevel }
29403831d35Sstevel
29503831d35Sstevel return (PICL_WALK_CONTINUE);
29603831d35Sstevel }
29703831d35Sstevel /*
29803831d35Sstevel * display_pci
29903831d35Sstevel * Display all the PCI IO cards on this board.
30003831d35Sstevel */
30103831d35Sstevel void
sun4v_display_pci(picl_nodehdl_t plafh)30203831d35Sstevel sun4v_display_pci(picl_nodehdl_t plafh)
30303831d35Sstevel {
30403831d35Sstevel char platbuf[MAXSTRLEN];
305867ad6ccSjesusm char *fmt = "%-11s %-5s %-4s %-45s %-25s %-10s";
30603831d35Sstevel static int banner = FALSE; /* Have we printed the column headings? */
30703831d35Sstevel
30803831d35Sstevel if (banner == FALSE) {
30903831d35Sstevel log_printf("\n", 0);
31003831d35Sstevel log_printf("=========================", 0);
31103831d35Sstevel log_printf(dgettext(TEXT_DOMAIN, " IO Configuration "), 0);
31203831d35Sstevel log_printf("=========================", 0);
31303831d35Sstevel log_printf("\n", 0);
31403831d35Sstevel log_printf("\n", 0);
31503831d35Sstevel log_printf(fmt, "", "IO", "", "", "", "", 0);
31603831d35Sstevel log_printf("\n", 0);
31703831d35Sstevel log_printf(fmt, "Location", "Type", "Slot", "Path",
31803831d35Sstevel "Name", "Model", 0);
31903831d35Sstevel log_printf("\n");
32003831d35Sstevel log_printf(fmt, "-----------", "-----", "----",
32103831d35Sstevel "---------------------------------------------",
322867ad6ccSjesusm "-------------------------", "----------", 0);
32303831d35Sstevel log_printf("\n");
32403831d35Sstevel banner = TRUE;
32503831d35Sstevel }
32603831d35Sstevel
32703831d35Sstevel /* Get platform name, if that fails, use ontario name by default */
32803831d35Sstevel if (sysinfo(SI_PLATFORM, platbuf, sizeof (platbuf)) == -1) {
32903831d35Sstevel (void) strcpy(platbuf, ONTARIO_PLATFORM);
33003831d35Sstevel }
33103831d35Sstevel
33203831d35Sstevel /*
33303831d35Sstevel * Call functions based on appropriate platform
33403831d35Sstevel */
33503831d35Sstevel if ((strncmp(platbuf, ONTARIO_PLATFORM,
336077f2dabSzx143588 strlen(ONTARIO_PLATFORM)) == 0) ||
337077f2dabSzx143588 (strncmp(platbuf, ONTARIO_PLATFORM2,
338077f2dabSzx143588 strlen(ONTARIO_PLATFORM2)) == 0)) {
33903831d35Sstevel (void) picl_walk_tree_by_class(plafh, "pciex",
34003831d35Sstevel "pciex", ontario_pci_callback);
341e9589223Smb158278 (void) picl_walk_tree_by_class(plafh, "pci",
342e9589223Smb158278 "pci", ontario_pci_callback);
34303831d35Sstevel } else if ((strncmp(platbuf, PELTON_PLATFORM,
34403831d35Sstevel strlen(PELTON_PLATFORM))) == 0) {
34503831d35Sstevel (void) picl_walk_tree_by_class(plafh, "pciex",
34603831d35Sstevel "pciex", pelton_pci_callback);
347483dd6e5Sarutz (void) picl_walk_tree_by_class(plafh, "pci",
348483dd6e5Sarutz "pci", pelton_pci_callback);
3499ef7884dSanovick } else if ((strncmp(platbuf, STPAUL_PLATFORM,
3509ef7884dSanovick strlen(STPAUL_PLATFORM))) == 0) {
3519ef7884dSanovick (void) picl_walk_tree_by_class(plafh, "pciex",
3529ef7884dSanovick "pciex", stpaul_pci_callback);
35344961713Sgirish } else if ((strncmp(platbuf, HURON_1U_PLATFORM,
35444961713Sgirish strlen(HURON_1U_PLATFORM)) == 0) || (strncmp(platbuf,
35544961713Sgirish HURON_2U_PLATFORM, strlen(HURON_2U_PLATFORM)) == 0)) {
35687c478a5Szx143588 (void) picl_walk_tree_by_class(plafh, "sun4v",
35787c478a5Szx143588 "niu", huron_pci_callback);
35844961713Sgirish (void) picl_walk_tree_by_class(plafh, "pciex",
35944961713Sgirish "pciex", huron_pci_callback);
36003831d35Sstevel } else {
36103831d35Sstevel (void) picl_walk_tree_by_class(plafh, "pciex", "pciex",
36203831d35Sstevel erie_pci_callback);
36303831d35Sstevel (void) picl_walk_tree_by_class(plafh, "pci", "pci",
36403831d35Sstevel erie_pci_callback);
36503831d35Sstevel }
36603831d35Sstevel }
36703831d35Sstevel
36803831d35Sstevel /*
36903831d35Sstevel * ----------------------------------------------------------------------------
37003831d35Sstevel */
37103831d35Sstevel
37203831d35Sstevel /* ARGSUSED */
37303831d35Sstevel void
sun4v_display_diaginfo(int flag,Prom_node * root,picl_nodehdl_t plafh)37403831d35Sstevel sun4v_display_diaginfo(int flag, Prom_node *root, picl_nodehdl_t plafh)
37503831d35Sstevel {
37603831d35Sstevel /* NOTE(ARGUNUSED(kstats)) */
37703831d35Sstevel /*
37803831d35Sstevel * Now display the last powerfail time and the fatal hardware
37903831d35Sstevel * reset information. We do this under a couple of conditions.
38003831d35Sstevel * First if the user asks for it. The second is if the user
38103831d35Sstevel * told us to do logging, and we found a system failure.
38203831d35Sstevel */
38303831d35Sstevel if (flag) {
38403831d35Sstevel /*
38503831d35Sstevel * display time of latest powerfail. Not all systems
38603831d35Sstevel * have this capability. For those that do not, this
38703831d35Sstevel * is just a no-op.
38803831d35Sstevel */
38903831d35Sstevel disp_powerfail(root);
39003831d35Sstevel
39103831d35Sstevel /* platform_disp_prom_version(tree); */
39203831d35Sstevel sun4v_display_hw_revisions(root, plafh);
39303831d35Sstevel }
39403831d35Sstevel }
39503831d35Sstevel
39603831d35Sstevel /*
39703831d35Sstevel * local functions
39803831d35Sstevel */
39903831d35Sstevel /*
40003831d35Sstevel * add all io devices under pci in io list
40103831d35Sstevel */
40203831d35Sstevel /* ARGSUSED */
40303831d35Sstevel static int
ontario_hw_rev_callback(picl_nodehdl_t pcih,void * args)40403831d35Sstevel ontario_hw_rev_callback(picl_nodehdl_t pcih, void *args)
40503831d35Sstevel {
40603831d35Sstevel int err = PICL_SUCCESS;
40703831d35Sstevel char path[MAXSTRLEN] = "";
40803831d35Sstevel char device_path[MAXSTRLEN];
40903831d35Sstevel char NAC[MAXSTRLEN];
41003831d35Sstevel char *compatible;
41103831d35Sstevel int32_t revision;
41203831d35Sstevel int device_found;
41303831d35Sstevel
41403831d35Sstevel device_found = 0;
41503831d35Sstevel
41603831d35Sstevel err = picl_get_propval_by_name(pcih, PICL_PROP_DEVFS_PATH, path,
41703831d35Sstevel sizeof (path));
41803831d35Sstevel if (err != PICL_SUCCESS) {
41903831d35Sstevel return (err);
42003831d35Sstevel }
42103831d35Sstevel
42203831d35Sstevel if ((strcmp(path, NETWORK_0_PATH) == 0) ||
42303831d35Sstevel (strcmp(path, NETWORK_1_PATH) == 0)) {
42403831d35Sstevel device_found = 1;
42503831d35Sstevel (void) snprintf(NAC, sizeof (NAC), "%s/%s%d", IOBOARD, OPHIR,
42603831d35Sstevel 0);
42703831d35Sstevel revision = ontario_get_int_propval(pcih, OBP_PROP_REVISION_ID,
42803831d35Sstevel &err);
42903831d35Sstevel }
43003831d35Sstevel
43103831d35Sstevel if ((strcmp(path, NETWORK_2_PATH) == 0) ||
43203831d35Sstevel (strcmp(path, NETWORK_3_PATH) == 0)) {
43303831d35Sstevel device_found = 1;
43403831d35Sstevel (void) snprintf(NAC, sizeof (NAC), "%s/%s%d", IOBOARD, OPHIR,
43503831d35Sstevel 1);
43603831d35Sstevel revision = ontario_get_int_propval(pcih, OBP_PROP_REVISION_ID,
43703831d35Sstevel &err);
43803831d35Sstevel }
43903831d35Sstevel
44003831d35Sstevel if ((strcmp(path, FIRE_PATH0) == 0) ||
44103831d35Sstevel (strcmp(path, FIRE_PATH1) == 0)) {
44203831d35Sstevel device_found = 1;
44303831d35Sstevel (void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD,
44403831d35Sstevel "IO-BRIDGE");
44503831d35Sstevel revision = ontario_get_int_propval(pcih, OBP_PROP_VERSION_NUM,
44603831d35Sstevel &err);
44703831d35Sstevel }
44803831d35Sstevel
44903831d35Sstevel if ((strcmp(path, PCIX_SLOT0) == 0) ||
45003831d35Sstevel (strcmp(path, PCIX_SLOT1) == 0)) {
45103831d35Sstevel device_found = 1;
45203831d35Sstevel (void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD,
45303831d35Sstevel PCI_BRIDGE);
45403831d35Sstevel revision = ontario_get_int_propval(pcih, OBP_PROP_REVISION_ID,
45503831d35Sstevel &err);
45603831d35Sstevel }
45703831d35Sstevel
45803831d35Sstevel if (strcmp(path, SWITCH_A_PATH) == 0) {
45903831d35Sstevel device_found = 1;
46003831d35Sstevel (void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD, SWITCH_A);
46103831d35Sstevel revision = ontario_get_int_propval(pcih, OBP_PROP_REVISION_ID,
46203831d35Sstevel &err);
46303831d35Sstevel }
46403831d35Sstevel
46503831d35Sstevel if (strcmp(path, SWITCH_B_PATH) == 0) {
46603831d35Sstevel device_found = 1;
46703831d35Sstevel (void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD, SWITCH_B);
46803831d35Sstevel revision = ontario_get_int_propval(pcih, OBP_PROP_REVISION_ID,
46903831d35Sstevel &err);
47003831d35Sstevel }
47103831d35Sstevel
47203831d35Sstevel if (strcmp(path, ONT_LSI_PATH) == 0) {
47303831d35Sstevel device_found = 1;
47403831d35Sstevel (void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD,
47503831d35Sstevel SAS_SATA_HBA);
47603831d35Sstevel revision = ontario_get_int_propval(pcih, OBP_PROP_REVISION_ID,
47703831d35Sstevel &err);
47803831d35Sstevel }
47903831d35Sstevel if (device_found == 1) {
48003831d35Sstevel (void) strcpy(device_path, path);
48103831d35Sstevel err = ontario_get_first_compatible_value(pcih, &compatible);
48203831d35Sstevel
48303831d35Sstevel /* Print NAC name */
48403831d35Sstevel log_printf("%-20s", NAC);
48503831d35Sstevel /* Print Device Path */
48603831d35Sstevel if (strlen(device_path) > 38)
48703831d35Sstevel log_printf("%38.37s+", device_path);
48803831d35Sstevel else
48903831d35Sstevel log_printf("%39s", device_path);
49003831d35Sstevel /* Print Compatible # */
491*087113e1Smb158278 if (err == PICL_SUCCESS) {
49203831d35Sstevel log_printf("%31s", compatible);
49303831d35Sstevel free(compatible);
494*087113e1Smb158278 } else
495*087113e1Smb158278 log_printf("%31s", " ");
49603831d35Sstevel /* Print Revision */
49703831d35Sstevel log_printf("%6d", revision);
49803831d35Sstevel log_printf("\n");
49903831d35Sstevel }
50003831d35Sstevel
50103831d35Sstevel return (PICL_WALK_CONTINUE);
50203831d35Sstevel }
50303831d35Sstevel
50403831d35Sstevel /*ARGSUSED*/
50503831d35Sstevel static void
sun4v_display_hw_revisions(Prom_node * root,picl_nodehdl_t plafh)50603831d35Sstevel sun4v_display_hw_revisions(Prom_node *root, picl_nodehdl_t plafh)
50703831d35Sstevel {
50803831d35Sstevel Prom_node *pnode;
50903831d35Sstevel char *value;
51003831d35Sstevel char platbuf[MAXSTRLEN];
51144961713Sgirish char *fmt = "%-20s %-45s %-30s %-9s";
51203831d35Sstevel
51303831d35Sstevel log_printf(dgettext(TEXT_DOMAIN, "\n"
51403831d35Sstevel "========================= HW Revisions "
51503831d35Sstevel "=======================================\n\n"));
51603831d35Sstevel
51703831d35Sstevel log_printf(dgettext(TEXT_DOMAIN,
51803831d35Sstevel "System PROM revisions:\n"
51903831d35Sstevel "----------------------\n"));
52003831d35Sstevel
52103831d35Sstevel pnode = dev_find_node(root, "openprom");
52203831d35Sstevel if (pnode != NULL) {
52303831d35Sstevel value = (char *)get_prop_val(find_prop(pnode, "version"));
52403831d35Sstevel log_printf(value);
52503831d35Sstevel }
52603831d35Sstevel
52703831d35Sstevel log_printf(dgettext(TEXT_DOMAIN, "\n\n"
52803831d35Sstevel "IO ASIC revisions:\n"
52903831d35Sstevel "------------------\n"));
53003831d35Sstevel log_printf(fmt, "Location", "Path", "Device", "Revision\n", 0);
53103831d35Sstevel log_printf(fmt, "--------------------",
53244961713Sgirish "---------------------------------------------",
53303831d35Sstevel "------------------------------",
53403831d35Sstevel "---------\n", 0);
53503831d35Sstevel
53603831d35Sstevel /* Get platform name, if that fails, use ontario name by default */
53703831d35Sstevel if (sysinfo(SI_PLATFORM, platbuf, sizeof (platbuf)) == -1) {
53803831d35Sstevel (void) strcpy(platbuf, ONTARIO_PLATFORM);
53903831d35Sstevel }
54003831d35Sstevel
54103831d35Sstevel /*
54203831d35Sstevel * Walk tree based on platform
54303831d35Sstevel */
54403831d35Sstevel if ((strncmp(platbuf, ONTARIO_PLATFORM,
54503831d35Sstevel strlen(ONTARIO_PLATFORM))) == 0) {
54603831d35Sstevel (void) picl_walk_tree_by_class(plafh, "pciex",
54703831d35Sstevel "pciex", ontario_hw_rev_callback);
54803831d35Sstevel (void) picl_walk_tree_by_class(plafh, "pci",
54903831d35Sstevel "pci", ontario_hw_rev_callback);
55003831d35Sstevel (void) picl_walk_tree_by_class(plafh, "network",
55103831d35Sstevel "network", ontario_hw_rev_callback);
55203831d35Sstevel (void) picl_walk_tree_by_class(plafh, "scsi-2", "scsi-2",
55303831d35Sstevel ontario_hw_rev_callback);
55403831d35Sstevel } else if ((strncmp(platbuf, PELTON_PLATFORM,
55503831d35Sstevel strlen(PELTON_PLATFORM))) == 0) {
55603831d35Sstevel (void) picl_walk_tree_by_class(plafh, "pciex",
55703831d35Sstevel "pciex", pelton_hw_rev_callback);
55803831d35Sstevel (void) picl_walk_tree_by_class(plafh, "pci",
55903831d35Sstevel "pci", pelton_hw_rev_callback);
56003831d35Sstevel (void) picl_walk_tree_by_class(plafh, "network",
56103831d35Sstevel "network", pelton_hw_rev_callback);
56203831d35Sstevel (void) picl_walk_tree_by_class(plafh, "scsi-2", "scsi-2",
56303831d35Sstevel pelton_hw_rev_callback);
5649ef7884dSanovick } else if ((strncmp(platbuf, STPAUL_PLATFORM,
5659ef7884dSanovick strlen(STPAUL_PLATFORM))) == 0) {
5669ef7884dSanovick (void) picl_walk_tree_by_class(plafh, "pciex",
5679ef7884dSanovick "pciex", stpaul_hw_rev_callback);
5689ef7884dSanovick (void) picl_walk_tree_by_class(plafh, "pci",
5699ef7884dSanovick "pci", stpaul_hw_rev_callback);
5709ef7884dSanovick (void) picl_walk_tree_by_class(plafh, "network",
5719ef7884dSanovick "network", stpaul_hw_rev_callback);
5729ef7884dSanovick (void) picl_walk_tree_by_class(plafh, "scsi-2", "scsi-2",
5739ef7884dSanovick stpaul_hw_rev_callback);
57444961713Sgirish } else if ((strncmp(platbuf, HURON_1U_PLATFORM,
57544961713Sgirish strlen(HURON_1U_PLATFORM)) == 0) || (strncmp(platbuf,
57644961713Sgirish HURON_2U_PLATFORM, strlen(HURON_2U_PLATFORM)) == 0)) {
57744961713Sgirish (void) picl_walk_tree_by_class(plafh, "pciex",
57844961713Sgirish "pciex", huron_hw_rev_callback);
57987c478a5Szx143588 (void) picl_walk_tree_by_class(plafh, "sun4v",
58087c478a5Szx143588 "niu", huron_hw_rev_callback);
58144961713Sgirish (void) picl_walk_tree_by_class(plafh, "network",
58244961713Sgirish "network", huron_hw_rev_callback);
58344961713Sgirish (void) picl_walk_tree_by_class(plafh, "scsi-2", "scsi-2",
58444961713Sgirish huron_hw_rev_callback);
58503831d35Sstevel } else {
58603831d35Sstevel (void) picl_walk_tree_by_class(plafh, "pciex", "pciex",
58703831d35Sstevel erie_hw_rev_callback);
58803831d35Sstevel (void) picl_walk_tree_by_class(plafh, "pci", "pci",
58903831d35Sstevel erie_hw_rev_callback);
59003831d35Sstevel (void) picl_walk_tree_by_class(plafh, "network", "network",
59103831d35Sstevel erie_hw_rev_callback);
59203831d35Sstevel (void) picl_walk_tree_by_class(plafh, "scsi-2", "scsi-2",
59303831d35Sstevel erie_hw_rev_callback);
59403831d35Sstevel }
59503831d35Sstevel }
59603831d35Sstevel
59703831d35Sstevel /*
59803831d35Sstevel * return the first compatible value
59903831d35Sstevel */
60003831d35Sstevel static int
ontario_get_first_compatible_value(picl_nodehdl_t nodeh,char ** outbuf)60103831d35Sstevel ontario_get_first_compatible_value(picl_nodehdl_t nodeh, char **outbuf)
60203831d35Sstevel {
60303831d35Sstevel int err;
60403831d35Sstevel picl_prophdl_t proph;
60503831d35Sstevel picl_propinfo_t pinfo;
60603831d35Sstevel picl_prophdl_t tblh;
60703831d35Sstevel picl_prophdl_t rowproph;
60803831d35Sstevel char *pval;
60903831d35Sstevel
61003831d35Sstevel err = picl_get_propinfo_by_name(nodeh, OBP_PROP_COMPATIBLE,
61103831d35Sstevel &pinfo, &proph);
61203831d35Sstevel if (err != PICL_SUCCESS)
61303831d35Sstevel return (err);
61403831d35Sstevel
61503831d35Sstevel if (pinfo.type == PICL_PTYPE_CHARSTRING) {
61603831d35Sstevel pval = malloc(pinfo.size);
61703831d35Sstevel if (pval == NULL)
61803831d35Sstevel return (PICL_FAILURE);
61903831d35Sstevel err = picl_get_propval(proph, pval, pinfo.size);
62003831d35Sstevel if (err != PICL_SUCCESS) {
62103831d35Sstevel free(pval);
62203831d35Sstevel return (err);
62303831d35Sstevel }
62403831d35Sstevel *outbuf = pval;
62503831d35Sstevel return (PICL_SUCCESS);
62603831d35Sstevel }
62703831d35Sstevel
62803831d35Sstevel if (pinfo.type != PICL_PTYPE_TABLE)
62903831d35Sstevel return (PICL_FAILURE);
63003831d35Sstevel
63103831d35Sstevel /* get first string from table */
63203831d35Sstevel err = picl_get_propval(proph, &tblh, pinfo.size);
63303831d35Sstevel if (err != PICL_SUCCESS)
63403831d35Sstevel return (err);
63503831d35Sstevel
63603831d35Sstevel err = picl_get_next_by_row(tblh, &rowproph);
63703831d35Sstevel if (err != PICL_SUCCESS)
63803831d35Sstevel return (err);
63903831d35Sstevel
64003831d35Sstevel err = picl_get_propinfo(rowproph, &pinfo);
64103831d35Sstevel if (err != PICL_SUCCESS)
64203831d35Sstevel return (err);
64303831d35Sstevel
64403831d35Sstevel pval = malloc(pinfo.size);
64503831d35Sstevel if (pval == NULL)
64603831d35Sstevel return (PICL_FAILURE);
64703831d35Sstevel
64803831d35Sstevel err = picl_get_propval(rowproph, pval, pinfo.size);
64903831d35Sstevel if (err != PICL_SUCCESS) {
65003831d35Sstevel free(pval);
65103831d35Sstevel return (err);
65203831d35Sstevel }
65303831d35Sstevel
65403831d35Sstevel *outbuf = pval;
65503831d35Sstevel return (PICL_SUCCESS);
65603831d35Sstevel }
65703831d35Sstevel
65803831d35Sstevel static int64_t
ontario_get_int_propval(picl_nodehdl_t modh,char * prop_name,int * ret)65903831d35Sstevel ontario_get_int_propval(picl_nodehdl_t modh, char *prop_name, int *ret)
66003831d35Sstevel {
66103831d35Sstevel int err;
66203831d35Sstevel picl_prophdl_t proph;
66303831d35Sstevel picl_propinfo_t pinfo;
66403831d35Sstevel int8_t int8v;
66503831d35Sstevel int16_t int16v;
66603831d35Sstevel int32_t int32v;
66703831d35Sstevel int64_t int64v;
66803831d35Sstevel
66903831d35Sstevel err = picl_get_propinfo_by_name(modh, prop_name, &pinfo, &proph);
67003831d35Sstevel if (err != PICL_SUCCESS) {
67103831d35Sstevel *ret = err;
67203831d35Sstevel return (0);
67303831d35Sstevel }
67403831d35Sstevel
67503831d35Sstevel /*
67603831d35Sstevel * If it is not an int, uint or byte array prop, return failure
67703831d35Sstevel */
67803831d35Sstevel if ((pinfo.type != PICL_PTYPE_INT) &&
67903831d35Sstevel (pinfo.type != PICL_PTYPE_UNSIGNED_INT) &&
68003831d35Sstevel (pinfo.type != PICL_PTYPE_BYTEARRAY)) {
68103831d35Sstevel *ret = PICL_FAILURE;
68203831d35Sstevel return (0);
68303831d35Sstevel }
68403831d35Sstevel
68503831d35Sstevel switch (pinfo.size) {
68603831d35Sstevel case sizeof (int8_t):
68703831d35Sstevel err = picl_get_propval(proph, &int8v, sizeof (int8v));
68803831d35Sstevel *ret = err;
68903831d35Sstevel return (int8v);
69003831d35Sstevel case sizeof (int16_t):
69103831d35Sstevel err = picl_get_propval(proph, &int16v, sizeof (int16v));
69203831d35Sstevel *ret = err;
69303831d35Sstevel return (int16v);
69403831d35Sstevel case sizeof (int32_t):
69503831d35Sstevel err = picl_get_propval(proph, &int32v, sizeof (int32v));
69603831d35Sstevel *ret = err;
69703831d35Sstevel return (int32v);
69803831d35Sstevel case sizeof (int64_t):
69903831d35Sstevel err = picl_get_propval(proph, &int64v, sizeof (int64v));
70003831d35Sstevel *ret = err;
70103831d35Sstevel return (int64v);
70203831d35Sstevel default: /* not supported size */
70303831d35Sstevel *ret = PICL_FAILURE;
70403831d35Sstevel return (0);
70503831d35Sstevel }
70603831d35Sstevel }
707