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 == pelton 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 "pelton.h" 55 56 #if !defined(TEXT_DOMAIN) 57 #define TEXT_DOMAIN "SYS_TEST" 58 #endif 59 60 61 /* local functions */ 62 static int pelton_get_first_compatible_value(picl_nodehdl_t nodeh, 63 char **outbuf); 64 static int64_t pelton_get_int_propval(picl_nodehdl_t modh, char *prop_name, 65 int *ret); 66 67 static void 68 get_bus_type(char *path, struct io_card *card) 69 { 70 if (strncmp(path, PEL_PCIX_SLOT0, PCIX_COMP_NUM) == 0) { 71 (void) strcpy(card->bus_type, "PCIX"); 72 } else if (strncmp(path, PEL_PCIX_SLOT1, PCIX_COMP_NUM) == 0) { 73 (void) strcpy(card->bus_type, "PCIX"); 74 } else if (strncmp(path, PEL_PCIX_SLOT2, PCIX_COMP_NUM) == 0) { 75 (void) strcpy(card->bus_type, "PCIX"); 76 } else if (strncmp(path, PEL_PCIX_SLOT3, PCIX_COMP_NUM) == 0) { 77 (void) strcpy(card->bus_type, "PCIX"); 78 } else { 79 (void) strcpy(card->bus_type, "PCIE"); 80 } 81 } 82 83 static void 84 get_slot_number(char *path, struct io_card *card) 85 { 86 if (strncmp(path, PEL_PCIE_SLOT0, PCIE_COMP_NUM) == 0) { 87 (void) strcpy(card->slot_str, "0"); 88 card->slot = 0; 89 } else if (strncmp(path, PEL_PCIX_SLOT2, strlen(PEL_PCIX_SLOT2)) == 0) { 90 (void) strcpy(card->slot_str, "PCIX"); 91 card->slot = -1; 92 } else if (strncmp(path, PEL_PCIX_SLOT1, strlen(PEL_PCIX_SLOT1)) == 0) { 93 (void) strcpy(card->slot_str, "PCIX"); 94 card->slot = -1; 95 } else if (strncmp(path, PEL_PCIX_SLOT0, strlen(PEL_PCIX_SLOT0)) == 0) { 96 (void) strcpy(card->slot_str, "PCIX"); 97 card->slot = -1; 98 } else { 99 (void) strcpy(card->slot_str, IOBOARD); 100 card->slot = -1; 101 } 102 } 103 104 static int 105 pelton_get_network_instance(char *path) 106 { 107 if (strncmp(path, PEL_NETWORK_1_PATH, 108 strlen(PEL_NETWORK_1_PATH)) == 0) { 109 return (1); 110 } else if (strncmp(path, PEL_NETWORK_3_PATH, 111 strlen(PEL_NETWORK_3_PATH)) == 0) { 112 return (3); 113 } else if (strncmp(path, PEL_NETWORK_0_PATH, 114 strlen(PEL_NETWORK_0_PATH)) == 0) { 115 return (0); 116 } else if (strncmp(path, PEL_NETWORK_2_PATH, 117 strlen(PEL_NETWORK_2_PATH)) == 0) { 118 return (2); 119 } else { 120 return (-1); 121 } 122 } 123 /* 124 * add all io devices under pci in io list 125 */ 126 /* ARGSUSED */ 127 int 128 pelton_pci_callback(picl_nodehdl_t pcih, void *args) 129 { 130 int err = PICL_SUCCESS; 131 picl_nodehdl_t nodeh; 132 char path[MAXSTRLEN]; 133 char parent_path[MAXSTRLEN]; 134 char piclclass[PICL_CLASSNAMELEN_MAX]; 135 char name[MAXSTRLEN]; 136 char model[MAXSTRLEN]; 137 char *compatible; 138 char binding_name[MAXSTRLEN]; 139 struct io_card pci_card; 140 int32_t instance; 141 142 err = picl_get_propval_by_name(pcih, PICL_PROP_DEVFS_PATH, parent_path, 143 sizeof (parent_path)); 144 if (err != PICL_SUCCESS) { 145 return (err); 146 } 147 148 /* Walk through the children */ 149 150 err = picl_get_propval_by_name(pcih, PICL_PROP_CHILD, &nodeh, 151 sizeof (picl_nodehdl_t)); 152 153 while (err == PICL_SUCCESS) { 154 err = picl_get_propval_by_name(nodeh, PICL_PROP_CLASSNAME, 155 piclclass, sizeof (piclclass)); 156 if (err != PICL_SUCCESS) 157 return (err); 158 159 if (strcmp(piclclass, "pciex") == 0) { 160 err = picl_get_propval_by_name(nodeh, PICL_PROP_PEER, 161 &nodeh, sizeof (picl_nodehdl_t)); 162 continue; 163 } 164 165 if (strcmp(piclclass, PICL_CLASS_PCI) == 0) { 166 err = picl_get_propval_by_name(nodeh, PICL_PROP_CHILD, 167 &nodeh, sizeof (picl_nodehdl_t)); 168 continue; 169 } 170 171 err = picl_get_propval_by_name(nodeh, PICL_PROP_DEVFS_PATH, 172 path, sizeof (path)); 173 if (err != PICL_SUCCESS) { 174 return (err); 175 } 176 177 (void) strlcpy(pci_card.notes, path, sizeof (pci_card.notes)); 178 179 get_bus_type(parent_path, &pci_card); 180 181 get_slot_number(parent_path, &pci_card); 182 183 err = picl_get_propval_by_name(nodeh, PICL_PROP_NAME, &name, 184 sizeof (name)); 185 if (err == PICL_PROPNOTFOUND) 186 (void) strcpy(name, ""); 187 else if (err != PICL_SUCCESS) 188 return (err); 189 190 191 /* Figure NAC name */ 192 if ((strcmp(name, NETWORK) == 0) && 193 (strcmp(pci_card.slot_str, IOBOARD) == 0)) { 194 instance = pelton_get_network_instance(path); 195 196 (void) snprintf(pci_card.status, 197 sizeof (pci_card.status), "%s/%s%d", IOBOARD, 198 "NET", instance); 199 } else { 200 if (pci_card.slot != -1) { 201 (void) snprintf(pci_card.status, 202 sizeof (pci_card.status), "%s/%s%d", 203 IOBOARD, pci_card.bus_type, pci_card.slot); 204 } else { 205 (void) snprintf(pci_card.status, 206 sizeof (pci_card.status), "%s/%s", IOBOARD, 207 pci_card.bus_type); 208 } 209 } 210 211 /* 212 * Get the name of this card. Iif binding_name is found, 213 * name will be <nodename>-<binding_name> 214 */ 215 216 err = picl_get_propval_by_name(nodeh, PICL_PROP_BINDING_NAME, 217 &binding_name, sizeof (binding_name)); 218 if (err == PICL_PROPNOTFOUND) { 219 /* 220 * if compatible prop is found, name will be 221 * <nodename>-<compatible> 222 */ 223 err = pelton_get_first_compatible_value(nodeh, 224 &compatible); 225 if (err == PICL_SUCCESS) { 226 (void) strlcat(name, "-", MAXSTRLEN); 227 (void) strlcat(name, compatible, MAXSTRLEN); 228 free(compatible); 229 } else if (err != PICL_PROPNOTFOUND) { 230 return (err); 231 } 232 } else if (err != PICL_SUCCESS) { 233 return (err); 234 } else if (strcmp(name, binding_name) != 0) { 235 (void) strlcat(name, "-", MAXSTRLEN); 236 (void) strlcat(name, binding_name, MAXSTRLEN); 237 } 238 239 (void) strlcpy(pci_card.name, name, sizeof (pci_card.name)); 240 241 /* Get the model of this card */ 242 243 err = picl_get_propval_by_name(nodeh, OBP_PROP_MODEL, 244 &model, sizeof (model)); 245 if (err == PICL_PROPNOTFOUND) 246 (void) strcpy(model, ""); 247 else if (err != PICL_SUCCESS) 248 return (err); 249 (void) strlcpy(pci_card.model, model, sizeof (pci_card.model)); 250 251 /* Print NAC name */ 252 log_printf("%-11s", pci_card.status); 253 /* Print IO Type */ 254 log_printf("%6s", pci_card.bus_type); 255 /* Print Slot # */ 256 log_printf("%5s", pci_card.slot_str); 257 /* Print Parent Path */ 258 log_printf("%46.45s", pci_card.notes); 259 /* Printf Card Name */ 260 if (strlen(pci_card.name) > 24) 261 log_printf("%25.24s+", pci_card.name); 262 else 263 log_printf("%26s", pci_card.name); 264 /* Print Card Model */ 265 if (strlen(pci_card.model) > 10) 266 log_printf("%10.9s+", pci_card.model); 267 else 268 log_printf("%10s", pci_card.model); 269 log_printf("\n"); 270 271 err = picl_get_propval_by_name(nodeh, PICL_PROP_PEER, &nodeh, 272 sizeof (picl_nodehdl_t)); 273 274 } 275 276 return (PICL_WALK_CONTINUE); 277 } 278 279 /* 280 * local functions 281 */ 282 /* 283 * add all io devices under pci in io list 284 */ 285 /* ARGSUSED */ 286 int 287 pelton_hw_rev_callback(picl_nodehdl_t pcih, void *args) 288 { 289 int err = PICL_SUCCESS; 290 char path[MAXSTRLEN] = ""; 291 char device_path[MAXSTRLEN]; 292 char NAC[MAXSTRLEN]; 293 char *compatible; 294 int32_t revision; 295 int device_found; 296 297 device_found = 0; 298 299 err = picl_get_propval_by_name(pcih, PICL_PROP_DEVFS_PATH, path, 300 sizeof (path)); 301 if (err != PICL_SUCCESS) { 302 return (err); 303 } 304 305 if ((strcmp(path, PEL_NETWORK_0_PATH) == 0) || 306 (strcmp(path, PEL_NETWORK_1_PATH) == 0)) { 307 device_found = 1; 308 (void) snprintf(NAC, sizeof (NAC), "%s/%s%d", IOBOARD, OPHIR, 309 0); 310 revision = pelton_get_int_propval(pcih, OBP_PROP_REVISION_ID, 311 &err); 312 } 313 314 if ((strcmp(path, PEL_NETWORK_2_PATH) == 0) || 315 (strcmp(path, PEL_NETWORK_3_PATH) == 0)) { 316 device_found = 1; 317 (void) snprintf(NAC, sizeof (NAC), "%s/%s%d", IOBOARD, OPHIR, 318 1); 319 revision = pelton_get_int_propval(pcih, OBP_PROP_REVISION_ID, 320 &err); 321 } 322 323 if ((strcmp(path, FIRE_PATH0) == 0) || 324 (strcmp(path, FIRE_PATH1) == 0)) { 325 device_found = 1; 326 (void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD, 327 "IO-BRIDGE"); 328 revision = pelton_get_int_propval(pcih, OBP_PROP_VERSION_NUM, 329 &err); 330 } 331 332 if ((strcmp(path, PEL_PCIX_SLOT0) == 0) || 333 (strcmp(path, PEL_PCIX_SLOT1) == 0) || 334 (strcmp(path, PEL_PCIX_SLOT2) == 0) || 335 (strcmp(path, PEL_PCIX_SLOT3) == 0)) { 336 device_found = 1; 337 (void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD, 338 PCI_BRIDGE); 339 revision = pelton_get_int_propval(pcih, OBP_PROP_REVISION_ID, 340 &err); 341 } 342 343 if (strcmp(path, SWITCH_A_PATH) == 0) { 344 device_found = 1; 345 (void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD, SWITCH_A); 346 revision = pelton_get_int_propval(pcih, OBP_PROP_REVISION_ID, 347 &err); 348 } 349 350 if (strcmp(path, SWITCH_B_PATH) == 0) { 351 device_found = 1; 352 (void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD, SWITCH_B); 353 revision = pelton_get_int_propval(pcih, OBP_PROP_REVISION_ID, 354 &err); 355 } 356 357 if (strcmp(path, PEL_LSI_PATH) == 0) { 358 device_found = 1; 359 (void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD, 360 PEL_SAS_HBA); 361 revision = pelton_get_int_propval(pcih, OBP_PROP_REVISION_ID, 362 &err); 363 } 364 if (device_found == 1) { 365 (void) strcpy(device_path, path); 366 err = pelton_get_first_compatible_value(pcih, &compatible); 367 368 /* Print NAC name */ 369 log_printf("%-20s", NAC); 370 /* Print Device Path */ 371 if (strlen(device_path) > 38) 372 log_printf("%38.37s+", device_path); 373 else 374 log_printf("%39s", device_path); 375 /* Print Compatible # */ 376 log_printf("%31s", compatible); 377 free(compatible); 378 /* Print Revision */ 379 log_printf("%6d", revision); 380 log_printf("\n"); 381 } 382 383 return (PICL_WALK_CONTINUE); 384 } 385 386 /* 387 * return the first compatible value 388 */ 389 static int 390 pelton_get_first_compatible_value(picl_nodehdl_t nodeh, char **outbuf) 391 { 392 int err; 393 picl_prophdl_t proph; 394 picl_propinfo_t pinfo; 395 picl_prophdl_t tblh; 396 picl_prophdl_t rowproph; 397 char *pval; 398 399 err = picl_get_propinfo_by_name(nodeh, OBP_PROP_COMPATIBLE, 400 &pinfo, &proph); 401 if (err != PICL_SUCCESS) 402 return (err); 403 404 if (pinfo.type == PICL_PTYPE_CHARSTRING) { 405 pval = malloc(pinfo.size); 406 if (pval == NULL) 407 return (PICL_FAILURE); 408 err = picl_get_propval(proph, pval, pinfo.size); 409 if (err != PICL_SUCCESS) { 410 free(pval); 411 return (err); 412 } 413 *outbuf = pval; 414 return (PICL_SUCCESS); 415 } 416 417 if (pinfo.type != PICL_PTYPE_TABLE) 418 return (PICL_FAILURE); 419 420 /* get first string from table */ 421 err = picl_get_propval(proph, &tblh, pinfo.size); 422 if (err != PICL_SUCCESS) 423 return (err); 424 425 err = picl_get_next_by_row(tblh, &rowproph); 426 if (err != PICL_SUCCESS) 427 return (err); 428 429 err = picl_get_propinfo(rowproph, &pinfo); 430 if (err != PICL_SUCCESS) 431 return (err); 432 433 pval = malloc(pinfo.size); 434 if (pval == NULL) 435 return (PICL_FAILURE); 436 437 err = picl_get_propval(rowproph, pval, pinfo.size); 438 if (err != PICL_SUCCESS) { 439 free(pval); 440 return (err); 441 } 442 443 *outbuf = pval; 444 return (PICL_SUCCESS); 445 } 446 447 static int64_t 448 pelton_get_int_propval(picl_nodehdl_t modh, char *prop_name, int *ret) 449 { 450 int err; 451 picl_prophdl_t proph; 452 picl_propinfo_t pinfo; 453 int8_t int8v; 454 int16_t int16v; 455 int32_t int32v; 456 int64_t int64v; 457 458 err = picl_get_propinfo_by_name(modh, prop_name, &pinfo, &proph); 459 if (err != PICL_SUCCESS) { 460 *ret = err; 461 return (0); 462 } 463 464 /* 465 * If it is not an int, uint or byte array prop, return failure 466 */ 467 if ((pinfo.type != PICL_PTYPE_INT) && 468 (pinfo.type != PICL_PTYPE_UNSIGNED_INT) && 469 (pinfo.type != PICL_PTYPE_BYTEARRAY)) { 470 *ret = PICL_FAILURE; 471 return (0); 472 } 473 474 switch (pinfo.size) { 475 case sizeof (int8_t): 476 err = picl_get_propval(proph, &int8v, sizeof (int8v)); 477 *ret = err; 478 return (int8v); 479 case sizeof (int16_t): 480 err = picl_get_propval(proph, &int16v, sizeof (int16v)); 481 *ret = err; 482 return (int16v); 483 case sizeof (int32_t): 484 err = picl_get_propval(proph, &int32v, sizeof (int32v)); 485 *ret = err; 486 return (int32v); 487 case sizeof (int64_t): 488 err = picl_get_propval(proph, &int64v, sizeof (int64v)); 489 *ret = err; 490 return (int64v); 491 default: /* not supported size */ 492 *ret = PICL_FAILURE; 493 return (0); 494 } 495 } 496