1*51b564acSmcwalter /*
2*51b564acSmcwalter  * CDDL HEADER START
3*51b564acSmcwalter  *
4*51b564acSmcwalter  * The contents of this file are subject to the terms of the
5*51b564acSmcwalter  * Common Development and Distribution License (the "License").
6*51b564acSmcwalter  * You may not use this file except in compliance with the License.
7*51b564acSmcwalter  *
8*51b564acSmcwalter  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*51b564acSmcwalter  * or http://www.opensolaris.org/os/licensing.
10*51b564acSmcwalter  * See the License for the specific language governing permissions
11*51b564acSmcwalter  * and limitations under the License.
12*51b564acSmcwalter  *
13*51b564acSmcwalter  * When distributing Covered Code, include this CDDL HEADER in each
14*51b564acSmcwalter  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*51b564acSmcwalter  * If applicable, add the following below this CDDL HEADER, with the
16*51b564acSmcwalter  * fields enclosed by brackets "[]" replaced with your own identifying
17*51b564acSmcwalter  * information: Portions Copyright [yyyy] [name of copyright owner]
18*51b564acSmcwalter  *
19*51b564acSmcwalter  * CDDL HEADER END
20*51b564acSmcwalter  */
21*51b564acSmcwalter /*
22*51b564acSmcwalter  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23*51b564acSmcwalter  * Use is subject to license terms.
24*51b564acSmcwalter  */
25*51b564acSmcwalter 
26*51b564acSmcwalter /*
27*51b564acSmcwalter  * Sun4v Platform specific functions.
28*51b564acSmcwalter  *
29*51b564acSmcwalter  * 	called when :
30*51b564acSmcwalter  *      machine_type ==  monza
31*51b564acSmcwalter  *
32*51b564acSmcwalter  */
33*51b564acSmcwalter 
34*51b564acSmcwalter #include <stdio.h>
35*51b564acSmcwalter #include <stdlib.h>
36*51b564acSmcwalter #include <unistd.h>
37*51b564acSmcwalter #include <kstat.h>
38*51b564acSmcwalter #include <fcntl.h>
39*51b564acSmcwalter #include <string.h>
40*51b564acSmcwalter #include <assert.h>
41*51b564acSmcwalter #include <libintl.h>
42*51b564acSmcwalter #include <note.h>
43*51b564acSmcwalter #include <sys/systeminfo.h>
44*51b564acSmcwalter #include <sys/openpromio.h>
45*51b564acSmcwalter #include <sys/sysmacros.h>
46*51b564acSmcwalter #include <picl.h>
47*51b564acSmcwalter #include "picldefs.h"
48*51b564acSmcwalter #include <pdevinfo.h>
49*51b564acSmcwalter #include <display.h>
50*51b564acSmcwalter #include <display_sun4v.h>
51*51b564acSmcwalter #include <libprtdiag.h>
52*51b564acSmcwalter #include "monza.h"
53*51b564acSmcwalter 
54*51b564acSmcwalter #if !defined(TEXT_DOMAIN)
55*51b564acSmcwalter #define	TEXT_DOMAIN	"SYS_TEST"
56*51b564acSmcwalter #endif
57*51b564acSmcwalter 
58*51b564acSmcwalter /*
59*51b564acSmcwalter  * These functions will overlay the symbol table of libprtdiag
60*51b564acSmcwalter  * at runtime
61*51b564acSmcwalter  */
62*51b564acSmcwalter void sun4v_display_pci(picl_nodehdl_t plafh);
63*51b564acSmcwalter void sun4v_display_diaginfo(int flag, Prom_node *root, picl_nodehdl_t plafh);
64*51b564acSmcwalter 
65*51b564acSmcwalter 
66*51b564acSmcwalter /*
67*51b564acSmcwalter  * local functions
68*51b564acSmcwalter  */
69*51b564acSmcwalter static void sun4v_display_hw_revisions(Prom_node *root, picl_nodehdl_t plafh);
70*51b564acSmcwalter static int monza_pci_callback(picl_nodehdl_t pcih, void *args);
71*51b564acSmcwalter static int monza_get_first_compatible_value(picl_nodehdl_t nodeh,
72*51b564acSmcwalter     char **outbuf);
73*51b564acSmcwalter static int64_t monza_get_int_propval(picl_nodehdl_t modh, char *prop_name,
74*51b564acSmcwalter     int *ret);
75*51b564acSmcwalter 
76*51b564acSmcwalter static void
monza_get_bus_type(char * path,struct io_card * card)77*51b564acSmcwalter monza_get_bus_type(char *path, struct io_card *card)
78*51b564acSmcwalter {
79*51b564acSmcwalter 	if (strcmp(path, MONZA_NIU) == 0) {
80*51b564acSmcwalter 		(void) strcpy(card->bus_type, "NIU");
81*51b564acSmcwalter 	} else {
82*51b564acSmcwalter 		(void) strcpy(card->bus_type, "PCIE");
83*51b564acSmcwalter 	}
84*51b564acSmcwalter }
85*51b564acSmcwalter 
86*51b564acSmcwalter static void
monza_get_slot_number(char * path,struct io_card * card)87*51b564acSmcwalter monza_get_slot_number(char *path, struct io_card *card)
88*51b564acSmcwalter {
89*51b564acSmcwalter 	if (strcmp(path, MONZA_N2_XAUI0) == 0) {
90*51b564acSmcwalter 		(void) strcpy(card->slot_str, "0");
91*51b564acSmcwalter 		card->slot = 0;
92*51b564acSmcwalter 	} else if (strcmp(path, MONZA_N2_XAUI1) == 0) {
93*51b564acSmcwalter 		(void) strcpy(card->slot_str, "1");
94*51b564acSmcwalter 		card->slot = 1;
95*51b564acSmcwalter 	} else {
96*51b564acSmcwalter 		(void) strcpy(card->slot_str, MOTHERBOARD);
97*51b564acSmcwalter 		card->slot = -1;
98*51b564acSmcwalter 	}
99*51b564acSmcwalter }
100*51b564acSmcwalter 
101*51b564acSmcwalter static int
monza_get_network_instance(char * path)102*51b564acSmcwalter monza_get_network_instance(char *path)
103*51b564acSmcwalter {
104*51b564acSmcwalter 
105*51b564acSmcwalter 	if (strncmp(path, MONZA_NETWORK_0, strlen(MONZA_NETWORK_0)) == 0) {
106*51b564acSmcwalter 		return (0);
107*51b564acSmcwalter 	} else if (strncmp(path, MONZA_NETWORK_1, strlen(MONZA_NETWORK_1))
108*51b564acSmcwalter 	    == 0) {
109*51b564acSmcwalter 		return (1);
110*51b564acSmcwalter 	} else if (strncmp(path, MONZA_NETWORK_2, strlen(MONZA_NETWORK_2))
111*51b564acSmcwalter 	    == 0) {
112*51b564acSmcwalter 		return (2);
113*51b564acSmcwalter 	} else if (strncmp(path, MONZA_ENET_2, strlen(MONZA_ENET_2))
114*51b564acSmcwalter 	    == 0) {
115*51b564acSmcwalter 		return (2);
116*51b564acSmcwalter 	} else if (strncmp(path, MONZA_NETWORK_3, strlen(MONZA_NETWORK_3))
117*51b564acSmcwalter 	    == 0) {
118*51b564acSmcwalter 		return (3);
119*51b564acSmcwalter 	} else if (strncmp(path, MONZA_ENET_3, strlen(MONZA_ENET_3))
120*51b564acSmcwalter 	    == 0) {
121*51b564acSmcwalter 		return (3);
122*51b564acSmcwalter 	} else if (strncmp(path, MONZA_NETWORK_4, strlen(MONZA_NETWORK_4))
123*51b564acSmcwalter 	    == 0) {
124*51b564acSmcwalter 		return (4);
125*51b564acSmcwalter 	} else if (strncmp(path, MONZA_NETWORK_5, strlen(MONZA_NETWORK_5))
126*51b564acSmcwalter 	    == 0) {
127*51b564acSmcwalter 		return (5);
128*51b564acSmcwalter 	} else if (strncmp(path, MONZA_N2_XAUI0, strlen(MONZA_N2_XAUI0))
129*51b564acSmcwalter 	    == 0) {
130*51b564acSmcwalter 		return (0);
131*51b564acSmcwalter 	} else if (strncmp(path, MONZA_N2_XAUI1, strlen(MONZA_N2_XAUI1))
132*51b564acSmcwalter 	    == 0) {
133*51b564acSmcwalter 		return (1);
134*51b564acSmcwalter 	} else {
135*51b564acSmcwalter 		return (-1);
136*51b564acSmcwalter 	}
137*51b564acSmcwalter }
138*51b564acSmcwalter 
139*51b564acSmcwalter /*
140*51b564acSmcwalter  * add all io devices under pci in io list
141*51b564acSmcwalter  */
142*51b564acSmcwalter /* ARGSUSED */
143*51b564acSmcwalter static int
monza_pci_callback(picl_nodehdl_t pcih,void * args)144*51b564acSmcwalter monza_pci_callback(picl_nodehdl_t pcih, void *args)
145*51b564acSmcwalter {
146*51b564acSmcwalter 	int		err = PICL_SUCCESS;
147*51b564acSmcwalter 	picl_nodehdl_t	nodeh;
148*51b564acSmcwalter 	char		path[MAXSTRLEN];
149*51b564acSmcwalter 	char		parent_path[MAXSTRLEN];
150*51b564acSmcwalter 	char		piclclass[PICL_CLASSNAMELEN_MAX];
151*51b564acSmcwalter 	char		name[MAXSTRLEN];
152*51b564acSmcwalter 	char		model[MAXSTRLEN];
153*51b564acSmcwalter 	char		*compatible;
154*51b564acSmcwalter 	char		binding_name[MAXSTRLEN];
155*51b564acSmcwalter 	struct io_card	pci_card;
156*51b564acSmcwalter 	int32_t		instance;
157*51b564acSmcwalter 
158*51b564acSmcwalter 	err = picl_get_propval_by_name(pcih, PICL_PROP_DEVFS_PATH, parent_path,
159*51b564acSmcwalter 	    sizeof (parent_path));
160*51b564acSmcwalter 	if (err != PICL_SUCCESS) {
161*51b564acSmcwalter 		return (err);
162*51b564acSmcwalter 	}
163*51b564acSmcwalter 
164*51b564acSmcwalter 	/*
165*51b564acSmcwalter 	 * Walk through the children
166*51b564acSmcwalter 	 */
167*51b564acSmcwalter 	err = picl_get_propval_by_name(pcih, PICL_PROP_CHILD, &nodeh,
168*51b564acSmcwalter 	    sizeof (picl_nodehdl_t));
169*51b564acSmcwalter 
170*51b564acSmcwalter 	while (err == PICL_SUCCESS) {
171*51b564acSmcwalter 		err = picl_get_propval_by_name(nodeh, PICL_PROP_CLASSNAME,
172*51b564acSmcwalter 		    piclclass, sizeof (piclclass));
173*51b564acSmcwalter 		if (err !=  PICL_SUCCESS)
174*51b564acSmcwalter 			return (err);
175*51b564acSmcwalter 
176*51b564acSmcwalter 		/*
177*51b564acSmcwalter 		 * Skip PCI and PCIEX devices because they will be processed
178*51b564acSmcwalter 		 * later in the picl tree walk.
179*51b564acSmcwalter 		 */
180*51b564acSmcwalter 		if ((strcmp(piclclass, PCIEX) == 0) ||
181*51b564acSmcwalter 		    (strcmp(piclclass, PCI) == 0)) {
182*51b564acSmcwalter 			err = picl_get_propval_by_name(nodeh, PICL_PROP_PEER,
183*51b564acSmcwalter 			    &nodeh, sizeof (picl_nodehdl_t));
184*51b564acSmcwalter 			continue;
185*51b564acSmcwalter 		}
186*51b564acSmcwalter 
187*51b564acSmcwalter 		err = picl_get_propval_by_name(nodeh, PICL_PROP_DEVFS_PATH,
188*51b564acSmcwalter 		    path, sizeof (path));
189*51b564acSmcwalter 		if (err != PICL_SUCCESS) {
190*51b564acSmcwalter 			return (err);
191*51b564acSmcwalter 		}
192*51b564acSmcwalter 
193*51b564acSmcwalter 		(void) strlcpy(pci_card.notes, path, sizeof (pci_card.notes));
194*51b564acSmcwalter 
195*51b564acSmcwalter 		monza_get_bus_type(parent_path, &pci_card);
196*51b564acSmcwalter 
197*51b564acSmcwalter 		err = picl_get_propval_by_name(nodeh, PICL_PROP_NAME, &name,
198*51b564acSmcwalter 		    sizeof (name));
199*51b564acSmcwalter 		if (err == PICL_PROPNOTFOUND)
200*51b564acSmcwalter 			(void) strcpy(name, "");
201*51b564acSmcwalter 		else if (err != PICL_SUCCESS)
202*51b564acSmcwalter 			return (err);
203*51b564acSmcwalter 
204*51b564acSmcwalter 		if (strcmp(parent_path, MONZA_NIU) == 0)
205*51b564acSmcwalter 			monza_get_slot_number(path, &pci_card);
206*51b564acSmcwalter 		else
207*51b564acSmcwalter 			monza_get_slot_number(parent_path, &pci_card);
208*51b564acSmcwalter 
209*51b564acSmcwalter 		err = picl_get_propval_by_name(nodeh, PICL_PROP_NAME, &name,
210*51b564acSmcwalter 		    sizeof (name));
211*51b564acSmcwalter 		if (err == PICL_PROPNOTFOUND)
212*51b564acSmcwalter 			(void) strcpy(name, "");
213*51b564acSmcwalter 		else if (err != PICL_SUCCESS)
214*51b564acSmcwalter 			return (err);
215*51b564acSmcwalter 
216*51b564acSmcwalter 		/* Figure NAC name */
217*51b564acSmcwalter 		if ((strcmp(name, NETWORK) == 0 ||
218*51b564acSmcwalter 		    strcmp(name, ETHERNET) == 0) &&
219*51b564acSmcwalter 		    (strcmp(pci_card.slot_str, MOTHERBOARD) == 0)) {
220*51b564acSmcwalter 			instance = monza_get_network_instance(path);
221*51b564acSmcwalter 
222*51b564acSmcwalter 			(void) snprintf(pci_card.status,
223*51b564acSmcwalter 			    sizeof (pci_card.status), "%s/%s%d", MOTHERBOARD,
224*51b564acSmcwalter 			    "NET", instance);
225*51b564acSmcwalter 		} else {
226*51b564acSmcwalter 			if (pci_card.slot != -1) {
227*51b564acSmcwalter 				(void) snprintf(pci_card.status,
228*51b564acSmcwalter 				    sizeof (pci_card.status), "%s/%s%d",
229*51b564acSmcwalter 				    IOBOARD, pci_card.bus_type, pci_card.slot);
230*51b564acSmcwalter 			} else {
231*51b564acSmcwalter 				(void) snprintf(pci_card.status,
232*51b564acSmcwalter 				    sizeof (pci_card.status),
233*51b564acSmcwalter 				"%s/%s", MOTHERBOARD, pci_card.bus_type);
234*51b564acSmcwalter 			}
235*51b564acSmcwalter 		}
236*51b564acSmcwalter 
237*51b564acSmcwalter 		/*
238*51b564acSmcwalter 		 * Get the name of this card. If binding_name is found,
239*51b564acSmcwalter 		 * name will be <nodename>-<binding_name>
240*51b564acSmcwalter 		 */
241*51b564acSmcwalter 
242*51b564acSmcwalter 		err = picl_get_propval_by_name(nodeh, PICL_PROP_BINDING_NAME,
243*51b564acSmcwalter 		    &binding_name, sizeof (binding_name));
244*51b564acSmcwalter 		if (err == PICL_PROPNOTFOUND) {
245*51b564acSmcwalter 			/*
246*51b564acSmcwalter 			 * if compatible prop is found, name will be
247*51b564acSmcwalter 			 * <nodename>-<compatible>
248*51b564acSmcwalter 			 */
249*51b564acSmcwalter 			err = monza_get_first_compatible_value(nodeh,
250*51b564acSmcwalter 			    &compatible);
251*51b564acSmcwalter 			if (err == PICL_SUCCESS) {
252*51b564acSmcwalter 				(void) strlcat(name, "-", MAXSTRLEN);
253*51b564acSmcwalter 				(void) strlcat(name, compatible, MAXSTRLEN);
254*51b564acSmcwalter 				free(compatible);
255*51b564acSmcwalter 			} else if (err != PICL_PROPNOTFOUND) {
256*51b564acSmcwalter 				return (err);
257*51b564acSmcwalter 			}
258*51b564acSmcwalter 		} else if (err != PICL_SUCCESS) {
259*51b564acSmcwalter 			return (err);
260*51b564acSmcwalter 		} else if (strcmp(name, binding_name) != 0) {
261*51b564acSmcwalter 			(void) strlcat(name, "-", MAXSTRLEN);
262*51b564acSmcwalter 			(void) strlcat(name, binding_name, MAXSTRLEN);
263*51b564acSmcwalter 		}
264*51b564acSmcwalter 
265*51b564acSmcwalter 		(void) strlcpy(pci_card.name, name, sizeof (pci_card.name));
266*51b564acSmcwalter 
267*51b564acSmcwalter 		/* Get the model of this card */
268*51b564acSmcwalter 
269*51b564acSmcwalter 		err = picl_get_propval_by_name(nodeh, OBP_PROP_MODEL,
270*51b564acSmcwalter 		    &model, sizeof (model));
271*51b564acSmcwalter 		if (err == PICL_PROPNOTFOUND)
272*51b564acSmcwalter 			(void) strcpy(model, "");
273*51b564acSmcwalter 		else if (err != PICL_SUCCESS)
274*51b564acSmcwalter 			return (err);
275*51b564acSmcwalter 		(void) strlcpy(pci_card.model, model, sizeof (pci_card.model));
276*51b564acSmcwalter 
277*51b564acSmcwalter 		/* Print NAC name */
278*51b564acSmcwalter 		log_printf("%-11s", pci_card.status);
279*51b564acSmcwalter 		/* Print IO Type */
280*51b564acSmcwalter 		log_printf("%6s", pci_card.bus_type);
281*51b564acSmcwalter 		/* Print Slot # */
282*51b564acSmcwalter 		log_printf("%5s", pci_card.slot_str);
283*51b564acSmcwalter 		/* Print Parent Path */
284*51b564acSmcwalter 		log_printf("%46.45s", pci_card.notes);
285*51b564acSmcwalter 		/* Printf Card Name */
286*51b564acSmcwalter 		if (strlen(pci_card.name) > 24)
287*51b564acSmcwalter 			log_printf("%25.24s+", pci_card.name);
288*51b564acSmcwalter 		else
289*51b564acSmcwalter 			log_printf("%26s", pci_card.name);
290*51b564acSmcwalter 		/* Print Card Model */
291*51b564acSmcwalter 		if (strlen(pci_card.model) > 10)
292*51b564acSmcwalter 			log_printf("%10.9s+", pci_card.model);
293*51b564acSmcwalter 		else
294*51b564acSmcwalter 			log_printf("%10s", pci_card.model);
295*51b564acSmcwalter 		log_printf("\n");
296*51b564acSmcwalter 
297*51b564acSmcwalter 		err = picl_get_propval_by_name(nodeh, PICL_PROP_PEER, &nodeh,
298*51b564acSmcwalter 		    sizeof (picl_nodehdl_t));
299*51b564acSmcwalter 
300*51b564acSmcwalter 	}
301*51b564acSmcwalter 
302*51b564acSmcwalter 	return (PICL_WALK_CONTINUE);
303*51b564acSmcwalter }
304*51b564acSmcwalter 
305*51b564acSmcwalter /*
306*51b564acSmcwalter  * display_pci
307*51b564acSmcwalter  * Display all the PCI IO cards on this board.
308*51b564acSmcwalter  */
309*51b564acSmcwalter void
sun4v_display_pci(picl_nodehdl_t plafh)310*51b564acSmcwalter sun4v_display_pci(picl_nodehdl_t plafh)
311*51b564acSmcwalter {
312*51b564acSmcwalter 	char    platbuf[MAXSTRLEN];
313*51b564acSmcwalter 	char	*fmt = "%-11s %-7s %-4s %-46s %-25s %-8s";
314*51b564acSmcwalter 	static int banner = FALSE; /* Have we printed the column headings? */
315*51b564acSmcwalter 
316*51b564acSmcwalter 	if (banner == FALSE) {
317*51b564acSmcwalter 		log_printf("\n", 0);
318*51b564acSmcwalter 		log_printf("=========================", 0);
319*51b564acSmcwalter 		log_printf(dgettext(TEXT_DOMAIN, " IO Configuration "), 0);
320*51b564acSmcwalter 		log_printf("=========================", 0);
321*51b564acSmcwalter 		log_printf("\n", 0);
322*51b564acSmcwalter 		log_printf("\n", 0);
323*51b564acSmcwalter 		log_printf(fmt, "", "IO", "", "", "", "", 0);
324*51b564acSmcwalter 		log_printf("\n", 0);
325*51b564acSmcwalter 		log_printf(fmt, "Location", "Type", "Slot", "Path",
326*51b564acSmcwalter 		    "Name", "Model", 0);
327*51b564acSmcwalter 		log_printf("\n");
328*51b564acSmcwalter 		log_printf(fmt, "-----------", "-----", "----",
329*51b564acSmcwalter 		    "---------------------------------------------",
330*51b564acSmcwalter 		    "-------------------------", "---------", 0);
331*51b564acSmcwalter 		log_printf("\n");
332*51b564acSmcwalter 		banner = TRUE;
333*51b564acSmcwalter 	}
334*51b564acSmcwalter 
335*51b564acSmcwalter 	/* Get platform name, if that fails, use monza name by default */
336*51b564acSmcwalter 	if (sysinfo(SI_PLATFORM, platbuf, sizeof (platbuf)) == -1) {
337*51b564acSmcwalter 		(void) strcpy(platbuf, MONZA_PLATFORM);
338*51b564acSmcwalter 	}
339*51b564acSmcwalter 
340*51b564acSmcwalter 	(void) picl_walk_tree_by_class(plafh, PCIEX, PCIEX, monza_pci_callback);
341*51b564acSmcwalter 	(void) picl_walk_tree_by_class(plafh, PCI, PCI, monza_pci_callback);
342*51b564acSmcwalter }
343*51b564acSmcwalter 
344*51b564acSmcwalter /* ARGSUSED */
345*51b564acSmcwalter void
sun4v_display_diaginfo(int flag,Prom_node * root,picl_nodehdl_t plafh)346*51b564acSmcwalter sun4v_display_diaginfo(int flag, Prom_node *root, picl_nodehdl_t plafh)
347*51b564acSmcwalter {
348*51b564acSmcwalter 	/* NOTE(ARGUNUSED(kstats)) */
349*51b564acSmcwalter 	/*
350*51b564acSmcwalter 	 * Now display the last powerfail time and the fatal hardware
351*51b564acSmcwalter 	 * reset information. We do this under a couple of conditions.
352*51b564acSmcwalter 	 * First if the user asks for it. The second is if the user
353*51b564acSmcwalter 	 * told us to do logging, and we found a system failure.
354*51b564acSmcwalter 	 */
355*51b564acSmcwalter 	if (flag) {
356*51b564acSmcwalter 		/*
357*51b564acSmcwalter 		 * display time of latest powerfail. Not all systems
358*51b564acSmcwalter 		 * have this capability. For those that do not, this
359*51b564acSmcwalter 		 * is just a no-op.
360*51b564acSmcwalter 		 */
361*51b564acSmcwalter 		disp_powerfail(root);
362*51b564acSmcwalter 
363*51b564acSmcwalter 		/* platform_disp_prom_version(tree); */
364*51b564acSmcwalter 		sun4v_display_hw_revisions(root, plafh);
365*51b564acSmcwalter 	}
366*51b564acSmcwalter }
367*51b564acSmcwalter 
368*51b564acSmcwalter /*
369*51b564acSmcwalter  * local functions
370*51b564acSmcwalter  */
371*51b564acSmcwalter /*
372*51b564acSmcwalter  * add all io devices under pci in io list
373*51b564acSmcwalter  */
374*51b564acSmcwalter /* ARGSUSED */
375*51b564acSmcwalter static int
monza_hw_rev_callback(picl_nodehdl_t pcih,void * args)376*51b564acSmcwalter monza_hw_rev_callback(picl_nodehdl_t pcih, void *args)
377*51b564acSmcwalter {
378*51b564acSmcwalter 	int		err = PICL_SUCCESS;
379*51b564acSmcwalter 	char		path[MAXSTRLEN] = "";
380*51b564acSmcwalter 	char		device_path[MAXSTRLEN];
381*51b564acSmcwalter 	char		NAC[MAXSTRLEN];
382*51b564acSmcwalter 	char		*compatible;
383*51b564acSmcwalter 	int32_t		revision;
384*51b564acSmcwalter 	int		device_found;
385*51b564acSmcwalter 
386*51b564acSmcwalter 	device_found = 0;
387*51b564acSmcwalter 
388*51b564acSmcwalter 	err = picl_get_propval_by_name(pcih, PICL_PROP_DEVFS_PATH, path,
389*51b564acSmcwalter 	    sizeof (path));
390*51b564acSmcwalter 	if (err != PICL_SUCCESS) {
391*51b564acSmcwalter 		return (err);
392*51b564acSmcwalter 	}
393*51b564acSmcwalter 
394*51b564acSmcwalter 
395*51b564acSmcwalter 	if ((strncmp(path, MONZA_NETWORK_0, strlen(MONZA_NETWORK_0)) == 0) ||
396*51b564acSmcwalter 	    (strncmp(path, MONZA_NETWORK_1, strlen(MONZA_NETWORK_1)) == 0)) {
397*51b564acSmcwalter 		device_found = 1;
398*51b564acSmcwalter 		(void) snprintf(NAC, sizeof (NAC), "%s/%s%d",
399*51b564acSmcwalter 		    MOTHERBOARD, OPHIR, 0);
400*51b564acSmcwalter 		revision = monza_get_int_propval(pcih, OBP_PROP_REVISION_ID,
401*51b564acSmcwalter 		    &err);
402*51b564acSmcwalter 	}
403*51b564acSmcwalter 
404*51b564acSmcwalter 	if ((strncmp(path, MONZA_NETWORK_2, strlen(MONZA_NETWORK_2)) == 0) ||
405*51b564acSmcwalter 	    (strncmp(path, MONZA_NETWORK_3, strlen(MONZA_NETWORK_3)) == 0)) {
406*51b564acSmcwalter 		device_found = 1;
407*51b564acSmcwalter 		(void) snprintf(NAC, sizeof (NAC), "%s/%s%d",
408*51b564acSmcwalter 		    MOTHERBOARD, OPHIR, 1);
409*51b564acSmcwalter 		revision = monza_get_int_propval(pcih, OBP_PROP_REVISION_ID,
410*51b564acSmcwalter 		    &err);
411*51b564acSmcwalter 	}
412*51b564acSmcwalter 
413*51b564acSmcwalter 	if ((strncmp(path, MONZA_ENET_2, strlen(MONZA_ENET_2)) == 0) ||
414*51b564acSmcwalter 	    (strncmp(path, MONZA_ENET_3, strlen(MONZA_ENET_3)) == 0)) {
415*51b564acSmcwalter 		device_found = 1;
416*51b564acSmcwalter 		(void) snprintf(NAC, sizeof (NAC), "%s/%s%d",
417*51b564acSmcwalter 		    MOTHERBOARD, OPHIR, 1);
418*51b564acSmcwalter 		revision = monza_get_int_propval(pcih, OBP_PROP_REVISION_ID,
419*51b564acSmcwalter 		    &err);
420*51b564acSmcwalter 	}
421*51b564acSmcwalter 
422*51b564acSmcwalter 	if ((strncmp(path, MONZA_NETWORK_4, strlen(MONZA_NETWORK_4)) == 0) ||
423*51b564acSmcwalter 	    (strncmp(path, MONZA_NETWORK_5, strlen(MONZA_NETWORK_5)) == 0)) {
424*51b564acSmcwalter 		device_found = 1;
425*51b564acSmcwalter 		(void) snprintf(NAC, sizeof (NAC), "%s/%s%d",
426*51b564acSmcwalter 		    MOTHERBOARD, OPHIR, 2);
427*51b564acSmcwalter 		revision = monza_get_int_propval(pcih, OBP_PROP_REVISION_ID,
428*51b564acSmcwalter 		    &err);
429*51b564acSmcwalter 	}
430*51b564acSmcwalter 
431*51b564acSmcwalter 	if (strcmp(path, MONZA_PCIE_SWITCH_PATH) == 0) {
432*51b564acSmcwalter 		device_found = 1;
433*51b564acSmcwalter 		(void) snprintf(NAC, sizeof (NAC), "%s/%s",
434*51b564acSmcwalter 		    MOTHERBOARD, PCIE_SWITCH);
435*51b564acSmcwalter 		revision = monza_get_int_propval(pcih,
436*51b564acSmcwalter 		    OBP_PROP_REVISION_ID, &err);
437*51b564acSmcwalter 	}
438*51b564acSmcwalter 
439*51b564acSmcwalter 	if (strcmp(path, MONZA_RTM_PATH) == 0) {
440*51b564acSmcwalter 		device_found = 1;
441*51b564acSmcwalter 		(void) snprintf(NAC, sizeof (NAC), "%s/%s", RTM, AMC);
442*51b564acSmcwalter 		revision = monza_get_int_propval(pcih, OBP_PROP_REVISION_ID,
443*51b564acSmcwalter 		    &err);
444*51b564acSmcwalter 	}
445*51b564acSmcwalter 
446*51b564acSmcwalter 	if (strcmp(path, MONZA_CF_PATH) == 0) {
447*51b564acSmcwalter 		device_found = 1;
448*51b564acSmcwalter 		(void) snprintf(NAC, sizeof (NAC), "%s/%s", MOTHERBOARD,
449*51b564acSmcwalter 		    MONZA_CF_DEVICE);
450*51b564acSmcwalter 		revision = monza_get_int_propval(pcih, OBP_PROP_REVISION_ID,
451*51b564acSmcwalter 		    &err);
452*51b564acSmcwalter 	}
453*51b564acSmcwalter 
454*51b564acSmcwalter 	if (device_found == 1) {
455*51b564acSmcwalter 		(void) strcpy(device_path, path);
456*51b564acSmcwalter 		err = monza_get_first_compatible_value(pcih, &compatible);
457*51b564acSmcwalter 
458*51b564acSmcwalter 		/* Print NAC name */
459*51b564acSmcwalter 		log_printf("%-20s", NAC);
460*51b564acSmcwalter 		/* Print Device Path */
461*51b564acSmcwalter 		if (strlen(device_path) > 38)
462*51b564acSmcwalter 			log_printf("%38.37s+", device_path);
463*51b564acSmcwalter 		else
464*51b564acSmcwalter 			log_printf("%39s", device_path);
465*51b564acSmcwalter 
466*51b564acSmcwalter 		/* Print Compatible # */
467*51b564acSmcwalter 		if (err == PICL_SUCCESS) {
468*51b564acSmcwalter 			log_printf("%31s", compatible);
469*51b564acSmcwalter 			free(compatible);
470*51b564acSmcwalter 		} else
471*51b564acSmcwalter 			log_printf("%31s", " ");
472*51b564acSmcwalter 
473*51b564acSmcwalter 		/* Print Revision */
474*51b564acSmcwalter 		log_printf("%6d", revision);
475*51b564acSmcwalter 		log_printf("\n");
476*51b564acSmcwalter 	}
477*51b564acSmcwalter 
478*51b564acSmcwalter 	return (PICL_WALK_CONTINUE);
479*51b564acSmcwalter }
480*51b564acSmcwalter 
481*51b564acSmcwalter /*ARGSUSED*/
482*51b564acSmcwalter static void
sun4v_display_hw_revisions(Prom_node * root,picl_nodehdl_t plafh)483*51b564acSmcwalter sun4v_display_hw_revisions(Prom_node *root, picl_nodehdl_t plafh)
484*51b564acSmcwalter {
485*51b564acSmcwalter 	Prom_node	*pnode;
486*51b564acSmcwalter 	char		*value;
487*51b564acSmcwalter 	char 		platbuf[MAXSTRLEN];
488*51b564acSmcwalter 	char	*fmt = "%-20s %-40s %-30s %-9s";
489*51b564acSmcwalter 
490*51b564acSmcwalter 	log_printf(dgettext(TEXT_DOMAIN, "\n"
491*51b564acSmcwalter 	    "========================= HW Revisions "
492*51b564acSmcwalter 	    "=======================================\n\n"));
493*51b564acSmcwalter 
494*51b564acSmcwalter 	log_printf(dgettext(TEXT_DOMAIN,
495*51b564acSmcwalter 	    "System PROM revisions:\n"
496*51b564acSmcwalter 	    "----------------------\n"));
497*51b564acSmcwalter 
498*51b564acSmcwalter 	pnode = dev_find_node(root, "openprom");
499*51b564acSmcwalter 	if (pnode != NULL) {
500*51b564acSmcwalter 		value = (char *)get_prop_val(find_prop(pnode, "version"));
501*51b564acSmcwalter 		log_printf(value);
502*51b564acSmcwalter 	}
503*51b564acSmcwalter 
504*51b564acSmcwalter 	log_printf(dgettext(TEXT_DOMAIN, "\n\n"
505*51b564acSmcwalter 	    "IO ASIC revisions:\n"
506*51b564acSmcwalter 	    "------------------\n"));
507*51b564acSmcwalter 	log_printf(fmt, "Location", "Path", "Device", "Revision\n", 0);
508*51b564acSmcwalter 	log_printf(fmt, "--------------------",
509*51b564acSmcwalter 	    "----------------------------------------",
510*51b564acSmcwalter 	    "------------------------------",
511*51b564acSmcwalter 	    "---------\n", 0);
512*51b564acSmcwalter 
513*51b564acSmcwalter 	/* Get platform name, if that fails, use monza name by default */
514*51b564acSmcwalter 	if (sysinfo(SI_PLATFORM, platbuf, sizeof (platbuf)) == -1) {
515*51b564acSmcwalter 		(void) strcpy(platbuf, MONZA_PLATFORM);
516*51b564acSmcwalter 	}
517*51b564acSmcwalter 
518*51b564acSmcwalter 	(void) picl_walk_tree_by_class(plafh, PCIEX,
519*51b564acSmcwalter 	    PCIEX, monza_hw_rev_callback);
520*51b564acSmcwalter 	(void) picl_walk_tree_by_class(plafh, PCI,
521*51b564acSmcwalter 	    PCI, monza_hw_rev_callback);
522*51b564acSmcwalter 	(void) picl_walk_tree_by_class(plafh, NETWORK,
523*51b564acSmcwalter 	    NETWORK, monza_hw_rev_callback);
524*51b564acSmcwalter }
525*51b564acSmcwalter 
526*51b564acSmcwalter /*
527*51b564acSmcwalter  * return the first compatible value
528*51b564acSmcwalter  */
529*51b564acSmcwalter static int
monza_get_first_compatible_value(picl_nodehdl_t nodeh,char ** outbuf)530*51b564acSmcwalter monza_get_first_compatible_value(picl_nodehdl_t nodeh, char **outbuf)
531*51b564acSmcwalter {
532*51b564acSmcwalter 	int		err;
533*51b564acSmcwalter 	picl_prophdl_t	proph;
534*51b564acSmcwalter 	picl_propinfo_t	pinfo;
535*51b564acSmcwalter 	picl_prophdl_t	tblh;
536*51b564acSmcwalter 	picl_prophdl_t	rowproph;
537*51b564acSmcwalter 	char		*pval;
538*51b564acSmcwalter 
539*51b564acSmcwalter 	err = picl_get_propinfo_by_name(nodeh, OBP_PROP_COMPATIBLE,
540*51b564acSmcwalter 	    &pinfo, &proph);
541*51b564acSmcwalter 	if (err != PICL_SUCCESS)
542*51b564acSmcwalter 		return (err);
543*51b564acSmcwalter 
544*51b564acSmcwalter 	if (pinfo.type == PICL_PTYPE_CHARSTRING) {
545*51b564acSmcwalter 		pval = malloc(pinfo.size);
546*51b564acSmcwalter 		if (pval == NULL)
547*51b564acSmcwalter 			return (PICL_FAILURE);
548*51b564acSmcwalter 		err = picl_get_propval(proph, pval, pinfo.size);
549*51b564acSmcwalter 		if (err != PICL_SUCCESS) {
550*51b564acSmcwalter 			free(pval);
551*51b564acSmcwalter 			return (err);
552*51b564acSmcwalter 		}
553*51b564acSmcwalter 		*outbuf = pval;
554*51b564acSmcwalter 		return (PICL_SUCCESS);
555*51b564acSmcwalter 	}
556*51b564acSmcwalter 
557*51b564acSmcwalter 	if (pinfo.type != PICL_PTYPE_TABLE)
558*51b564acSmcwalter 		return (PICL_FAILURE);
559*51b564acSmcwalter 
560*51b564acSmcwalter 	/* get first string from table */
561*51b564acSmcwalter 	err = picl_get_propval(proph, &tblh, pinfo.size);
562*51b564acSmcwalter 	if (err != PICL_SUCCESS)
563*51b564acSmcwalter 		return (err);
564*51b564acSmcwalter 
565*51b564acSmcwalter 	err = picl_get_next_by_row(tblh, &rowproph);
566*51b564acSmcwalter 	if (err != PICL_SUCCESS)
567*51b564acSmcwalter 		return (err);
568*51b564acSmcwalter 
569*51b564acSmcwalter 	err = picl_get_propinfo(rowproph, &pinfo);
570*51b564acSmcwalter 	if (err != PICL_SUCCESS)
571*51b564acSmcwalter 		return (err);
572*51b564acSmcwalter 
573*51b564acSmcwalter 	pval = malloc(pinfo.size);
574*51b564acSmcwalter 	if (pval == NULL)
575*51b564acSmcwalter 		return (PICL_FAILURE);
576*51b564acSmcwalter 
577*51b564acSmcwalter 	err = picl_get_propval(rowproph, pval, pinfo.size);
578*51b564acSmcwalter 	if (err != PICL_SUCCESS) {
579*51b564acSmcwalter 		free(pval);
580*51b564acSmcwalter 		return (err);
581*51b564acSmcwalter 	}
582*51b564acSmcwalter 
583*51b564acSmcwalter 	*outbuf = pval;
584*51b564acSmcwalter 	return (PICL_SUCCESS);
585*51b564acSmcwalter }
586*51b564acSmcwalter 
587*51b564acSmcwalter static int64_t
monza_get_int_propval(picl_nodehdl_t modh,char * prop_name,int * ret)588*51b564acSmcwalter monza_get_int_propval(picl_nodehdl_t modh, char *prop_name, int *ret)
589*51b564acSmcwalter {
590*51b564acSmcwalter 	int		err;
591*51b564acSmcwalter 	picl_prophdl_t	proph;
592*51b564acSmcwalter 	picl_propinfo_t	pinfo;
593*51b564acSmcwalter 	int8_t		int8v;
594*51b564acSmcwalter 	int16_t		int16v;
595*51b564acSmcwalter 	int32_t		int32v;
596*51b564acSmcwalter 	int64_t		int64v;
597*51b564acSmcwalter 
598*51b564acSmcwalter 	err = picl_get_propinfo_by_name(modh, prop_name, &pinfo, &proph);
599*51b564acSmcwalter 	if (err != PICL_SUCCESS) {
600*51b564acSmcwalter 		*ret = err;
601*51b564acSmcwalter 		return (0);
602*51b564acSmcwalter 	}
603*51b564acSmcwalter 
604*51b564acSmcwalter 	/*
605*51b564acSmcwalter 	 * If it is not an int, uint or byte array prop, return failure
606*51b564acSmcwalter 	 */
607*51b564acSmcwalter 	if ((pinfo.type != PICL_PTYPE_INT) &&
608*51b564acSmcwalter 	    (pinfo.type != PICL_PTYPE_UNSIGNED_INT) &&
609*51b564acSmcwalter 	    (pinfo.type != PICL_PTYPE_BYTEARRAY)) {
610*51b564acSmcwalter 		*ret = PICL_FAILURE;
611*51b564acSmcwalter 		return (0);
612*51b564acSmcwalter 	}
613*51b564acSmcwalter 
614*51b564acSmcwalter 	switch (pinfo.size) {
615*51b564acSmcwalter 	case sizeof (int8_t):
616*51b564acSmcwalter 		err = picl_get_propval(proph, &int8v, sizeof (int8v));
617*51b564acSmcwalter 		*ret = err;
618*51b564acSmcwalter 		return (int8v);
619*51b564acSmcwalter 	case sizeof (int16_t):
620*51b564acSmcwalter 		err = picl_get_propval(proph, &int16v, sizeof (int16v));
621*51b564acSmcwalter 		*ret = err;
622*51b564acSmcwalter 		return (int16v);
623*51b564acSmcwalter 	case sizeof (int32_t):
624*51b564acSmcwalter 		err = picl_get_propval(proph, &int32v, sizeof (int32v));
625*51b564acSmcwalter 		*ret = err;
626*51b564acSmcwalter 		return (int32v);
627*51b564acSmcwalter 	case sizeof (int64_t):
628*51b564acSmcwalter 		err = picl_get_propval(proph, &int64v, sizeof (int64v));
629*51b564acSmcwalter 		*ret = err;
630*51b564acSmcwalter 		return (int64v);
631*51b564acSmcwalter 	default:	/* not supported size */
632*51b564acSmcwalter 		*ret = PICL_FAILURE;
633*51b564acSmcwalter 		return (0);
634*51b564acSmcwalter 	}
635*51b564acSmcwalter }
636