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 #include <stdio.h> 28 #include <stdlib.h> 29 #include <stdarg.h> 30 #include <string.h> 31 #include <strings.h> 32 #include <libnvpair.h> 33 #include <kstat.h> 34 #include <unistd.h> 35 #include <sys/types.h> 36 #include <fm/topo_mod.h> 37 #include <sys/devfm.h> 38 #include <fm/fmd_agent.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 counting 478 * the unique chipids. 479 */ 480 static int 481 get_num_chips(topo_mod_t *mod) 482 { 483 fmd_agent_hdl_t *hdl; 484 nvlist_t **cpus; 485 uint_t ncpu; 486 int i, nchip = 0; 487 int32_t chipid; 488 uint64_t bitmap = 0; 489 490 if ((hdl = fmd_agent_open(FMD_AGENT_VERSION)) == NULL) 491 return (-1); 492 if (fmd_agent_physcpu_info(hdl, &cpus, &ncpu) == -1) { 493 topo_mod_dprintf(mod, "get physcpu info failed:%s\n", 494 fmd_agent_errmsg(hdl)); 495 fmd_agent_close(hdl); 496 return (-1); 497 } 498 fmd_agent_close(hdl); 499 500 for (i = 0; i < ncpu; i++) { 501 if (nvlist_lookup_int32(cpus[i], FM_PHYSCPU_INFO_CHIP_ID, 502 &chipid) != 0 || chipid >= 64) { 503 topo_mod_dprintf(mod, "lookup chipid failed\n"); 504 nchip = -1; 505 break; 506 } 507 if ((bitmap & (1 << chipid)) != 0) { 508 bitmap |= (1 << chipid); 509 nchip++; 510 } 511 } 512 513 for (i = 0; i < ncpu; i++) 514 nvlist_free(cpus[i]); 515 umem_free(cpus, sizeof (nvlist_t *) * ncpu); 516 517 return (nchip); 518 } 519 520 /* 521 * This is a custom property method for generating the CPU slot label for the 522 * Andromeda Fplus platforms. 523 * 524 * format: a string containing a printf-like format with a single %d token 525 * which this method computes 526 * 527 * i.e.: CPU %d 528 */ 529 /* ARGSUSED */ 530 int 531 a4fplus_chip_label(topo_mod_t *mod, tnode_t *node, topo_version_t vers, 532 nvlist_t *in, nvlist_t **out) 533 { 534 char *fmtstr, buf[BUFSZ]; 535 int num_nodes; 536 537 topo_mod_dprintf(mod, "a4fplus_chip_label() called\n"); 538 if ((fmtstr = get_fmtstr(mod, in)) == NULL) { 539 topo_mod_dprintf(mod, "Failed to retrieve 'format' arg\n"); 540 /* topo errno already set */ 541 return (-1); 542 } 543 544 /* 545 * Normally we'd figure out the total number of chip nodes by looking 546 * at the CoherentNodes property. However, due to the lack of a memory 547 * controller driver for family 0x10, this property wont exist on the 548 * chip nodes on A4Fplus. 549 */ 550 if ((num_nodes = get_num_chips(mod)) < 0) { 551 topo_mod_dprintf(mod, "Failed to determine number of chip " 552 "nodes\n"); 553 return (topo_mod_seterrno(mod, EMOD_UNKNOWN)); 554 } 555 switch (num_nodes) { 556 case (2): 557 /* LINTED: E_SEC_PRINTF_VAR_FMT */ 558 (void) snprintf(buf, BUFSZ, fmtstr, 559 topo_node_instance(node) + 2); 560 break; 561 case (4): 562 /* LINTED: E_SEC_PRINTF_VAR_FMT */ 563 (void) snprintf(buf, BUFSZ, fmtstr, 564 topo_node_instance(node)); 565 break; 566 default: 567 topo_mod_dprintf(mod, "Invalid number of chip nodes:" 568 " %d\n", num_nodes); 569 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 570 } 571 572 573 if (store_prop_val(mod, buf, "label", out) != 0) { 574 topo_mod_dprintf(mod, "Failed to set label\n"); 575 /* topo errno already set */ 576 return (-1); 577 } 578 579 return (0); 580 } 581 582 /* 583 * This is a somewhat generic property method for labelling the chip-select 584 * nodes on multi-socket AMD family 0x10 platforms. This is necessary because 585 * these platforms are not supported by the current AMD memory controller driver 586 * and therefore we're not able to discover the memory topology on AMD family 587 * 0x10 systems. As a result, instead of enumerating the installed dimms and 588 * their ranks, the chip enumerator generically enumerates all of the possible 589 * chip-selects beneath each dram channel. 590 * 591 * When we diagnose a dimm fault, the FRU fmri will be for the chip-select node, 592 * so we need to attach FRU labels to the chip-select nodes. 593 * 594 * format: a string containing a printf-like format with a two %d tokens 595 * for the cpu and dimm slot label numbers, which this method 596 * computes 597 * 598 * i.e.: CPU %d DIMM %d 599 * 600 * offset: a numeric offset that we'll number the dimms from. This is to 601 * allow for the fact that some systems may number the dimm slots 602 * from zero while others may start from one 603 * 604 * This function computes the DIMM slot number using the following formula: 605 * 606 * slot = cs - (cs % 2) + channel + offset 607 */ 608 /* ARGSUSED */ 609 int 610 simple_cs_label_mp(topo_mod_t *mod, tnode_t *node, topo_version_t vers, 611 nvlist_t *in, nvlist_t **out) 612 { 613 char *fmtstr, buf[BUFSZ]; 614 tnode_t *chip, *chan; 615 int dimm_num, ret; 616 uint32_t offset; 617 nvlist_t *args; 618 619 topo_mod_dprintf(mod, "simple_cs_label_mp() called\n"); 620 621 if ((ret = nvlist_lookup_nvlist(in, TOPO_PROP_ARGS, &args)) != 0) { 622 topo_mod_dprintf(mod, "Failed to lookup 'args' list (%s)\n", 623 strerror(ret)); 624 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 625 } 626 if ((ret = nvlist_lookup_uint32(args, "offset", &offset)) != 0) { 627 topo_mod_dprintf(mod, "Failed to lookup 'offset' arg (%s)\n", 628 strerror(ret)); 629 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 630 } 631 if ((fmtstr = get_fmtstr(mod, in)) == NULL) { 632 topo_mod_dprintf(mod, "Failed to retrieve 'format' arg\n"); 633 /* topo errno already set */ 634 return (-1); 635 } 636 637 chip = topo_node_parent(topo_node_parent(topo_node_parent(node))); 638 chan = topo_node_parent(node); 639 640 dimm_num = topo_node_instance(node) - (topo_node_instance(node) % 2) 641 + topo_node_instance(chan) + offset; 642 /* LINTED: E_SEC_PRINTF_VAR_FMT */ 643 (void) snprintf(buf, BUFSZ, fmtstr, topo_node_instance(chip), 644 dimm_num); 645 646 if (store_prop_val(mod, buf, "label", out) != 0) { 647 topo_mod_dprintf(mod, "Failed to set label\n"); 648 /* topo errno already set */ 649 return (-1); 650 } 651 652 return (0); 653 } 654 655 /* ARGSUSED */ 656 int 657 g4_dimm_label(topo_mod_t *mod, tnode_t *node, topo_version_t vers, 658 nvlist_t *in, nvlist_t **out) 659 { 660 char *fmtstr, *chip_lbl, buf[BUFSZ]; 661 tnode_t *chip; 662 int ret, err = 0; 663 uint32_t offset; 664 nvlist_t *args; 665 666 topo_mod_dprintf(mod, "g4_dimm_label() called\n"); 667 668 if ((ret = nvlist_lookup_nvlist(in, TOPO_PROP_ARGS, &args)) != 0) { 669 topo_mod_dprintf(mod, "Failed to lookup 'args' list (%s)\n", 670 strerror(ret)); 671 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 672 } 673 if ((ret = nvlist_lookup_uint32(args, "offset", &offset)) != 0) { 674 topo_mod_dprintf(mod, "Failed to lookup 'offset' arg (%s)\n", 675 strerror(ret)); 676 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 677 } 678 if ((fmtstr = get_fmtstr(mod, in)) == NULL) { 679 topo_mod_dprintf(mod, "Failed to retrieve 'format' arg\n"); 680 /* topo errno already set */ 681 return (-1); 682 } 683 684 /* 685 * The 4600/4600M2 have a weird way of labeling the chip nodes, so 686 * instead of trying to recompute it, we'll simply look it up and 687 * prepend it to our dimm label. 688 */ 689 chip = topo_node_parent(topo_node_parent(node)); 690 if (topo_prop_get_string(chip, TOPO_PGROUP_PROTOCOL, "label", &chip_lbl, 691 &err) != 0) { 692 topo_mod_dprintf(mod, "Failed to lookup label prop on %s=%d\n", 693 topo_node_name(chip), topo_node_instance(chip), 694 topo_strerror(err)); 695 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 696 } 697 698 /* LINTED: E_SEC_PRINTF_VAR_FMT */ 699 (void) snprintf(buf, BUFSZ, fmtstr, chip_lbl, 700 (topo_node_instance(node) + offset)); 701 702 topo_mod_strfree(mod, chip_lbl); 703 704 if (store_prop_val(mod, buf, "label", out) != 0) { 705 topo_mod_dprintf(mod, "Failed to set label\n"); 706 /* topo errno already set */ 707 return (-1); 708 } 709 710 return (0); 711 } 712 713 /* 714 * This method is used to compute the labels for DIMM slots on the Galaxy 1F and 715 * 2F platforms. It results in following dimm node label assignments: 716 * 717 * chip/dimm instances label 718 * ------------------- ----- 719 * chip=0/dimm=0 CPU 1 DIMM A0 720 * chip=0/dimm=1 CPU 1 DIMM B0 721 * chip=0/dimm=2 CPU 1 DIMM A1 722 * chip=0/dimm=3 CPU 1 DIMM B1 723 * 724 * chip=1/dimm=0 CPU 2 DIMM A0 725 * chip=1/dimm=1 CPU 2 DIMM B0 726 * chip=1/dimm=2 CPU 2 DIMM A1 727 * chip=1/dimm=3 CPU 2 DIMM B1 728 */ 729 /* ARGSUSED */ 730 int 731 g12f_dimm_label(topo_mod_t *mod, tnode_t *node, topo_version_t vers, 732 nvlist_t *in, nvlist_t **out) 733 { 734 char *fmtstr, buf[BUFSZ], chan; 735 tnode_t *chip; 736 int ret, dimm_inst, slot_num; 737 nvlist_t *args; 738 739 topo_mod_dprintf(mod, "g12f_dimm_label() called\n"); 740 741 if ((ret = nvlist_lookup_nvlist(in, TOPO_PROP_ARGS, &args)) != 0) { 742 topo_mod_dprintf(mod, "Failed to lookup 'args' list (%s)\n", 743 strerror(ret)); 744 return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); 745 } 746 if ((fmtstr = get_fmtstr(mod, in)) == NULL) { 747 topo_mod_dprintf(mod, "Failed to retrieve 'format' arg\n"); 748 /* topo errno already set */ 749 return (-1); 750 } 751 752 chip = topo_node_parent(topo_node_parent(node)); 753 dimm_inst = topo_node_instance(node); 754 chan = dimm_inst == 0 || dimm_inst == 2 ? 'A': 'B'; 755 slot_num = (dimm_inst <= 1 ? 0 : 1); 756 757 /* LINTED: E_SEC_PRINTF_VAR_FMT */ 758 (void) snprintf(buf, BUFSZ, fmtstr, topo_node_instance(chip) + 1, chan, 759 slot_num); 760 761 if (store_prop_val(mod, buf, "label", out) != 0) { 762 topo_mod_dprintf(mod, "Failed to set label\n"); 763 /* topo errno already set */ 764 return (-1); 765 } 766 767 return (0); 768 } 769