xref: /illumos-gate/usr/src/lib/libprtdiag_psr/sparc/ontario/common/ontario.c (revision 8c067cfd3aea0c49a166f9fb38114b56a9160ac6)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * Sun4v Platform specific functions.
28  *
29  * 	called when :
30  *      machine_type ==  ontario
31  *
32  */
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"
35 
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <unistd.h>
39 #include <kstat.h>
40 #include <fcntl.h>
41 #include <string.h>
42 #include <assert.h>
43 #include <libintl.h>
44 #include <note.h>
45 #include <sys/systeminfo.h>
46 #include <sys/openpromio.h>
47 #include <sys/sysmacros.h>
48 #include <picl.h>
49 #include "picldefs.h"
50 #include <pdevinfo.h>
51 #include <display.h>
52 #include <display_sun4v.h>
53 #include <libprtdiag.h>
54 #include "ontario.h"
55 #include "erie.h"
56 #include "pelton.h"
57 #include "stpaul.h"
58 #include "huron.h"
59 
60 #if !defined(TEXT_DOMAIN)
61 #define	TEXT_DOMAIN	"SYS_TEST"
62 #endif
63 
64 /*
65  * these functions will overlay the symbol table of libprtdiag
66  * at runtime
67  */
68 void sun4v_display_pci(picl_nodehdl_t plafh);
69 void sun4v_display_diaginfo(int flag, Prom_node *root, picl_nodehdl_t plafh);
70 
71 
72 /* local functions */
73 static void sun4v_display_hw_revisions(Prom_node *root, picl_nodehdl_t plafh);
74 static int ontario_pci_callback(picl_nodehdl_t pcih, void *args);
75 static int ontario_get_first_compatible_value(picl_nodehdl_t nodeh,
76     char **outbuf);
77 static int64_t ontario_get_int_propval(picl_nodehdl_t modh, char *prop_name,
78     int *ret);
79 
80 static void
81 get_bus_type(char *path, struct io_card *card)
82 {
83 	if (strncmp(path, PCIX_SLOT0, PCIX_COMP_NUM) == 0) {
84 		(void) strcpy(card->bus_type, "PCIX");
85 	} else {
86 		(void) strcpy(card->bus_type, "PCIE");
87 	}
88 }
89 
90 static void
91 get_slot_number(picl_nodehdl_t nodeh, char *path, struct io_card *card)
92 {
93 	if (strncmp(path, PCIE_SLOT0, PCIE_COMP_NUM) == 0) {
94 		(void) strcpy(card->slot_str, "0");
95 		card->slot = 0;
96 	} else if (strncmp(path, PCIE_SLOT1, PCIE_COMP_NUM) == 0) {
97 		(void) strcpy(card->slot_str, "1");
98 		card->slot = 1;
99 	} else if (strncmp(path, PCIE_SLOT2, PCIE_COMP_NUM) == 0) {
100 		(void) strcpy(card->slot_str, "2");
101 		card->slot = 2;
102 	} else if ((strncmp(path, PCIX_SLOT1, strlen(PCIX_SLOT1)) == 0) ||
103 	    (strncmp(path, PCIX_SLOT0, strlen(PCIX_SLOT0)) == 0)) {
104 		char	ua[MAXSTRLEN];
105 		int	err;
106 
107 		(void) strcpy(card->slot_str, "PCIX");
108 		card->slot = -1;
109 
110 		/*
111 		 * PCIX_SLOT0 and PCIX_SLOT1 are actually the same path so
112 		 * use the unit address to distinguish the slot number.
113 		 */
114 		err = picl_get_propval_by_name(nodeh, PICL_PROP_UNIT_ADDRESS,
115 		    ua, sizeof (ua));
116 		if (err == PICL_SUCCESS) {
117 			if (ua[0] == '2') {
118 				card->slot = 0;
119 				(void) strcpy(card->slot_str, "0");
120 			} else if (ua[0] == '1') {
121 				card->slot = 1;
122 				(void) strcpy(card->slot_str, "1");
123 			}
124 		}
125 	} else {
126 		(void) strcpy(card->slot_str, IOBOARD);
127 		card->slot = -1;
128 	}
129 }
130 
131 static int
132 ontario_get_network_instance(char *path)
133 {
134 	if (strncmp(path, NETWORK_1_PATH, strlen(NETWORK_1_PATH)) == 0) {
135 		return (1);
136 	} else if (strncmp(path, NETWORK_3_PATH, strlen(NETWORK_3_PATH)) == 0) {
137 		return (3);
138 	} else if (strncmp(path, NETWORK_0_PATH, strlen(NETWORK_0_PATH)) == 0) {
139 		return (0);
140 	} else if (strncmp(path, NETWORK_2_PATH, strlen(NETWORK_2_PATH)) == 0) {
141 		return (2);
142 	} else {
143 		return (-1);
144 	}
145 }
146 /*
147  * add all io devices under pci in io list
148  */
149 /* ARGSUSED */
150 static int
151 ontario_pci_callback(picl_nodehdl_t pcih, void *args)
152 {
153 	int		err = PICL_SUCCESS;
154 	picl_nodehdl_t	nodeh;
155 	char		path[MAXSTRLEN];
156 	char		parent_path[MAXSTRLEN];
157 	char		piclclass[PICL_CLASSNAMELEN_MAX];
158 	char		name[MAXSTRLEN];
159 	char		model[MAXSTRLEN];
160 	char		*compatible;
161 	char		binding_name[MAXSTRLEN];
162 	struct io_card	pci_card;
163 	int32_t		instance;
164 
165 	err = picl_get_propval_by_name(pcih, PICL_PROP_DEVFS_PATH, parent_path,
166 	    sizeof (parent_path));
167 	if (err != PICL_SUCCESS) {
168 		return (err);
169 	}
170 
171 	/* Walk through the children */
172 
173 	err = picl_get_propval_by_name(pcih, PICL_PROP_CHILD, &nodeh,
174 	    sizeof (picl_nodehdl_t));
175 
176 	while (err == PICL_SUCCESS) {
177 		err = picl_get_propval_by_name(nodeh, PICL_PROP_CLASSNAME,
178 		    piclclass, sizeof (piclclass));
179 		if (err !=  PICL_SUCCESS)
180 			return (err);
181 
182 		/*
183 		 * Skip PCI and PCIEX devices because they will be processed
184 		 * later in the picl tree walk.
185 		 */
186 		if ((strcmp(piclclass, "pci") == 0) ||
187 		    (strcmp(piclclass, "pciex") == 0)) {
188 			err = picl_get_propval_by_name(nodeh, PICL_PROP_PEER,
189 			    &nodeh, sizeof (picl_nodehdl_t));
190 			continue;
191 		}
192 
193 		err = picl_get_propval_by_name(nodeh, PICL_PROP_DEVFS_PATH,
194 		    path, sizeof (path));
195 		if (err != PICL_SUCCESS) {
196 			return (err);
197 		}
198 
199 		(void) strlcpy(pci_card.notes, path, sizeof (pci_card.notes));
200 
201 		get_bus_type(parent_path, &pci_card);
202 
203 		get_slot_number(nodeh, parent_path, &pci_card);
204 
205 		err = picl_get_propval_by_name(nodeh, PICL_PROP_NAME, &name,
206 		    sizeof (name));
207 		if (err == PICL_PROPNOTFOUND)
208 			(void) strcpy(name, "");
209 		else if (err != PICL_SUCCESS)
210 			return (err);
211 
212 		/* Figure NAC name */
213 		if ((strcmp(name, NETWORK) == 0) &&
214 		    (strcmp(pci_card.slot_str, IOBOARD) == 0)) {
215 			instance = ontario_get_network_instance(path);
216 
217 			(void) snprintf(pci_card.status,
218 			    sizeof (pci_card.status), "%s/%s%d", IOBOARD,
219 			    "NET", instance);
220 		} else {
221 			if (pci_card.slot != -1) {
222 				(void) snprintf(pci_card.status,
223 				    sizeof (pci_card.status), "%s/%s%d",
224 				    IOBOARD, pci_card.bus_type, pci_card.slot);
225 			} else {
226 				(void) snprintf(pci_card.status,
227 				    sizeof (pci_card.status), "%s/%s", IOBOARD,
228 				    pci_card.bus_type);
229 			}
230 		}
231 
232 		/*
233 		 * Get the name of this card. If binding_name is found,
234 		 * name will be <nodename>-<binding_name>
235 		 */
236 
237 		err = picl_get_propval_by_name(nodeh, PICL_PROP_BINDING_NAME,
238 		    &binding_name, sizeof (binding_name));
239 		if (err == PICL_PROPNOTFOUND) {
240 			/*
241 			 * if compatible prop is found, name will be
242 			 * <nodename>-<compatible>
243 			 */
244 			err = ontario_get_first_compatible_value(nodeh,
245 			    &compatible);
246 			if (err == PICL_SUCCESS) {
247 				(void) strlcat(name, "-", MAXSTRLEN);
248 				(void) strlcat(name, compatible, MAXSTRLEN);
249 				free(compatible);
250 			} else if (err != PICL_PROPNOTFOUND) {
251 				return (err);
252 			}
253 		} else if (err != PICL_SUCCESS) {
254 			return (err);
255 		} else if (strcmp(name, binding_name) != 0) {
256 			(void) strlcat(name, "-", MAXSTRLEN);
257 			(void) strlcat(name, binding_name, MAXSTRLEN);
258 		}
259 
260 		(void) strlcpy(pci_card.name, name, sizeof (pci_card.name));
261 
262 		/* Get the model of this card */
263 
264 		err = picl_get_propval_by_name(nodeh, OBP_PROP_MODEL,
265 		    &model, sizeof (model));
266 		if (err == PICL_PROPNOTFOUND)
267 			(void) strcpy(model, "");
268 		else if (err != PICL_SUCCESS)
269 			return (err);
270 		(void) strlcpy(pci_card.model, model, sizeof (pci_card.model));
271 
272 		/* Print NAC name */
273 		log_printf("%-11s", pci_card.status);
274 		/* Print IO Type */
275 		log_printf("%6s", pci_card.bus_type);
276 		/* Print Slot # */
277 		log_printf("%5s", pci_card.slot_str);
278 		/* Print Parent Path */
279 		log_printf("%46.45s", pci_card.notes);
280 		/* Printf Card Name */
281 		if (strlen(pci_card.name) > 25)
282 			log_printf("%25.24s+", pci_card.name);
283 		else
284 			log_printf("%26s", pci_card.name);
285 		/* Print Card Model */
286 		if (strlen(pci_card.model) > 10)
287 			log_printf("%10.9s+", pci_card.model);
288 		else
289 			log_printf("%11s", pci_card.model);
290 		log_printf("\n");
291 
292 		err = picl_get_propval_by_name(nodeh, PICL_PROP_PEER, &nodeh,
293 		    sizeof (picl_nodehdl_t));
294 
295 	}
296 
297 	return (PICL_WALK_CONTINUE);
298 }
299 /*
300  * display_pci
301  * Display all the PCI IO cards on this board.
302  */
303 void
304 sun4v_display_pci(picl_nodehdl_t plafh)
305 {
306 	char    platbuf[MAXSTRLEN];
307 	char	*fmt = "%-11s %-5s %-4s %-45s %-25s %-10s";
308 	static int banner = FALSE; /* Have we printed the column headings? */
309 
310 	if (banner == FALSE) {
311 		log_printf("\n", 0);
312 		log_printf("=========================", 0);
313 		log_printf(dgettext(TEXT_DOMAIN, " IO Configuration "), 0);
314 		log_printf("=========================", 0);
315 		log_printf("\n", 0);
316 		log_printf("\n", 0);
317 		log_printf(fmt, "", "IO", "", "", "", "", 0);
318 		log_printf("\n", 0);
319 		log_printf(fmt, "Location", "Type", "Slot", "Path",
320 		    "Name", "Model", 0);
321 		log_printf("\n");
322 		log_printf(fmt, "-----------", "-----", "----",
323 		    "---------------------------------------------",
324 		    "-------------------------", "----------", 0);
325 		log_printf("\n");
326 		banner = TRUE;
327 	}
328 
329 	/* Get platform name, if that fails, use ontario name by default */
330 	if (sysinfo(SI_PLATFORM, platbuf, sizeof (platbuf)) == -1) {
331 		(void) strcpy(platbuf, ONTARIO_PLATFORM);
332 	}
333 
334 	/*
335 	 * Call functions based on appropriate platform
336 	 */
337 	if ((strncmp(platbuf, ONTARIO_PLATFORM,
338 	    strlen(ONTARIO_PLATFORM)) == 0) ||
339 	    (strncmp(platbuf, ONTARIO_PLATFORM2,
340 	    strlen(ONTARIO_PLATFORM2)) == 0)) {
341 		(void) picl_walk_tree_by_class(plafh, "pciex",
342 		    "pciex", ontario_pci_callback);
343 		(void) picl_walk_tree_by_class(plafh, "pci",
344 		    "pci", ontario_pci_callback);
345 	} else if ((strncmp(platbuf, PELTON_PLATFORM,
346 	    strlen(PELTON_PLATFORM))) == 0) {
347 		(void) picl_walk_tree_by_class(plafh, "pciex",
348 		    "pciex", pelton_pci_callback);
349 		(void) picl_walk_tree_by_class(plafh, "pci",
350 		    "pci", pelton_pci_callback);
351 	} else if ((strncmp(platbuf, STPAUL_PLATFORM,
352 	    strlen(STPAUL_PLATFORM))) == 0) {
353 		(void) picl_walk_tree_by_class(plafh, "pciex",
354 		    "pciex", stpaul_pci_callback);
355 	} else if ((strncmp(platbuf, HURON_1U_PLATFORM,
356 	    strlen(HURON_1U_PLATFORM)) == 0) || (strncmp(platbuf,
357 	    HURON_2U_PLATFORM, strlen(HURON_2U_PLATFORM)) == 0)) {
358 			(void) picl_walk_tree_by_class(plafh, "sun4v",
359 			    "niu", huron_pci_callback);
360 			(void) picl_walk_tree_by_class(plafh, "pciex",
361 			    "pciex", huron_pci_callback);
362 	} else {
363 		(void) picl_walk_tree_by_class(plafh, "pciex", "pciex",
364 		    erie_pci_callback);
365 		(void) picl_walk_tree_by_class(plafh, "pci", "pci",
366 		    erie_pci_callback);
367 	}
368 }
369 
370 /*
371  * ----------------------------------------------------------------------------
372  */
373 
374 /* ARGSUSED */
375 void
376 sun4v_display_diaginfo(int flag, Prom_node *root, picl_nodehdl_t plafh)
377 {
378 	/* NOTE(ARGUNUSED(kstats)) */
379 	/*
380 	 * Now display the last powerfail time and the fatal hardware
381 	 * reset information. We do this under a couple of conditions.
382 	 * First if the user asks for it. The second is if the user
383 	 * told us to do logging, and we found a system failure.
384 	 */
385 	if (flag) {
386 		/*
387 		 * display time of latest powerfail. Not all systems
388 		 * have this capability. For those that do not, this
389 		 * is just a no-op.
390 		 */
391 		disp_powerfail(root);
392 
393 		/* platform_disp_prom_version(tree); */
394 		sun4v_display_hw_revisions(root, plafh);
395 	}
396 }
397 
398 /*
399  * local functions
400  */
401 /*
402  * add all io devices under pci in io list
403  */
404 /* ARGSUSED */
405 static int
406 ontario_hw_rev_callback(picl_nodehdl_t pcih, void *args)
407 {
408 	int		err = PICL_SUCCESS;
409 	char		path[MAXSTRLEN] = "";
410 	char		device_path[MAXSTRLEN];
411 	char		NAC[MAXSTRLEN];
412 	char		*compatible;
413 	int32_t		revision;
414 	int		device_found;
415 
416 	device_found = 0;
417 
418 	err = picl_get_propval_by_name(pcih, PICL_PROP_DEVFS_PATH, path,
419 	    sizeof (path));
420 	if (err != PICL_SUCCESS) {
421 		return (err);
422 	}
423 
424 	if ((strcmp(path, NETWORK_0_PATH) == 0) ||
425 	    (strcmp(path, NETWORK_1_PATH) == 0)) {
426 		device_found = 1;
427 		(void) snprintf(NAC, sizeof (NAC), "%s/%s%d", IOBOARD, OPHIR,
428 		    0);
429 		revision = ontario_get_int_propval(pcih, OBP_PROP_REVISION_ID,
430 		    &err);
431 	}
432 
433 	if ((strcmp(path, NETWORK_2_PATH) == 0) ||
434 	    (strcmp(path, NETWORK_3_PATH) == 0)) {
435 		device_found = 1;
436 		(void) snprintf(NAC, sizeof (NAC), "%s/%s%d", IOBOARD, OPHIR,
437 		    1);
438 		revision = ontario_get_int_propval(pcih, OBP_PROP_REVISION_ID,
439 		    &err);
440 	}
441 
442 	if ((strcmp(path, FIRE_PATH0) == 0) ||
443 	    (strcmp(path, FIRE_PATH1) == 0)) {
444 		device_found = 1;
445 		(void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD,
446 		    "IO-BRIDGE");
447 		revision = ontario_get_int_propval(pcih, OBP_PROP_VERSION_NUM,
448 		    &err);
449 	}
450 
451 	if ((strcmp(path, PCIX_SLOT0) == 0) ||
452 	    (strcmp(path, PCIX_SLOT1) == 0)) {
453 		device_found = 1;
454 		(void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD,
455 		    PCI_BRIDGE);
456 		revision = ontario_get_int_propval(pcih, OBP_PROP_REVISION_ID,
457 		    &err);
458 	}
459 
460 	if (strcmp(path, SWITCH_A_PATH) == 0) {
461 		device_found = 1;
462 		(void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD, SWITCH_A);
463 		revision = ontario_get_int_propval(pcih, OBP_PROP_REVISION_ID,
464 		    &err);
465 	}
466 
467 	if (strcmp(path, SWITCH_B_PATH) == 0) {
468 		device_found = 1;
469 		(void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD, SWITCH_B);
470 		revision = ontario_get_int_propval(pcih, OBP_PROP_REVISION_ID,
471 		    &err);
472 	}
473 
474 	if (strcmp(path, ONT_LSI_PATH) == 0) {
475 		device_found = 1;
476 		(void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD,
477 		    SAS_SATA_HBA);
478 		revision = ontario_get_int_propval(pcih, OBP_PROP_REVISION_ID,
479 		    &err);
480 	}
481 	if (device_found == 1) {
482 		(void) strcpy(device_path, path);
483 		err = ontario_get_first_compatible_value(pcih, &compatible);
484 
485 		/* Print NAC name */
486 		log_printf("%-20s", NAC);
487 		/* Print Device Path */
488 		if (strlen(device_path) > 38)
489 			log_printf("%38.37s+", device_path);
490 		else
491 			log_printf("%39s", device_path);
492 		/* Print Compatible # */
493 		if (err == PICL_SUCCESS) {
494 			log_printf("%31s", compatible);
495 			free(compatible);
496 		} else
497 			log_printf("%31s", " ");
498 		/* Print Revision */
499 		log_printf("%6d", revision);
500 		log_printf("\n");
501 	}
502 
503 	return (PICL_WALK_CONTINUE);
504 }
505 
506 /*ARGSUSED*/
507 static void
508 sun4v_display_hw_revisions(Prom_node *root, picl_nodehdl_t plafh)
509 {
510 	Prom_node	*pnode;
511 	char		*value;
512 	char 		platbuf[MAXSTRLEN];
513 	char	*fmt = "%-20s %-45s %-30s %-9s";
514 
515 	log_printf(dgettext(TEXT_DOMAIN, "\n"
516 	    "========================= HW Revisions "
517 	    "=======================================\n\n"));
518 
519 	log_printf(dgettext(TEXT_DOMAIN,
520 	    "System PROM revisions:\n"
521 	    "----------------------\n"));
522 
523 	pnode = dev_find_node(root, "openprom");
524 	if (pnode != NULL) {
525 		value = (char *)get_prop_val(find_prop(pnode, "version"));
526 		log_printf(value);
527 	}
528 
529 	log_printf(dgettext(TEXT_DOMAIN, "\n\n"
530 	    "IO ASIC revisions:\n"
531 	    "------------------\n"));
532 	log_printf(fmt, "Location", "Path", "Device", "Revision\n", 0);
533 	log_printf(fmt, "--------------------",
534 	    "---------------------------------------------",
535 	    "------------------------------",
536 	    "---------\n", 0);
537 
538 	/* Get platform name, if that fails, use ontario name by default */
539 	if (sysinfo(SI_PLATFORM, platbuf, sizeof (platbuf)) == -1) {
540 		(void) strcpy(platbuf, ONTARIO_PLATFORM);
541 	}
542 
543 	/*
544 	 * Walk tree based on platform
545 	 */
546 	if ((strncmp(platbuf, ONTARIO_PLATFORM,
547 	    strlen(ONTARIO_PLATFORM))) == 0) {
548 		(void) picl_walk_tree_by_class(plafh, "pciex",
549 		    "pciex", ontario_hw_rev_callback);
550 		(void) picl_walk_tree_by_class(plafh, "pci",
551 		    "pci", ontario_hw_rev_callback);
552 		(void) picl_walk_tree_by_class(plafh, "network",
553 		    "network", ontario_hw_rev_callback);
554 		(void) picl_walk_tree_by_class(plafh, "scsi-2", "scsi-2",
555 		    ontario_hw_rev_callback);
556 	} else if ((strncmp(platbuf, PELTON_PLATFORM,
557 	    strlen(PELTON_PLATFORM))) == 0) {
558 		(void) picl_walk_tree_by_class(plafh, "pciex",
559 		    "pciex", pelton_hw_rev_callback);
560 		(void) picl_walk_tree_by_class(plafh, "pci",
561 		    "pci", pelton_hw_rev_callback);
562 		(void) picl_walk_tree_by_class(plafh, "network",
563 		    "network", pelton_hw_rev_callback);
564 		(void) picl_walk_tree_by_class(plafh, "scsi-2", "scsi-2",
565 		    pelton_hw_rev_callback);
566 	} else if ((strncmp(platbuf, STPAUL_PLATFORM,
567 	    strlen(STPAUL_PLATFORM))) == 0) {
568 		(void) picl_walk_tree_by_class(plafh, "pciex",
569 		    "pciex", stpaul_hw_rev_callback);
570 		(void) picl_walk_tree_by_class(plafh, "pci",
571 		    "pci", stpaul_hw_rev_callback);
572 		(void) picl_walk_tree_by_class(plafh, "network",
573 		    "network", stpaul_hw_rev_callback);
574 		(void) picl_walk_tree_by_class(plafh, "scsi-2", "scsi-2",
575 		    stpaul_hw_rev_callback);
576 	} else if ((strncmp(platbuf, HURON_1U_PLATFORM,
577 	    strlen(HURON_1U_PLATFORM)) == 0) || (strncmp(platbuf,
578 	    HURON_2U_PLATFORM, strlen(HURON_2U_PLATFORM)) == 0)) {
579 		(void) picl_walk_tree_by_class(plafh, "pciex",
580 		    "pciex", huron_hw_rev_callback);
581 		(void) picl_walk_tree_by_class(plafh, "sun4v",
582 		    "niu", huron_hw_rev_callback);
583 		(void) picl_walk_tree_by_class(plafh, "network",
584 		    "network", huron_hw_rev_callback);
585 		(void) picl_walk_tree_by_class(plafh, "scsi-2", "scsi-2",
586 		    huron_hw_rev_callback);
587 	} else {
588 		(void) picl_walk_tree_by_class(plafh, "pciex", "pciex",
589 		    erie_hw_rev_callback);
590 		(void) picl_walk_tree_by_class(plafh, "pci", "pci",
591 		    erie_hw_rev_callback);
592 		(void) picl_walk_tree_by_class(plafh, "network", "network",
593 		    erie_hw_rev_callback);
594 		(void) picl_walk_tree_by_class(plafh, "scsi-2", "scsi-2",
595 		    erie_hw_rev_callback);
596 	}
597 }
598 
599 /*
600  * return the first compatible value
601  */
602 static int
603 ontario_get_first_compatible_value(picl_nodehdl_t nodeh, char **outbuf)
604 {
605 	int		err;
606 	picl_prophdl_t	proph;
607 	picl_propinfo_t	pinfo;
608 	picl_prophdl_t	tblh;
609 	picl_prophdl_t	rowproph;
610 	char		*pval;
611 
612 	err = picl_get_propinfo_by_name(nodeh, OBP_PROP_COMPATIBLE,
613 	    &pinfo, &proph);
614 	if (err != PICL_SUCCESS)
615 		return (err);
616 
617 	if (pinfo.type == PICL_PTYPE_CHARSTRING) {
618 		pval = malloc(pinfo.size);
619 		if (pval == NULL)
620 			return (PICL_FAILURE);
621 		err = picl_get_propval(proph, pval, pinfo.size);
622 		if (err != PICL_SUCCESS) {
623 			free(pval);
624 			return (err);
625 		}
626 		*outbuf = pval;
627 		return (PICL_SUCCESS);
628 	}
629 
630 	if (pinfo.type != PICL_PTYPE_TABLE)
631 		return (PICL_FAILURE);
632 
633 	/* get first string from table */
634 	err = picl_get_propval(proph, &tblh, pinfo.size);
635 	if (err != PICL_SUCCESS)
636 		return (err);
637 
638 	err = picl_get_next_by_row(tblh, &rowproph);
639 	if (err != PICL_SUCCESS)
640 		return (err);
641 
642 	err = picl_get_propinfo(rowproph, &pinfo);
643 	if (err != PICL_SUCCESS)
644 		return (err);
645 
646 	pval = malloc(pinfo.size);
647 	if (pval == NULL)
648 		return (PICL_FAILURE);
649 
650 	err = picl_get_propval(rowproph, pval, pinfo.size);
651 	if (err != PICL_SUCCESS) {
652 		free(pval);
653 		return (err);
654 	}
655 
656 	*outbuf = pval;
657 	return (PICL_SUCCESS);
658 }
659 
660 static int64_t
661 ontario_get_int_propval(picl_nodehdl_t modh, char *prop_name, int *ret)
662 {
663 	int		err;
664 	picl_prophdl_t	proph;
665 	picl_propinfo_t	pinfo;
666 	int8_t		int8v;
667 	int16_t		int16v;
668 	int32_t		int32v;
669 	int64_t		int64v;
670 
671 	err = picl_get_propinfo_by_name(modh, prop_name, &pinfo, &proph);
672 	if (err != PICL_SUCCESS) {
673 		*ret = err;
674 		return (0);
675 	}
676 
677 	/*
678 	 * If it is not an int, uint or byte array prop, return failure
679 	 */
680 	if ((pinfo.type != PICL_PTYPE_INT) &&
681 	    (pinfo.type != PICL_PTYPE_UNSIGNED_INT) &&
682 	    (pinfo.type != PICL_PTYPE_BYTEARRAY)) {
683 		*ret = PICL_FAILURE;
684 		return (0);
685 	}
686 
687 	switch (pinfo.size) {
688 	case sizeof (int8_t):
689 		err = picl_get_propval(proph, &int8v, sizeof (int8v));
690 		*ret = err;
691 		return (int8v);
692 	case sizeof (int16_t):
693 		err = picl_get_propval(proph, &int16v, sizeof (int16v));
694 		*ret = err;
695 		return (int16v);
696 	case sizeof (int32_t):
697 		err = picl_get_propval(proph, &int32v, sizeof (int32v));
698 		*ret = err;
699 		return (int32v);
700 	case sizeof (int64_t):
701 		err = picl_get_propval(proph, &int64v, sizeof (int64v));
702 		*ret = err;
703 		return (int64v);
704 	default:	/* not supported size */
705 		*ret = PICL_FAILURE;
706 		return (0);
707 	}
708 }
709