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, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2005 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 <sys/ib/ibtl/impl/ibtl.h> 30 #include <sys/ib/ibtl/impl/ibtl_cm.h> 31 32 /* 33 * ibtl_cm.c 34 * These routines tie the Communication Manager into IBTL. 35 */ 36 37 /* 38 * Globals. 39 */ 40 static char ibtf_cm[] = "ibtl_cm"; 41 boolean_t ibtl_fast_gid_cache_valid = B_FALSE; 42 43 /* 44 * Function: 45 * ibtl_cm_set_chan_private 46 * Input: 47 * chan Channel Handle. 48 * cm_private CM private data. 49 * Output: 50 * none. 51 * Returns: 52 * none. 53 * Description: 54 * A helper function to store CM's Private data in the specified channel. 55 */ 56 void 57 ibtl_cm_set_chan_private(ibt_channel_hdl_t chan, void *cm_private) 58 { 59 IBTF_DPRINTF_L3(ibtf_cm, "ibtl_cm_set_chan_private(%p, %p)", 60 chan, cm_private); 61 62 mutex_enter(&chan->ch_cm_mutex); 63 chan->ch_cm_private = cm_private; 64 if (cm_private == NULL) 65 cv_signal(&chan->ch_cm_cv); 66 mutex_exit(&chan->ch_cm_mutex); 67 } 68 69 70 /* 71 * Function: 72 * ibtl_cm_get_chan_private 73 * Input: 74 * chan Channel Handle. 75 * Output: 76 * cm_private_p The CM private data. 77 * Returns: 78 * CM private data. 79 * Description: 80 * A helper function to get CM's Private data for the specified channel. 81 */ 82 void * 83 ibtl_cm_get_chan_private(ibt_channel_hdl_t chan) 84 { 85 void *cm_private; 86 87 IBTF_DPRINTF_L3(ibtf_cm, "ibtl_cm_get_chan_private(%p)", chan); 88 mutex_enter(&chan->ch_cm_mutex); 89 cm_private = chan->ch_cm_private; 90 #ifndef __lock_lint 91 /* IBCM will call the release function if cm_private is non-NULL */ 92 if (cm_private == NULL) 93 #endif 94 mutex_exit(&chan->ch_cm_mutex); 95 return (cm_private); 96 } 97 98 void 99 ibtl_cm_release_chan_private(ibt_channel_hdl_t chan) 100 { 101 #ifndef __lock_lint 102 mutex_exit(&chan->ch_cm_mutex); 103 #endif 104 } 105 106 void 107 ibtl_cm_wait_chan_private(ibt_channel_hdl_t chan) 108 { 109 mutex_enter(&chan->ch_cm_mutex); 110 if (chan->ch_cm_private != NULL) 111 cv_wait(&chan->ch_cm_cv, &chan->ch_cm_mutex); 112 mutex_exit(&chan->ch_cm_mutex); 113 delay(drv_usectohz(50000)); 114 } 115 116 117 /* 118 * Function: 119 * ibtl_cm_get_chan_type 120 * Input: 121 * chan Channel Handle. 122 * Output: 123 * none. 124 * Returns: 125 * Channel transport type. 126 * Description: 127 * A helper function to get channel transport type. 128 */ 129 ibt_tran_srv_t 130 ibtl_cm_get_chan_type(ibt_channel_hdl_t chan) 131 { 132 IBTF_DPRINTF_L3(ibtf_cm, "ibtl_cm_get_chan_type(%p)", chan); 133 134 return (chan->ch_qp.qp_type); 135 } 136 137 /* 138 * Function: 139 * ibtl_cm_change_service_cnt 140 * Input: 141 * ibt_hdl Client's IBT Handle. 142 * delta_num_sids The change in the number of service ids 143 * (positive for ibt_register_service() and 144 * negative fo ibt_service_deregister()). 145 */ 146 void 147 ibtl_cm_change_service_cnt(ibt_clnt_hdl_t ibt_hdl, int delta_num_sids) 148 { 149 IBTF_DPRINTF_L3(ibtf_cm, "ibtl_cm_change_service_cnt(%p. %d)", 150 ibt_hdl, delta_num_sids); 151 152 mutex_enter(&ibtl_clnt_list_mutex); 153 if ((delta_num_sids < 0) && (-delta_num_sids > ibt_hdl->clnt_srv_cnt)) { 154 IBTF_DPRINTF_L2(ibtf_cm, "ibtl_cm_change_service_cnt: " 155 "ERROR: service registration counter underflow\n" 156 "current count = %d, requested delta = %d", 157 ibt_hdl->clnt_srv_cnt, delta_num_sids); 158 } 159 ibt_hdl->clnt_srv_cnt += delta_num_sids; 160 mutex_exit(&ibtl_clnt_list_mutex); 161 } 162 163 164 /* 165 * Function: 166 * ibtl_cm_get_hca_port 167 * Input: 168 * gid Source GID. 169 * hca_guid Optional source HCA GUID on which SGID is available. 170 * Ignored if zero. 171 * Output: 172 * hca_port Pointer to ibtl_cm_hca_port_t struct. 173 * Returns: 174 * IBT_SUCCESS. 175 * Description: 176 * A helper function to get HCA node GUID, Base LID, SGID Index, 177 * port number, LMC and MTU for the specified SGID. 178 * Also filling default SGID, to be used in ibmf_sa_session_open. 179 */ 180 ibt_status_t 181 ibtl_cm_get_hca_port(ib_gid_t gid, ib_guid_t hca_guid, 182 ibtl_cm_hca_port_t *hca_port) 183 { 184 ibtl_hca_devinfo_t *hca_devp; /* HCA Dev Info */ 185 ibt_hca_portinfo_t *portinfop; 186 uint_t ports, port; 187 uint_t i; 188 ib_gid_t *sgid; 189 static ib_gid_t fast_gid; /* fast_gid_cache data */ 190 static uint8_t fast_sgid_ix; 191 static ibt_hca_portinfo_t *fast_portinfop; 192 static ib_guid_t fast_node_guid; 193 static ib_guid_t fast_port_guid; 194 195 IBTF_DPRINTF_L3(ibtf_cm, "ibtl_cm_get_hca_port(%llX:%llX, %llX)", 196 gid.gid_prefix, gid.gid_guid, hca_guid); 197 198 if ((gid.gid_prefix == 0) || (gid.gid_guid == 0)) { 199 IBTF_DPRINTF_L2(ibtf_cm, "ibtl_cm_get_hca_port: " 200 "NULL SGID specified."); 201 return (IBT_INVALID_PARAM); 202 } 203 204 mutex_enter(&ibtl_clnt_list_mutex); 205 206 if ((ibtl_fast_gid_cache_valid == B_TRUE) && 207 (gid.gid_guid == fast_gid.gid_guid) && 208 (gid.gid_prefix == fast_gid.gid_prefix)) { 209 210 if ((hca_guid != 0) && (hca_guid != fast_node_guid)) { 211 IBTF_DPRINTF_L3(ibtf_cm, "ibtl_cm_get_hca_port: " 212 "Mis-match hca_guid v/s sgid combination."); 213 mutex_exit(&ibtl_clnt_list_mutex); 214 return (IBT_INVALID_PARAM); 215 } 216 217 portinfop = fast_portinfop; 218 hca_port->hp_base_lid = portinfop->p_base_lid; 219 hca_port->hp_port = portinfop->p_port_num; 220 hca_port->hp_sgid_ix = fast_sgid_ix; 221 hca_port->hp_lmc = portinfop->p_lmc; 222 hca_port->hp_mtu = portinfop->p_mtu; 223 hca_port->hp_hca_guid = fast_node_guid; 224 hca_port->hp_port_guid = fast_port_guid; 225 226 mutex_exit(&ibtl_clnt_list_mutex); 227 228 return (IBT_SUCCESS); 229 } 230 231 /* If HCA GUID is specified, then lookup in that device only. */ 232 if (hca_guid) { 233 hca_devp = ibtl_get_hcadevinfo(hca_guid); 234 } else { 235 hca_devp = ibtl_hca_list; 236 } 237 238 while (hca_devp != NULL) { 239 240 ports = hca_devp->hd_hca_attr->hca_nports; 241 portinfop = hca_devp->hd_portinfop; 242 243 for (port = 0; port < ports; port++, portinfop++) { 244 if (portinfop->p_linkstate != IBT_PORT_ACTIVE) 245 continue; 246 sgid = &portinfop->p_sgid_tbl[0]; 247 for (i = 0; i < portinfop->p_sgid_tbl_sz; i++, sgid++) { 248 if ((gid.gid_guid != sgid->gid_guid) || 249 (gid.gid_prefix != sgid->gid_prefix)) 250 continue; 251 252 /* 253 * Found the matching GID. 254 */ 255 ibtl_fast_gid_cache_valid = B_TRUE; 256 fast_gid = gid; 257 fast_portinfop = portinfop; 258 fast_node_guid = hca_port->hp_hca_guid = 259 hca_devp->hd_hca_attr->hca_node_guid; 260 fast_sgid_ix = hca_port->hp_sgid_ix = i; 261 fast_port_guid = 262 portinfop->p_sgid_tbl[0].gid_guid; 263 hca_port->hp_port_guid = fast_port_guid; 264 hca_port->hp_base_lid = portinfop->p_base_lid; 265 hca_port->hp_port = portinfop->p_port_num; 266 hca_port->hp_lmc = portinfop->p_lmc; 267 hca_port->hp_mtu = portinfop->p_mtu; 268 269 mutex_exit(&ibtl_clnt_list_mutex); 270 271 return (IBT_SUCCESS); 272 } 273 } 274 275 /* Asked to look in the specified HCA device only?. */ 276 if (hca_guid) 277 break; 278 279 /* Get next in the list */ 280 hca_devp = hca_devp->hd_hca_dev_link; 281 } 282 283 mutex_exit(&ibtl_clnt_list_mutex); 284 285 /* If we are here, then we failed to get a match, so return error. */ 286 return (IBT_INVALID_PARAM); 287 } 288 289 290 static ibt_status_t 291 ibtl_cm_get_cnt(ibt_path_attr_t *attr, ibt_path_flags_t flags, 292 ibtl_cm_port_list_t *plistp, uint_t *count) 293 { 294 ibtl_hca_devinfo_t *hdevp; 295 ibt_hca_portinfo_t *pinfop; 296 ib_guid_t hca_guid, tmp_hca_guid = 0; 297 ib_gid_t gid; 298 uint_t pcount = 0; 299 uint_t cnt = *count; 300 ibt_status_t retval = IBT_SUCCESS; 301 uint_t i, j; 302 303 *count = 0; 304 305 /* If HCA GUID is specified, then lookup in that device only. */ 306 if (attr->pa_hca_guid) { 307 hdevp = ibtl_get_hcadevinfo(attr->pa_hca_guid); 308 } else { 309 hdevp = ibtl_hca_list; 310 } 311 312 while (hdevp != NULL) { 313 hca_guid = hdevp->hd_hca_attr->hca_node_guid; 314 315 if ((flags & IBT_PATH_APM) && 316 (!(hdevp->hd_hca_attr->hca_flags & 317 IBT_HCA_AUTO_PATH_MIG))) { 318 319 IBTF_DPRINTF_L2(ibtf_cm, "ibtl_cm_get_cnt: " 320 "HCA (%llX) - APM NOT SUPPORTED ", hca_guid); 321 322 retval = IBT_APM_NOT_SUPPORTED; 323 324 if (attr->pa_hca_guid) 325 break; 326 hdevp = hdevp->hd_hca_dev_link; 327 continue; 328 } 329 330 for (i = 0; i < hdevp->hd_hca_attr->hca_nports; i++) { 331 332 if ((attr->pa_hca_port_num) && 333 (attr->pa_hca_port_num != (i + 1))) { 334 IBTF_DPRINTF_L3(ibtf_cm, "ibtl_cm_get_cnt: " 335 "Asked only on Port# %d, so skip this " 336 "port(%d)", attr->pa_hca_port_num, (i + 1)); 337 continue; 338 } 339 pinfop = hdevp->hd_portinfop + i; 340 341 if (pinfop->p_linkstate != IBT_PORT_ACTIVE) { 342 retval = IBT_HCA_PORT_NOT_ACTIVE; 343 continue; 344 } 345 if (attr->pa_mtu.r_mtu) { 346 if ((attr->pa_mtu.r_selector == IBT_GT) && 347 (attr->pa_mtu.r_mtu >= pinfop->p_mtu)) 348 continue; 349 else if ((attr->pa_mtu.r_selector == IBT_EQU) && 350 (attr->pa_mtu.r_mtu > pinfop->p_mtu)) 351 continue; 352 } 353 354 for (j = 0; j < pinfop->p_sgid_tbl_sz; j++) { 355 gid = pinfop->p_sgid_tbl[j]; 356 if (gid.gid_prefix && gid.gid_guid) { 357 pcount++; 358 if (plistp) { 359 plistp->p_hca_guid = hca_guid; 360 plistp->p_mtu = pinfop->p_mtu; 361 plistp->p_base_lid = 362 pinfop->p_base_lid; 363 plistp->p_port_num = 364 pinfop->p_port_num; 365 plistp->p_sgid_ix = j; 366 plistp->p_sgid = gid; 367 plistp->p_count = cnt; 368 plistp->p_multism = 369 hdevp->hd_multism; 370 371 IBTF_DPRINTF_L3(ibtf_cm, 372 "ibtl_cm_get_cnt: HCA" 373 "(%llX,%d) SGID(%llX:%llX)", 374 plistp->p_hca_guid, 375 plistp->p_port_num, 376 plistp->p_sgid.gid_prefix, 377 plistp->p_sgid.gid_guid); 378 379 plistp++; 380 } 381 } 382 } 383 } 384 /* Asked to look in the specified HCA device only?. */ 385 if (attr->pa_hca_guid) 386 break; 387 388 if (flags & IBT_PATH_APM) { 389 if (pcount == 2) { 390 attr->pa_hca_guid = hca_guid; 391 break; 392 } else if (pcount == 1) { 393 if (hdevp->hd_hca_dev_link) { 394 tmp_hca_guid = hca_guid; 395 pcount = 0; 396 } else if (tmp_hca_guid) { 397 attr->pa_hca_guid = tmp_hca_guid; 398 } else { 399 attr->pa_hca_guid = hca_guid; 400 } 401 } 402 } 403 hdevp = hdevp->hd_hca_dev_link; 404 } 405 406 *count = pcount; 407 408 if (pcount) { 409 retval = IBT_SUCCESS; 410 } else { 411 IBTF_DPRINTF_L2(ibtf_cm, "ibtl_cm_get_cnt: " 412 "Appropriate Source Points NOT found"); 413 if (retval == IBT_SUCCESS) 414 retval = IBT_NO_HCAS_AVAILABLE; 415 } 416 417 return (retval); 418 } 419 420 421 ibt_status_t 422 ibtl_cm_get_active_plist(ibt_path_attr_t *attr, ibt_path_flags_t flags, 423 ibtl_cm_port_list_t **port_list_p) 424 { 425 ibtl_cm_port_list_t *p_listp, tmp; 426 uint_t i, j; 427 uint_t count, rcount; 428 ibt_status_t retval = IBT_SUCCESS; 429 430 IBTF_DPRINTF_L3(ibtf_cm, "ibtl_cm_get_active_plist(%p, %X)", 431 attr, flags); 432 433 get_plist_start: 434 *port_list_p = NULL; 435 436 /* Get "number of active src points" so that we can allocate memory. */ 437 mutex_enter(&ibtl_clnt_list_mutex); 438 retval = ibtl_cm_get_cnt(attr, flags, NULL, &count); 439 mutex_exit(&ibtl_clnt_list_mutex); 440 441 IBTF_DPRINTF_L3(ibtf_cm, "ibtl_cm_get_active_plist: Found %d SrcPoint", 442 count); 443 if (retval != IBT_SUCCESS) 444 return (retval); 445 446 /* Allocate Memory to hold Src Point information. */ 447 p_listp = kmem_zalloc(count * sizeof (ibtl_cm_port_list_t), KM_SLEEP); 448 449 /* 450 * Verify that the count we got previously is still valid, as we had 451 * dropped mutex to allocate memory. If not, restart the process. 452 */ 453 mutex_enter(&ibtl_clnt_list_mutex); 454 retval = ibtl_cm_get_cnt(attr, flags, NULL, &rcount); 455 if (retval != IBT_SUCCESS) { 456 mutex_exit(&ibtl_clnt_list_mutex); 457 kmem_free(p_listp, count * sizeof (ibtl_cm_port_list_t)); 458 return (retval); 459 } else if (rcount != count) { 460 mutex_exit(&ibtl_clnt_list_mutex); 461 kmem_free(p_listp, count * sizeof (ibtl_cm_port_list_t)); 462 goto get_plist_start; 463 } 464 465 *port_list_p = p_listp; 466 /* 467 * Src count hasn't changed, still holding the lock fill-in the 468 * required source point information. 469 */ 470 retval = ibtl_cm_get_cnt(attr, flags, p_listp, &rcount); 471 mutex_exit(&ibtl_clnt_list_mutex); 472 if (retval != IBT_SUCCESS) { 473 kmem_free(p_listp, count * sizeof (ibtl_cm_port_list_t)); 474 *port_list_p = NULL; 475 return (retval); 476 } 477 478 p_listp = *port_list_p; 479 480 _NOTE(NO_COMPETING_THREADS_NOW) 481 482 /* 483 * Sort (bubble sort) the list based on MTU quality (higher on top). 484 * Sorting is only performed, if IBT_PATH_AVAIL is set. 485 */ 486 if (((attr->pa_mtu.r_selector == IBT_GT) || (flags & IBT_PATH_AVAIL)) && 487 (!(flags & IBT_PATH_APM))) { 488 for (i = 0; i < count - 1; i++) { 489 for (j = 0; j < count - 1 - i; j++) { 490 if (p_listp[j].p_mtu < p_listp[j+1].p_mtu) { 491 tmp = p_listp[j]; 492 p_listp[j] = p_listp[j+1]; 493 p_listp[j+1] = tmp; 494 } 495 } 496 } 497 } 498 499 if ((flags & IBT_PATH_AVAIL) && (!(flags & IBT_PATH_APM))) { 500 /* Avoid having same HCA next to each other in the list. */ 501 for (i = 0; i < count - 1; i++) { 502 for (j = 0; j < (count - 1 - i); j++) { 503 if ((p_listp[j].p_hca_guid == 504 p_listp[j+1].p_hca_guid) && 505 (j+2 < count)) { 506 tmp = p_listp[j+1]; 507 p_listp[j+1] = p_listp[j+2]; 508 p_listp[j+2] = tmp; 509 } 510 } 511 } 512 } 513 514 /* 515 * If SGID is specified, then make sure that SGID info is first 516 * in the array. 517 */ 518 if (attr->pa_sgid.gid_guid && (p_listp->p_count > 1) && 519 (p_listp[0].p_sgid.gid_guid != attr->pa_sgid.gid_guid)) { 520 for (i = 1; i < count; i++) { 521 if (p_listp[i].p_sgid.gid_guid == 522 attr->pa_sgid.gid_guid) { 523 tmp = p_listp[i]; 524 p_listp[i] = p_listp[0]; 525 p_listp[0] = tmp; 526 } 527 } 528 } 529 530 _NOTE(COMPETING_THREADS_NOW) 531 532 IBTF_DPRINTF_L3(ibtf_cm, "ibtl_cm_get_active_plist: " 533 "Returned <%d> entries @0x%p", count, *port_list_p); 534 535 return (retval); 536 } 537 538 539 void 540 ibtl_cm_free_active_plist(ibtl_cm_port_list_t *plist) 541 { 542 int count; 543 544 IBTF_DPRINTF_L3(ibtf_cm, "ibtl_cm_free_active_plist(%p)", plist); 545 546 if (plist != NULL) { 547 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*plist)) 548 count = plist->p_count; 549 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*plist)) 550 551 kmem_free(plist, count * sizeof (ibtl_cm_port_list_t)); 552 } 553 } 554 555 /* 556 * Function: 557 * ibtl_cm_get_1st_full_pkey_ix 558 * Input: 559 * hca_guid HCA GUID. 560 * port Port Number. 561 * Output: 562 * None. 563 * Returns: 564 * P_Key Index of the first full member available from the P_Key table 565 * of the specified HCA<->Port. 566 * Description: 567 * A helper function to get P_Key Index of the first full member P_Key 568 * available on the specified HCA and Port combination. 569 */ 570 uint16_t 571 ibtl_cm_get_1st_full_pkey_ix(ib_guid_t hca_guid, uint8_t port) 572 { 573 ibtl_hca_devinfo_t *hca_devp; /* HCA Dev Info */ 574 uint16_t pkey_ix = 0; 575 576 IBTF_DPRINTF_L3(ibtf_cm, "ibtl_cm_get_1st_full_pkey_ix(%llX, %d)", 577 hca_guid, port); 578 579 mutex_enter(&ibtl_clnt_list_mutex); 580 hca_devp = ibtl_get_hcadevinfo(hca_guid); 581 582 if ((hca_devp != NULL) && (port <= hca_devp->hd_hca_attr->hca_nports) && 583 (port != 0)) { 584 pkey_ix = hca_devp->hd_portinfop[port - 1].p_def_pkey_ix; 585 } else { 586 IBTF_DPRINTF_L2(ibtf_cm, "ibtl_cm_get_1st_full_pkey_ix: " 587 "Invalid HCA (%llX), Port (%d) specified.", hca_guid, port); 588 } 589 mutex_exit(&ibtl_clnt_list_mutex); 590 591 return (pkey_ix); 592 } 593 594 595 ibt_status_t 596 ibtl_cm_get_local_comp_gids(ib_guid_t hca_guid, ib_gid_t gid, ib_gid_t **gids_p, 597 uint_t *num_gids_p) 598 { 599 ibtl_hca_devinfo_t *hdevp; /* HCA Dev Info */ 600 ibt_hca_portinfo_t *pinfop; 601 ib_gid_t sgid; 602 ib_gid_t *gidp = NULL; 603 int i, j, k; 604 int count = 0; 605 int gid_specified; 606 607 IBTF_DPRINTF_L3(ibtf_cm, "ibtl_cm_get_local_comp_gids(%llX, %llX:%llX)", 608 hca_guid, gid.gid_prefix, gid.gid_guid); 609 610 mutex_enter(&ibtl_clnt_list_mutex); 611 hdevp = ibtl_get_hcadevinfo(hca_guid); 612 613 if (hdevp == NULL) { 614 IBTF_DPRINTF_L3(ibtf_cm, "ibtl_cm_get_local_comp_gids: ", 615 "NO HCA (%llX) availble", hca_guid); 616 mutex_exit(&ibtl_clnt_list_mutex); 617 return (IBT_NO_HCAS_AVAILABLE); 618 } 619 620 if (gid.gid_prefix && gid.gid_guid) 621 gid_specified = 1; 622 else 623 gid_specified = 0; 624 625 for (i = 0; i < hdevp->hd_hca_attr->hca_nports; i++) { 626 pinfop = hdevp->hd_portinfop + i; 627 628 if (pinfop->p_linkstate != IBT_PORT_ACTIVE) 629 continue; 630 631 for (j = 0; j < pinfop->p_sgid_tbl_sz; j++) { 632 sgid = pinfop->p_sgid_tbl[j]; 633 if (sgid.gid_prefix && sgid.gid_guid) { 634 if (gid_specified && 635 ((gid.gid_prefix == sgid.gid_prefix) && 636 (gid.gid_guid == sgid.gid_guid))) { 637 /* 638 * Don't return the input specified 639 * GID 640 */ 641 continue; 642 } 643 count++; 644 } 645 } 646 } 647 648 if (count == 0) { 649 IBTF_DPRINTF_L2(ibtf_cm, "ibtl_cm_get_local_comp_gids: " 650 "Companion GIDs not available"); 651 mutex_exit(&ibtl_clnt_list_mutex); 652 return (IBT_GIDS_NOT_FOUND); 653 } 654 655 gidp = kmem_zalloc(count * sizeof (ib_gid_t), KM_SLEEP); 656 *num_gids_p = count; 657 *gids_p = gidp; 658 k = 0; 659 660 for (i = 0; i < hdevp->hd_hca_attr->hca_nports; i++) { 661 pinfop = hdevp->hd_portinfop + i; 662 663 if (pinfop->p_linkstate != IBT_PORT_ACTIVE) 664 continue; 665 666 for (j = 0; j < pinfop->p_sgid_tbl_sz; j++) { 667 sgid = pinfop->p_sgid_tbl[j]; 668 if (sgid.gid_prefix && sgid.gid_guid) { 669 if (gid_specified && 670 ((gid.gid_prefix == sgid.gid_prefix) && 671 (gid.gid_guid == sgid.gid_guid))) 672 continue; 673 674 gidp[k].gid_prefix = sgid.gid_prefix; 675 gidp[k].gid_guid = sgid.gid_guid; 676 677 IBTF_DPRINTF_L3(ibtf_cm, 678 "ibtl_cm_get_local_comp_gids: GID[%d]=" 679 "%llX:%llX", k, gidp[k].gid_prefix, 680 gidp[k].gid_guid); 681 k++; 682 if (k == count) 683 break; 684 } 685 } 686 if (k == count) 687 break; 688 } 689 mutex_exit(&ibtl_clnt_list_mutex); 690 691 return (IBT_SUCCESS); 692 } 693 694 695 int 696 ibtl_cm_is_multi_sm(ib_guid_t hca_guid) 697 { 698 ibtl_hca_devinfo_t *hdevp; /* HCA Dev Info */ 699 uint_t multi_sm; 700 701 mutex_enter(&ibtl_clnt_list_mutex); 702 hdevp = ibtl_get_hcadevinfo(hca_guid); 703 if (hdevp == NULL) { 704 IBTF_DPRINTF_L2(ibtf_cm, "ibtl_cm_is_multi_sm: NO HCA (%llX) " 705 "availble", hca_guid); 706 mutex_exit(&ibtl_clnt_list_mutex); 707 return (-1); 708 } 709 multi_sm = hdevp->hd_multism; 710 mutex_exit(&ibtl_clnt_list_mutex); 711 712 IBTF_DPRINTF_L3(ibtf_cm, "ibtl_cm_is_multi_sm(%llX): %d", hca_guid, 713 multi_sm); 714 715 return (multi_sm); 716 } 717