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 /* 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 #include <stdio.h> 30 #include <stdlib.h> 31 #include <stdarg.h> 32 #include <string.h> 33 #include <strings.h> 34 #include <libnvpair.h> 35 #include <kstat.h> 36 #include <unistd.h> 37 #include <sys/types.h> 38 #include <fm/topo_mod.h> 39 40 #define BUFSZ 128 41 42 char * 43 get_fmtstr(topo_mod_t *mod, nvlist_t *in) 44 { 45 char *fmtstr; 46 nvlist_t *args; 47 int ret; 48 49 topo_mod_dprintf(mod, "get_fmtstr() called\n"); 50 51 if ((ret = nvlist_lookup_nvlist(in, TOPO_PROP_ARGS, &args)) != 0) { 52 topo_mod_dprintf(mod, "Failed to lookup 'args' list (%s)\n", 53 strerror(ret)); 54 (void) topo_mod_seterrno(mod, EMOD_NVL_INVAL); 55 return (NULL); 56 } 57 if ((ret = nvlist_lookup_string(args, "format", &fmtstr)) != 0) { 58 topo_mod_dprintf(mod, "Failed to lookup 'format' arg (%s)\n", 59 strerror(ret)); 60 (void) topo_mod_seterrno(mod, EMOD_NVL_INVAL); 61 return (NULL); 62 } 63 return (fmtstr); 64 } 65 66 int 67 store_prop_val(topo_mod_t *mod, char *buf, char *propname, nvlist_t **out) 68 { 69 if (topo_mod_nvalloc(mod, out, NV_UNIQUE_NAME) != 0) { 70 topo_mod_dprintf(mod, "Failed to allocate 'out' nvlist\n"); 71 return (topo_mod_seterrno(mod, EMOD_NOMEM)); 72 } 73 if (nvlist_add_string(*out, TOPO_PROP_VAL_NAME, propname) != 0) { 74 topo_mod_dprintf(mod, "Failed to set '%s'\n", 75 TOPO_PROP_VAL_NAME); 76 nvlist_free(*out); 77 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 78 } 79 if (nvlist_add_uint32(*out, TOPO_PROP_VAL_TYPE, TOPO_TYPE_STRING) 80 != 0) { 81 topo_mod_dprintf(mod, "Failed to set '%s'\n", 82 TOPO_PROP_VAL_TYPE); 83 nvlist_free(*out); 84 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 85 } 86 if (nvlist_add_string(*out, TOPO_PROP_VAL_VAL, buf) != 0) { 87 topo_mod_dprintf(mod, "Failed to set '%s'\n", 88 TOPO_PROP_VAL_VAL); 89 nvlist_free(*out); 90 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 91 } 92 return (0); 93 } 94 95 /* 96 * This is a somewhat generic property method for labelling the dimm slots on 97 * uni-socket x86/x64 platforms. This method assumes a direct linear 98 * correlation between the dimm topo node instance number and the dimm slot 99 * label number. It takes the following two arguments: 100 * 101 * format: a string containing a printf-like format with a single %d token 102 * which this method computes 103 * 104 * i.e.: DIMM %d 105 * 106 * offset: a numeric offset that we'll number the dimms from. This is to 107 * allow for the fact that some systems number the dimm slots 108 * from zero and others start from one (like the Ultra 20) 109 */ 110 /* ARGSUSED */ 111 int 112 simple_dimm_label(topo_mod_t *mod, tnode_t *node, topo_version_t vers, 113 nvlist_t *in, nvlist_t **out) 114 { 115 char *fmtstr, buf[BUFSZ]; 116 int ret; 117 uint32_t offset; 118 nvlist_t *args; 119 120 topo_mod_dprintf(mod, "simple_dimm_label() called\n"); 121 if ((ret = nvlist_lookup_nvlist(in, TOPO_PROP_ARGS, &args)) != 0) { 122 topo_mod_dprintf(mod, "Failed to lookup 'args' list (%s)\n", 123 strerror(ret)); 124 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 125 } 126 if ((ret = nvlist_lookup_uint32(args, "offset", &offset)) != 0) { 127 topo_mod_dprintf(mod, "Failed to lookup 'offset' arg (%s)\n", 128 strerror(ret)); 129 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 130 } 131 132 if ((fmtstr = get_fmtstr(mod, in)) == NULL) { 133 topo_mod_dprintf(mod, "Failed to retrieve 'format' arg\n"); 134 /* topo errno already set */ 135 return (-1); 136 } 137 138 /* LINTED: E_SEC_PRINTF_VAR_FMT */ 139 (void) snprintf(buf, BUFSZ, fmtstr, 140 (topo_node_instance(node) + offset)); 141 142 if (store_prop_val(mod, buf, "label", out) != 0) { 143 topo_mod_dprintf(mod, "Failed to set label\n"); 144 /* topo errno already set */ 145 return (-1); 146 } 147 148 return (0); 149 } 150 151 152 /* 153 * This is a somewhat generic property method for labelling the dimm slots on 154 * multi-socket x86/x64 platforms. It takes the following two arguments: 155 * 156 * format: a string containing a printf-like format with a two %d tokens 157 * for the cpu and dimm slot label numbers, which this method 158 * computes 159 * 160 * i.e.: CPU %d DIMM %d 161 * 162 * offset: a numeric offset that we'll number the dimms from. This is to 163 * allow for the fact that some systems number the dimm slots 164 * from zero while others may start from one 165 * 166 * order: "reverse" or "forward" - sets the direction of the correlation 167 * between dimm topo node instance number and DIMM slot number 168 * 169 * dimms_per_chip: the number of DIMM slots per chip 170 */ 171 /* ARGSUSED */ 172 int 173 simple_dimm_label_mp(topo_mod_t *mod, tnode_t *node, topo_version_t vers, 174 nvlist_t *in, nvlist_t **out) 175 { 176 char *fmtstr, *order, buf[BUFSZ]; 177 tnode_t *chip; 178 int ret; 179 uint32_t offset, dimms_per_chip; 180 nvlist_t *args; 181 182 topo_mod_dprintf(mod, "simple_dimm_label_mp() called\n"); 183 184 if ((ret = nvlist_lookup_nvlist(in, TOPO_PROP_ARGS, &args)) != 0) { 185 topo_mod_dprintf(mod, "Failed to lookup 'args' list (%s)\n", 186 strerror(ret)); 187 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 188 } 189 if ((ret = nvlist_lookup_uint32(args, "offset", &offset)) != 0) { 190 topo_mod_dprintf(mod, "Failed to lookup 'offset' arg (%s)\n", 191 strerror(ret)); 192 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 193 } 194 if ((ret = nvlist_lookup_uint32(args, "dimms_per_chip", 195 &dimms_per_chip)) != 0) { 196 topo_mod_dprintf(mod, "Failed to lookup 'dimms_per_chip' arg " 197 "(%s)\n", strerror(ret)); 198 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 199 } 200 if ((ret = nvlist_lookup_string(args, "order", &order)) != 0) { 201 topo_mod_dprintf(mod, "Failed to lookup 'order' arg (%s)\n", 202 strerror(ret)); 203 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 204 } 205 if ((fmtstr = get_fmtstr(mod, in)) == NULL) { 206 topo_mod_dprintf(mod, "Failed to retrieve 'format' arg\n"); 207 topo_mod_free(mod, order, BUFSZ); 208 /* topo errno already set */ 209 return (-1); 210 } 211 212 chip = topo_node_parent(topo_node_parent(node)); 213 214 if (strcasecmp(order, "forward") == 0) 215 /* LINTED: E_SEC_PRINTF_VAR_FMT */ 216 (void) snprintf(buf, BUFSZ, fmtstr, topo_node_instance(chip), 217 (topo_node_instance(node) + offset)); 218 else if (strcasecmp(order, "reverse") == 0) 219 /* LINTED: E_SEC_PRINTF_VAR_FMT */ 220 (void) snprintf(buf, BUFSZ, fmtstr, topo_node_instance(chip), 221 (((topo_node_instance(chip) + 1) * dimms_per_chip) 222 - (topo_node_instance(node)) - 1 + offset)); 223 else { 224 topo_mod_dprintf(mod, "Invalid value for order arg\n"); 225 topo_mod_free(mod, order, BUFSZ); 226 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 227 } 228 229 if (store_prop_val(mod, buf, "label", out) != 0) { 230 topo_mod_dprintf(mod, "Failed to set label\n"); 231 topo_mod_free(mod, order, BUFSZ); 232 /* topo errno already set */ 233 return (-1); 234 } 235 236 return (0); 237 } 238 239 /* 240 * This method assumes a correspondence between the dimm topo node instance 241 * number and the dimm slot label number, but unlike simple_chip_label_mp, the 242 * slot numbers aren't reused between CPU's. This method assumes there 243 * are 4 DIMM slots per chip. It takes the following two arguments: 244 * 245 * format: a string containing a printf-like format with a single %d token 246 * which this method computes 247 * 248 * i.e.: DIMM %d 249 * 250 * offset: a numeric offset that we'll number the dimms from. This is to 251 * allow for the fact that some systems number the dimm slots 252 * from zero and others may start from one 253 * 254 * order: "reverse" or "forward" - sets the direction of the correlation 255 * between dimm topo node instance number and DIMM slot number 256 */ 257 /* ARGSUSED */ 258 int 259 seq_dimm_label(topo_mod_t *mod, tnode_t *node, topo_version_t vers, 260 nvlist_t *in, nvlist_t **out) 261 { 262 char *fmtstr, *order, buf[BUFSZ]; 263 int ret; 264 uint32_t offset; 265 nvlist_t *args; 266 tnode_t *chip; 267 268 topo_mod_dprintf(mod, "seq_dimm_label() called\n"); 269 if ((ret = nvlist_lookup_nvlist(in, TOPO_PROP_ARGS, &args)) != 0) { 270 topo_mod_dprintf(mod, "Failed to lookup 'args' list (%s)\n", 271 strerror(ret)); 272 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 273 } 274 if ((ret = nvlist_lookup_uint32(args, "offset", &offset)) != 0) { 275 topo_mod_dprintf(mod, "Failed to lookup 'offset' arg (%s)\n", 276 strerror(ret)); 277 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 278 } 279 if ((ret = nvlist_lookup_string(args, "order", &order)) != 0) { 280 topo_mod_dprintf(mod, "Failed to lookup 'order' arg (%s)\n", 281 strerror(ret)); 282 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 283 } 284 285 if ((fmtstr = get_fmtstr(mod, in)) == NULL) { 286 topo_mod_dprintf(mod, "Failed to retrieve 'format' arg\n"); 287 topo_mod_free(mod, order, BUFSZ); 288 /* topo errno already set */ 289 return (-1); 290 } 291 292 chip = topo_node_parent(topo_node_parent(node)); 293 294 if (strcasecmp(order, "forward") == 0) 295 /* LINTED: E_SEC_PRINTF_VAR_FMT */ 296 (void) snprintf(buf, BUFSZ, fmtstr, ((topo_node_instance(node)) 297 + (topo_node_instance(chip) * 4) + offset)); 298 else if (strcasecmp(order, "reverse") == 0) 299 /* LINTED: E_SEC_PRINTF_VAR_FMT */ 300 (void) snprintf(buf, BUFSZ, fmtstr, 301 (((topo_node_instance(chip) + 1) * 4) 302 - (topo_node_instance(node)) - 1 + offset)); 303 else { 304 topo_mod_dprintf(mod, "Invalid value for order arg\n"); 305 topo_mod_free(mod, order, BUFSZ); 306 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 307 } 308 309 if (store_prop_val(mod, buf, "label", out) != 0) { 310 topo_mod_dprintf(mod, "Failed to set label\n"); 311 topo_mod_free(mod, order, BUFSZ); 312 /* topo errno already set */ 313 return (-1); 314 } 315 316 return (0); 317 } 318 319 320 /* 321 * This is a somewhat generic property method for labelling the CPU sockets on 322 * x86/x64 platforms. This method assumes a correspondence between 323 * the chip topo node instance number and the CPU socket label number. It takes 324 * the following two arguments: 325 * 326 * format: a string containing a printf-like format with a single %d token 327 * which this method computes 328 * 329 * i.e.: CPU %d 330 * 331 * offset: a numeric offset that we'll number the CPU's from. This is to 332 * allow for the fact that some systems number the CPU sockets 333 * from zero and others start from one (like the X4X00-M2 systems) 334 */ 335 /* ARGSUSED */ 336 int 337 simple_chip_label(topo_mod_t *mod, tnode_t *node, topo_version_t vers, 338 nvlist_t *in, nvlist_t **out) 339 { 340 char *fmtstr, buf[BUFSZ]; 341 int ret; 342 uint32_t offset; 343 nvlist_t *args; 344 345 topo_mod_dprintf(mod, "simple_chip_label() called\n"); 346 if ((ret = nvlist_lookup_nvlist(in, TOPO_PROP_ARGS, &args)) != 0) { 347 topo_mod_dprintf(mod, "Failed to lookup 'args' list (%s)\n", 348 strerror(ret)); 349 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 350 } 351 if ((ret = nvlist_lookup_uint32(args, "offset", &offset)) != 0) { 352 topo_mod_dprintf(mod, "Failed to lookup 'offset' arg (%s)\n", 353 strerror(ret)); 354 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 355 } 356 357 if ((fmtstr = get_fmtstr(mod, in)) == NULL) { 358 topo_mod_dprintf(mod, "Failed to retrieve 'format' arg\n"); 359 /* topo errno already set */ 360 return (-1); 361 } 362 363 /* LINTED: E_SEC_PRINTF_VAR_FMT */ 364 (void) snprintf(buf, BUFSZ, fmtstr, 365 (topo_node_instance(node) + offset)); 366 367 if (store_prop_val(mod, buf, "label", out) != 0) { 368 topo_mod_dprintf(mod, "Failed to set label\n"); 369 /* topo errno already set */ 370 return (-1); 371 } 372 373 return (0); 374 } 375 376 377 /* 378 * This is a custom property method for generating the CPU slot label for the 379 * Galaxy 4E/4F platforms. 380 * 381 * format: a string containing a printf-like format with a single %c token 382 * which this method computes 383 * 384 * i.e.: CPU %c 385 */ 386 /* ARGSUSED */ 387 int 388 g4_chip_label(topo_mod_t *mod, tnode_t *node, topo_version_t vers, 389 nvlist_t *in, nvlist_t **out) 390 { 391 char *fmtstr, buf[BUFSZ], slot_id; 392 int err, htid, mapidx; 393 uint32_t num_nodes; 394 /* 395 * G4 HT node ID to FRU label translation. The g4map array 396 * is indexed by (number of coherent nodes) / 2 - 1. 397 * The value for a given number of nodes is a char array 398 * indexed by node ID. 399 */ 400 const char *g4map[] = { 401 "AB", /* 2 nodes */ 402 "ADEH", /* 4 nodes */ 403 "ABDEFH", /* 6 nodes */ 404 "ACBDEFGH" /* 8 nodes */ 405 }; 406 407 topo_mod_dprintf(mod, "g4_chip_label() called\n"); 408 if ((fmtstr = get_fmtstr(mod, in)) == NULL) { 409 topo_mod_dprintf(mod, "Failed to retrieve 'format' arg\n"); 410 /* topo errno already set */ 411 return (-1); 412 } 413 /* 414 * The chip-properties property will not exist if this platform has 415 * AMD family 0x10 modules. In that case we don't want to treat it as a 416 * fatal error as that will cause calls like topo_prop_getprops to fail 417 * to return any properties on this node. Therefore, if the topo errno 418 * is set to ETOPO_PROP_NOENT, then we'll just set an empty label 419 * and return 0. If the topo errno is set to anything else we'll 420 * return -1. 421 */ 422 if (topo_prop_get_uint32(node, "chip-properties", "CoherentNodes", 423 &num_nodes, &err) != 0) { 424 if (err == ETOPO_PROP_NOENT) { 425 if (store_prop_val(mod, "", "label", out) != 0) { 426 topo_mod_dprintf(mod, "Failed to set label\n"); 427 /* topo errno already set */ 428 return (-1); 429 } 430 return (0); 431 } else { 432 topo_mod_dprintf(mod, "Failed to lookup 'CoherentNodes'" 433 "property\n"); 434 return (topo_mod_seterrno(mod, err)); 435 } 436 } 437 438 mapidx = num_nodes / 2 - 1; 439 htid = topo_node_instance(node); 440 441 /* HT nodes must number 0 .. num_nodes - 1 */ 442 if (htid >= num_nodes) { 443 topo_mod_dprintf(mod, "chip node instance range check failed:" 444 "num_nodes=%d, instance=%d\n", num_nodes, htid); 445 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 446 } 447 448 switch (num_nodes) { 449 case (2): 450 case (4): 451 case (6): 452 case (8): 453 /* htid is already range-checked */ 454 mapidx = num_nodes / 2 - 1; 455 slot_id = g4map[mapidx][htid]; 456 break; 457 default: 458 topo_mod_dprintf(mod, "Invalid number of CoherentNodes:" 459 " %d\n", num_nodes); 460 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 461 } 462 463 /* LINTED: E_SEC_PRINTF_VAR_FMT */ 464 (void) snprintf(buf, BUFSZ, fmtstr, slot_id); 465 466 if (store_prop_val(mod, buf, "label", out) != 0) { 467 topo_mod_dprintf(mod, "Failed to set label\n"); 468 /* topo errno already set */ 469 return (-1); 470 } 471 472 return (0); 473 } 474 475 /* 476 * Utility function used by a4fplus_chip_label to determine the number of chips 477 * (as opposed to processors) that are installed in the system by dividing the 478 * number of installed processors (cores) by the number of cores per chip 479 * (from kstat). This assumes that an an A4F+ blade won't have some weird 480 * configuration of mixed chip models with differing numbers of cores per chip, 481 * which I think is a relatively safe assumption here. 482 */ 483 static int 484 get_num_chips(topo_mod_t *mod) 485 { 486 kstat_t *ksp; 487 kstat_ctl_t *kctl; 488 kstat_named_t *k; 489 490 if ((kctl = kstat_open()) == NULL) { 491 topo_mod_dprintf(mod, NULL, "kstat_open failed (%s)\n", 492 strerror(errno)); 493 return (-1); 494 } 495 if ((ksp = kstat_lookup(kctl, "cpu_info", -1, NULL)) == NULL) { 496 topo_mod_dprintf(mod, NULL, "kstat_lookup failed (%s)\n", 497 strerror(errno)); 498 (void) kstat_close(kctl); 499 return (-1); 500 } 501 if (kstat_read(kctl, ksp, NULL) < 0) { 502 topo_mod_dprintf(mod, NULL, "kstat_read failed (%s)\n", 503 strerror(errno)); 504 (void) kstat_close(kctl); 505 return (-1); 506 } 507 if ((k = kstat_data_lookup(ksp, "ncore_per_chip")) == NULL) { 508 topo_mod_dprintf(mod, NULL, "kstat_data_lookup failed (%s)\n", 509 strerror(errno)); 510 (void) kstat_close(kctl); 511 return (-1); 512 } 513 (void) kstat_close(kctl); 514 return (sysconf(_SC_NPROCESSORS_CONF) / k->value.l); 515 } 516 517 /* 518 * This is a custom property method for generating the CPU slot label for the 519 * Andromeda Fplus platforms. 520 * 521 * format: a string containing a printf-like format with a single %d token 522 * which this method computes 523 * 524 * i.e.: CPU %d 525 */ 526 /* ARGSUSED */ 527 int 528 a4fplus_chip_label(topo_mod_t *mod, tnode_t *node, topo_version_t vers, 529 nvlist_t *in, nvlist_t **out) 530 { 531 char *fmtstr, buf[BUFSZ]; 532 int num_nodes; 533 534 topo_mod_dprintf(mod, "a4fplus_chip_label() called\n"); 535 if ((fmtstr = get_fmtstr(mod, in)) == NULL) { 536 topo_mod_dprintf(mod, "Failed to retrieve 'format' arg\n"); 537 /* topo errno already set */ 538 return (-1); 539 } 540 541 /* 542 * Normally we'd figure out the total number of chip nodes by looking 543 * at the CoherentNodes property. However, due to the lack of a memory 544 * controller driver for family 0x10, this property wont exist on the 545 * chip nodes on A4Fplus. 546 */ 547 if ((num_nodes = get_num_chips(mod)) < 0) { 548 topo_mod_dprintf(mod, "Failed to determine number of chip " 549 "nodes\n"); 550 return (topo_mod_seterrno(mod, EMOD_UNKNOWN)); 551 } 552 switch (num_nodes) { 553 case (2): 554 /* LINTED: E_SEC_PRINTF_VAR_FMT */ 555 (void) snprintf(buf, BUFSZ, fmtstr, 556 topo_node_instance(node) + 2); 557 break; 558 case (4): 559 /* LINTED: E_SEC_PRINTF_VAR_FMT */ 560 (void) snprintf(buf, BUFSZ, fmtstr, 561 topo_node_instance(node)); 562 break; 563 default: 564 topo_mod_dprintf(mod, "Invalid number of chip nodes:" 565 " %d\n", num_nodes); 566 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 567 } 568 569 570 if (store_prop_val(mod, buf, "label", out) != 0) { 571 topo_mod_dprintf(mod, "Failed to set label\n"); 572 /* topo errno already set */ 573 return (-1); 574 } 575 576 return (0); 577 } 578 579 /* 580 * This is a somewhat generic property method for labelling the chip-select 581 * nodes on multi-socket AMD family 0x10 platforms. This is necessary because 582 * these platforms are not supported by the current AMD memory controller driver 583 * and therefore we're not able to discover the memory topology on AMD family 584 * 0x10 systems. As a result, instead of enumerating the installed dimms and 585 * their ranks, the chip enumerator generically enumerates all of the possible 586 * chip-selects beneath each dram channel. 587 * 588 * When we diagnose a dimm fault, the FRU fmri will be for the chip-select node, 589 * so we need to attach FRU labels to the chip-select nodes. 590 * 591 * format: a string containing a printf-like format with a two %d tokens 592 * for the cpu and dimm slot label numbers, which this method 593 * computes 594 * 595 * i.e.: CPU %d DIMM %d 596 * 597 * offset: a numeric offset that we'll number the dimms from. This is to 598 * allow for the fact that some systems may number the dimm slots 599 * from zero while others may start from one 600 * 601 * This function computes the DIMM slot number using the following formula: 602 * 603 * slot = cs - (cs % 2) + channel + offset 604 */ 605 /* ARGSUSED */ 606 int 607 simple_cs_label_mp(topo_mod_t *mod, tnode_t *node, topo_version_t vers, 608 nvlist_t *in, nvlist_t **out) 609 { 610 char *fmtstr, buf[BUFSZ]; 611 tnode_t *chip, *chan; 612 int dimm_num, ret; 613 uint32_t offset; 614 nvlist_t *args; 615 616 topo_mod_dprintf(mod, "simple_cs_label_mp() called\n"); 617 618 if ((ret = nvlist_lookup_nvlist(in, TOPO_PROP_ARGS, &args)) != 0) { 619 topo_mod_dprintf(mod, "Failed to lookup 'args' list (%s)\n", 620 strerror(ret)); 621 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 622 } 623 if ((ret = nvlist_lookup_uint32(args, "offset", &offset)) != 0) { 624 topo_mod_dprintf(mod, "Failed to lookup 'offset' arg (%s)\n", 625 strerror(ret)); 626 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 627 } 628 if ((fmtstr = get_fmtstr(mod, in)) == NULL) { 629 topo_mod_dprintf(mod, "Failed to retrieve 'format' arg\n"); 630 /* topo errno already set */ 631 return (-1); 632 } 633 634 chip = topo_node_parent(topo_node_parent(topo_node_parent(node))); 635 chan = topo_node_parent(node); 636 637 dimm_num = topo_node_instance(node) - (topo_node_instance(node) % 2) 638 + topo_node_instance(chan) + offset; 639 /* LINTED: E_SEC_PRINTF_VAR_FMT */ 640 (void) snprintf(buf, BUFSZ, fmtstr, topo_node_instance(chip), 641 dimm_num); 642 643 if (store_prop_val(mod, buf, "label", out) != 0) { 644 topo_mod_dprintf(mod, "Failed to set label\n"); 645 /* topo errno already set */ 646 return (-1); 647 } 648 649 return (0); 650 } 651 652 /* ARGSUSED */ 653 int 654 g4_dimm_label(topo_mod_t *mod, tnode_t *node, topo_version_t vers, 655 nvlist_t *in, nvlist_t **out) 656 { 657 char *fmtstr, *chip_lbl, buf[BUFSZ]; 658 tnode_t *chip; 659 int ret, err = 0; 660 uint32_t offset; 661 nvlist_t *args; 662 663 topo_mod_dprintf(mod, "g4_dimm_label() called\n"); 664 665 if ((ret = nvlist_lookup_nvlist(in, TOPO_PROP_ARGS, &args)) != 0) { 666 topo_mod_dprintf(mod, "Failed to lookup 'args' list (%s)\n", 667 strerror(ret)); 668 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 669 } 670 if ((ret = nvlist_lookup_uint32(args, "offset", &offset)) != 0) { 671 topo_mod_dprintf(mod, "Failed to lookup 'offset' arg (%s)\n", 672 strerror(ret)); 673 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 674 } 675 if ((fmtstr = get_fmtstr(mod, in)) == NULL) { 676 topo_mod_dprintf(mod, "Failed to retrieve 'format' arg\n"); 677 /* topo errno already set */ 678 return (-1); 679 } 680 681 /* 682 * The 4600/4600M2 have a weird way of labeling the chip nodes, so 683 * instead of trying to recompute it, we'll simply look it up and 684 * prepend it to our dimm label. 685 */ 686 chip = topo_node_parent(topo_node_parent(node)); 687 if (topo_prop_get_string(chip, TOPO_PGROUP_PROTOCOL, "label", &chip_lbl, 688 &err) != 0) { 689 topo_mod_dprintf(mod, "Failed to lookup label prop on %s=%d\n", 690 topo_node_name(chip), topo_node_instance(chip), 691 topo_strerror(err)); 692 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 693 } 694 695 /* LINTED: E_SEC_PRINTF_VAR_FMT */ 696 (void) snprintf(buf, BUFSZ, fmtstr, chip_lbl, 697 (topo_node_instance(node) + offset)); 698 699 topo_mod_strfree(mod, chip_lbl); 700 701 if (store_prop_val(mod, buf, "label", out) != 0) { 702 topo_mod_dprintf(mod, "Failed to set label\n"); 703 /* topo errno already set */ 704 return (-1); 705 } 706 707 return (0); 708 } 709 710 /* 711 * This method is used to compute the labels for DIMM slots on the Galaxy 1F and 712 * 2F platforms. It results in following dimm node label assignments: 713 * 714 * chip/dimm instances label 715 * ------------------- ----- 716 * chip=0/dimm=0 CPU 1 DIMM A0 717 * chip=0/dimm=1 CPU 1 DIMM B0 718 * chip=0/dimm=2 CPU 1 DIMM A1 719 * chip=0/dimm=3 CPU 1 DIMM B1 720 * 721 * chip=1/dimm=0 CPU 2 DIMM A0 722 * chip=1/dimm=1 CPU 2 DIMM B0 723 * chip=1/dimm=2 CPU 2 DIMM A1 724 * chip=1/dimm=3 CPU 2 DIMM B1 725 */ 726 /* ARGSUSED */ 727 int 728 g12f_dimm_label(topo_mod_t *mod, tnode_t *node, topo_version_t vers, 729 nvlist_t *in, nvlist_t **out) 730 { 731 char *fmtstr, buf[BUFSZ], chan; 732 tnode_t *chip; 733 int ret, dimm_inst, slot_num; 734 nvlist_t *args; 735 736 topo_mod_dprintf(mod, "g12f_dimm_label() called\n"); 737 738 if ((ret = nvlist_lookup_nvlist(in, TOPO_PROP_ARGS, &args)) != 0) { 739 topo_mod_dprintf(mod, "Failed to lookup 'args' list (%s)\n", 740 strerror(ret)); 741 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 742 } 743 if ((fmtstr = get_fmtstr(mod, in)) == NULL) { 744 topo_mod_dprintf(mod, "Failed to retrieve 'format' arg\n"); 745 /* topo errno already set */ 746 return (-1); 747 } 748 749 chip = topo_node_parent(topo_node_parent(node)); 750 dimm_inst = topo_node_instance(node); 751 chan = dimm_inst == 0 || dimm_inst == 2 ? 'A': 'B'; 752 slot_num = (dimm_inst <= 1 ? 0 : 1); 753 754 /* LINTED: E_SEC_PRINTF_VAR_FMT */ 755 (void) snprintf(buf, BUFSZ, fmtstr, topo_node_instance(chip) + 1, chan, 756 slot_num); 757 758 if (store_prop_val(mod, buf, "label", out) != 0) { 759 topo_mod_dprintf(mod, "Failed to set label\n"); 760 /* topo errno already set */ 761 return (-1); 762 } 763 764 return (0); 765 } 766