xref: /illumos-gate/usr/src/lib/libprtdiag_psr/sparc/ontario/common/ontario.c (revision 8521e5e6630b57b9883c3979cd5589e53f09e044)
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 2007 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 	} else if ((strncmp(platbuf, STPAUL_PLATFORM,
350 		strlen(STPAUL_PLATFORM))) == 0) {
351 		(void) picl_walk_tree_by_class(plafh, "pciex",
352 		    "pciex", stpaul_pci_callback);
353 	} else if ((strncmp(platbuf, HURON_1U_PLATFORM,
354 		strlen(HURON_1U_PLATFORM)) == 0) || (strncmp(platbuf,
355 		HURON_2U_PLATFORM, strlen(HURON_2U_PLATFORM)) == 0)) {
356 			(void) picl_walk_tree_by_class(plafh, "sun4v",
357 				"niu", huron_pci_callback);
358 			(void) picl_walk_tree_by_class(plafh, "pciex",
359 				"pciex", huron_pci_callback);
360 	} else {
361 		(void) picl_walk_tree_by_class(plafh, "pciex", "pciex",
362 		    erie_pci_callback);
363 		(void) picl_walk_tree_by_class(plafh, "pci", "pci",
364 		    erie_pci_callback);
365 	}
366 }
367 
368 /*
369  * ----------------------------------------------------------------------------
370  */
371 
372 /* ARGSUSED */
373 void
374 sun4v_display_diaginfo(int flag, Prom_node *root, picl_nodehdl_t plafh)
375 {
376 	/* NOTE(ARGUNUSED(kstats)) */
377 	/*
378 	 * Now display the last powerfail time and the fatal hardware
379 	 * reset information. We do this under a couple of conditions.
380 	 * First if the user asks for it. The second is if the user
381 	 * told us to do logging, and we found a system failure.
382 	 */
383 	if (flag) {
384 		/*
385 		 * display time of latest powerfail. Not all systems
386 		 * have this capability. For those that do not, this
387 		 * is just a no-op.
388 		 */
389 		disp_powerfail(root);
390 
391 		/* platform_disp_prom_version(tree); */
392 		sun4v_display_hw_revisions(root, plafh);
393 	}
394 }
395 
396 /*
397  * local functions
398  */
399 /*
400  * add all io devices under pci in io list
401  */
402 /* ARGSUSED */
403 static int
404 ontario_hw_rev_callback(picl_nodehdl_t pcih, void *args)
405 {
406 	int		err = PICL_SUCCESS;
407 	char		path[MAXSTRLEN] = "";
408 	char		device_path[MAXSTRLEN];
409 	char		NAC[MAXSTRLEN];
410 	char		*compatible;
411 	int32_t		revision;
412 	int		device_found;
413 
414 	device_found = 0;
415 
416 	err = picl_get_propval_by_name(pcih, PICL_PROP_DEVFS_PATH, path,
417 	    sizeof (path));
418 	if (err != PICL_SUCCESS) {
419 		return (err);
420 	}
421 
422 	if ((strcmp(path, NETWORK_0_PATH) == 0) ||
423 	    (strcmp(path, NETWORK_1_PATH) == 0)) {
424 		device_found = 1;
425 		(void) snprintf(NAC, sizeof (NAC), "%s/%s%d", IOBOARD, OPHIR,
426 		    0);
427 		revision = ontario_get_int_propval(pcih, OBP_PROP_REVISION_ID,
428 		    &err);
429 	}
430 
431 	if ((strcmp(path, NETWORK_2_PATH) == 0) ||
432 	    (strcmp(path, NETWORK_3_PATH) == 0)) {
433 		device_found = 1;
434 		(void) snprintf(NAC, sizeof (NAC), "%s/%s%d", IOBOARD, OPHIR,
435 		    1);
436 		revision = ontario_get_int_propval(pcih, OBP_PROP_REVISION_ID,
437 		    &err);
438 	}
439 
440 	if ((strcmp(path, FIRE_PATH0) == 0) ||
441 	    (strcmp(path, FIRE_PATH1) == 0)) {
442 		device_found = 1;
443 		(void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD,
444 		    "IO-BRIDGE");
445 		revision = ontario_get_int_propval(pcih, OBP_PROP_VERSION_NUM,
446 		    &err);
447 	}
448 
449 	if ((strcmp(path, PCIX_SLOT0) == 0) ||
450 	    (strcmp(path, PCIX_SLOT1) == 0)) {
451 		device_found = 1;
452 		(void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD,
453 		    PCI_BRIDGE);
454 		revision = ontario_get_int_propval(pcih, OBP_PROP_REVISION_ID,
455 		    &err);
456 	}
457 
458 	if (strcmp(path, SWITCH_A_PATH) == 0) {
459 		device_found = 1;
460 		(void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD, SWITCH_A);
461 		revision = ontario_get_int_propval(pcih, OBP_PROP_REVISION_ID,
462 		    &err);
463 	}
464 
465 	if (strcmp(path, SWITCH_B_PATH) == 0) {
466 		device_found = 1;
467 		(void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD, SWITCH_B);
468 		revision = ontario_get_int_propval(pcih, OBP_PROP_REVISION_ID,
469 		    &err);
470 	}
471 
472 	if (strcmp(path, ONT_LSI_PATH) == 0) {
473 		device_found = 1;
474 		(void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD,
475 		    SAS_SATA_HBA);
476 		revision = ontario_get_int_propval(pcih, OBP_PROP_REVISION_ID,
477 		    &err);
478 	}
479 	if (device_found == 1) {
480 		(void) strcpy(device_path, path);
481 		err = ontario_get_first_compatible_value(pcih, &compatible);
482 
483 		/* Print NAC name */
484 		log_printf("%-20s", NAC);
485 		/* Print Device Path */
486 		if (strlen(device_path) > 38)
487 			log_printf("%38.37s+", device_path);
488 		else
489 			log_printf("%39s", device_path);
490 		/* Print Compatible # */
491 		log_printf("%31s", compatible);
492 		free(compatible);
493 		/* Print Revision */
494 		log_printf("%6d", revision);
495 		log_printf("\n");
496 	}
497 
498 	return (PICL_WALK_CONTINUE);
499 }
500 
501 /*ARGSUSED*/
502 static void
503 sun4v_display_hw_revisions(Prom_node *root, picl_nodehdl_t plafh)
504 {
505 	Prom_node	*pnode;
506 	char		*value;
507 	char 		platbuf[MAXSTRLEN];
508 	char	*fmt = "%-20s %-45s %-30s %-9s";
509 
510 	log_printf(dgettext(TEXT_DOMAIN, "\n"
511 		"========================= HW Revisions "
512 		"=======================================\n\n"));
513 
514 	log_printf(dgettext(TEXT_DOMAIN,
515 		"System PROM revisions:\n"
516 		"----------------------\n"));
517 
518 	pnode = dev_find_node(root, "openprom");
519 	if (pnode != NULL) {
520 	    value = (char *)get_prop_val(find_prop(pnode, "version"));
521 	    log_printf(value);
522 	}
523 
524 	log_printf(dgettext(TEXT_DOMAIN, "\n\n"
525 		"IO ASIC revisions:\n"
526 			    "------------------\n"));
527 	log_printf(fmt, "Location", "Path", "Device", "Revision\n", 0);
528 	log_printf(fmt, "--------------------",
529 	    "---------------------------------------------",
530 	    "------------------------------",
531 	    "---------\n", 0);
532 
533 	/* Get platform name, if that fails, use ontario name by default */
534 	if (sysinfo(SI_PLATFORM, platbuf, sizeof (platbuf)) == -1) {
535 		(void) strcpy(platbuf, ONTARIO_PLATFORM);
536 	}
537 
538 	/*
539 	 * Walk tree based on platform
540 	 */
541 	if ((strncmp(platbuf, ONTARIO_PLATFORM,
542 	    strlen(ONTARIO_PLATFORM))) == 0) {
543 		(void) picl_walk_tree_by_class(plafh, "pciex",
544 		    "pciex", ontario_hw_rev_callback);
545 		(void) picl_walk_tree_by_class(plafh, "pci",
546 		    "pci", ontario_hw_rev_callback);
547 		(void) picl_walk_tree_by_class(plafh, "network",
548 		    "network", ontario_hw_rev_callback);
549 		(void) picl_walk_tree_by_class(plafh, "scsi-2", "scsi-2",
550 		    ontario_hw_rev_callback);
551 	} else if ((strncmp(platbuf, PELTON_PLATFORM,
552 	    strlen(PELTON_PLATFORM))) == 0) {
553 		(void) picl_walk_tree_by_class(plafh, "pciex",
554 		    "pciex", pelton_hw_rev_callback);
555 		(void) picl_walk_tree_by_class(plafh, "pci",
556 		    "pci", pelton_hw_rev_callback);
557 		(void) picl_walk_tree_by_class(plafh, "network",
558 		    "network", pelton_hw_rev_callback);
559 		(void) picl_walk_tree_by_class(plafh, "scsi-2", "scsi-2",
560 		    pelton_hw_rev_callback);
561 	} else if ((strncmp(platbuf, STPAUL_PLATFORM,
562 	    strlen(STPAUL_PLATFORM))) == 0) {
563 		(void) picl_walk_tree_by_class(plafh, "pciex",
564 		    "pciex", stpaul_hw_rev_callback);
565 		(void) picl_walk_tree_by_class(plafh, "pci",
566 		    "pci", stpaul_hw_rev_callback);
567 		(void) picl_walk_tree_by_class(plafh, "network",
568 		    "network", stpaul_hw_rev_callback);
569 		(void) picl_walk_tree_by_class(plafh, "scsi-2", "scsi-2",
570 		    stpaul_hw_rev_callback);
571 	} else if ((strncmp(platbuf, HURON_1U_PLATFORM,
572 		strlen(HURON_1U_PLATFORM)) == 0) || (strncmp(platbuf,
573 		HURON_2U_PLATFORM, strlen(HURON_2U_PLATFORM)) == 0)) {
574 		(void) picl_walk_tree_by_class(plafh, "pciex",
575 			"pciex", huron_hw_rev_callback);
576 		(void) picl_walk_tree_by_class(plafh, "sun4v",
577 			"niu", huron_hw_rev_callback);
578 		(void) picl_walk_tree_by_class(plafh, "network",
579 			"network", huron_hw_rev_callback);
580 		(void) picl_walk_tree_by_class(plafh, "scsi-2", "scsi-2",
581 			huron_hw_rev_callback);
582 	} else {
583 		(void) picl_walk_tree_by_class(plafh, "pciex", "pciex",
584 		    erie_hw_rev_callback);
585 		(void) picl_walk_tree_by_class(plafh, "pci", "pci",
586 		    erie_hw_rev_callback);
587 		(void) picl_walk_tree_by_class(plafh, "network", "network",
588 		    erie_hw_rev_callback);
589 		(void) picl_walk_tree_by_class(plafh, "scsi-2", "scsi-2",
590 		    erie_hw_rev_callback);
591 	}
592 }
593 
594 /*
595  * return the first compatible value
596  */
597 static int
598 ontario_get_first_compatible_value(picl_nodehdl_t nodeh, char **outbuf)
599 {
600 	int		err;
601 	picl_prophdl_t	proph;
602 	picl_propinfo_t	pinfo;
603 	picl_prophdl_t	tblh;
604 	picl_prophdl_t	rowproph;
605 	char		*pval;
606 
607 	err = picl_get_propinfo_by_name(nodeh, OBP_PROP_COMPATIBLE,
608 	    &pinfo, &proph);
609 	if (err != PICL_SUCCESS)
610 	    return (err);
611 
612 	if (pinfo.type == PICL_PTYPE_CHARSTRING) {
613 		pval = malloc(pinfo.size);
614 		if (pval == NULL)
615 			return (PICL_FAILURE);
616 		err = picl_get_propval(proph, pval, pinfo.size);
617 		if (err != PICL_SUCCESS) {
618 			free(pval);
619 			return (err);
620 		}
621 		*outbuf = pval;
622 		return (PICL_SUCCESS);
623 	}
624 
625 	if (pinfo.type != PICL_PTYPE_TABLE)
626 		return (PICL_FAILURE);
627 
628 	/* get first string from table */
629 	err = picl_get_propval(proph, &tblh, pinfo.size);
630 	if (err != PICL_SUCCESS)
631 		return (err);
632 
633 	err = picl_get_next_by_row(tblh, &rowproph);
634 	if (err != PICL_SUCCESS)
635 		return (err);
636 
637 	err = picl_get_propinfo(rowproph, &pinfo);
638 	if (err != PICL_SUCCESS)
639 	    return (err);
640 
641 	pval = malloc(pinfo.size);
642 	if (pval == NULL)
643 		return (PICL_FAILURE);
644 
645 	err = picl_get_propval(rowproph, pval, pinfo.size);
646 	if (err != PICL_SUCCESS) {
647 		free(pval);
648 		return (err);
649 	}
650 
651 	*outbuf = pval;
652 	return (PICL_SUCCESS);
653 }
654 
655 static int64_t
656 ontario_get_int_propval(picl_nodehdl_t modh, char *prop_name, int *ret)
657 {
658 	int		err;
659 	picl_prophdl_t	proph;
660 	picl_propinfo_t	pinfo;
661 	int8_t		int8v;
662 	int16_t		int16v;
663 	int32_t		int32v;
664 	int64_t		int64v;
665 
666 	err = picl_get_propinfo_by_name(modh, prop_name, &pinfo, &proph);
667 	if (err != PICL_SUCCESS) {
668 		*ret = err;
669 		return (0);
670 	}
671 
672 	/*
673 	 * If it is not an int, uint or byte array prop, return failure
674 	 */
675 	if ((pinfo.type != PICL_PTYPE_INT) &&
676 		(pinfo.type != PICL_PTYPE_UNSIGNED_INT) &&
677 		(pinfo.type != PICL_PTYPE_BYTEARRAY)) {
678 		*ret = PICL_FAILURE;
679 		return (0);
680 	}
681 
682 	switch (pinfo.size) {
683 	case sizeof (int8_t):
684 		err = picl_get_propval(proph, &int8v, sizeof (int8v));
685 		*ret = err;
686 		return (int8v);
687 	case sizeof (int16_t):
688 		err = picl_get_propval(proph, &int16v, sizeof (int16v));
689 		*ret = err;
690 		return (int16v);
691 	case sizeof (int32_t):
692 		err = picl_get_propval(proph, &int32v, sizeof (int32v));
693 		*ret = err;
694 		return (int32v);
695 	case sizeof (int64_t):
696 		err = picl_get_propval(proph, &int64v, sizeof (int64v));
697 		*ret = err;
698 		return (int64v);
699 	default:	/* not supported size */
700 		*ret = PICL_FAILURE;
701 		return (0);
702 	}
703 }
704