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