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 if (hdevp->hd_multism) 369 plistp->p_multi |= 370 IBTL_CM_MULTI_SM; 371 372 IBTF_DPRINTF_L3(ibtf_cm, 373 "ibtl_cm_get_cnt: HCA" 374 "(%llX,%d) SGID(%llX:%llX)", 375 plistp->p_hca_guid, 376 plistp->p_port_num, 377 plistp->p_sgid.gid_prefix, 378 plistp->p_sgid.gid_guid); 379 380 plistp++; 381 } 382 } 383 } 384 } 385 /* Asked to look in the specified HCA device only?. */ 386 if (attr->pa_hca_guid) 387 break; 388 389 if (flags & IBT_PATH_APM) { 390 if (pcount == 2) { 391 attr->pa_hca_guid = hca_guid; 392 break; 393 } else if (pcount == 1) { 394 if (hdevp->hd_hca_dev_link) { 395 tmp_hca_guid = hca_guid; 396 pcount = 0; 397 } else if (tmp_hca_guid) { 398 attr->pa_hca_guid = tmp_hca_guid; 399 } else { 400 attr->pa_hca_guid = hca_guid; 401 } 402 } else if ((pcount == 0) && (tmp_hca_guid) && 403 (hdevp->hd_hca_dev_link != NULL)) { 404 attr->pa_hca_guid = tmp_hca_guid; 405 } 406 } 407 hdevp = hdevp->hd_hca_dev_link; 408 } 409 410 *count = pcount; 411 412 if (pcount) { 413 retval = IBT_SUCCESS; 414 } else { 415 IBTF_DPRINTF_L2(ibtf_cm, "ibtl_cm_get_cnt: " 416 "Appropriate Source Points NOT found"); 417 if (retval == IBT_SUCCESS) 418 retval = IBT_NO_HCAS_AVAILABLE; 419 } 420 421 return (retval); 422 } 423 424 425 ibt_status_t 426 ibtl_cm_get_active_plist(ibt_path_attr_t *attr, ibt_path_flags_t flags, 427 ibtl_cm_port_list_t **port_list_p) 428 { 429 ibtl_cm_port_list_t *p_listp, tmp; 430 uint_t i, j; 431 uint_t count, rcount; 432 boolean_t multi_hca = B_FALSE; 433 ibt_status_t retval = IBT_SUCCESS; 434 435 IBTF_DPRINTF_L3(ibtf_cm, "ibtl_cm_get_active_plist(%p, %X)", 436 attr, flags); 437 438 get_plist_start: 439 *port_list_p = NULL; 440 441 /* Get "number of active src points" so that we can allocate memory. */ 442 mutex_enter(&ibtl_clnt_list_mutex); 443 retval = ibtl_cm_get_cnt(attr, flags, NULL, &count); 444 mutex_exit(&ibtl_clnt_list_mutex); 445 446 IBTF_DPRINTF_L3(ibtf_cm, "ibtl_cm_get_active_plist: Found %d SrcPoint", 447 count); 448 if (retval != IBT_SUCCESS) 449 return (retval); 450 451 /* Allocate Memory to hold Src Point information. */ 452 p_listp = kmem_zalloc(count * sizeof (ibtl_cm_port_list_t), KM_SLEEP); 453 454 /* 455 * Verify that the count we got previously is still valid, as we had 456 * dropped mutex to allocate memory. If not, restart the process. 457 */ 458 mutex_enter(&ibtl_clnt_list_mutex); 459 retval = ibtl_cm_get_cnt(attr, flags, NULL, &rcount); 460 if (retval != IBT_SUCCESS) { 461 mutex_exit(&ibtl_clnt_list_mutex); 462 kmem_free(p_listp, count * sizeof (ibtl_cm_port_list_t)); 463 return (retval); 464 } else if (rcount != count) { 465 mutex_exit(&ibtl_clnt_list_mutex); 466 kmem_free(p_listp, count * sizeof (ibtl_cm_port_list_t)); 467 goto get_plist_start; 468 } 469 470 *port_list_p = p_listp; 471 /* 472 * Src count hasn't changed, still holding the lock fill-in the 473 * required source point information. 474 */ 475 retval = ibtl_cm_get_cnt(attr, flags, p_listp, &rcount); 476 mutex_exit(&ibtl_clnt_list_mutex); 477 if (retval != IBT_SUCCESS) { 478 kmem_free(p_listp, count * sizeof (ibtl_cm_port_list_t)); 479 *port_list_p = NULL; 480 return (retval); 481 } 482 483 p_listp = *port_list_p; 484 485 _NOTE(NO_COMPETING_THREADS_NOW) 486 487 for (i = 0; i < count - 1; i++) { 488 for (j = 0; j < count - 1 - i; j++) { 489 if (p_listp[j].p_hca_guid != p_listp[j+1].p_hca_guid) { 490 multi_hca = B_TRUE; 491 break; 492 } 493 } 494 if (multi_hca == B_TRUE) 495 break; 496 } 497 498 if (multi_hca == B_TRUE) 499 for (i = 0; i < count; i++) 500 p_listp[i].p_multi |= IBTL_CM_MULTI_HCA; 501 502 /* 503 * Sort (bubble sort) the list based on MTU quality (higher on top). 504 * Sorting is only performed, if IBT_PATH_AVAIL is set. 505 */ 506 if (((attr->pa_mtu.r_selector == IBT_GT) || (flags & IBT_PATH_AVAIL)) && 507 (!(flags & IBT_PATH_APM))) { 508 for (i = 0; i < count - 1; i++) { 509 for (j = 0; j < count - 1 - i; j++) { 510 if (p_listp[j].p_mtu < p_listp[j+1].p_mtu) { 511 tmp = p_listp[j]; 512 p_listp[j] = p_listp[j+1]; 513 p_listp[j+1] = tmp; 514 } 515 } 516 } 517 } 518 519 if ((p_listp->p_multi & IBTL_CM_MULTI_HCA) && 520 (flags & IBT_PATH_AVAIL) && (!(flags & IBT_PATH_APM))) { 521 /* Avoid having same HCA next to each other in the list. */ 522 for (i = 0; i < count - 1; i++) { 523 for (j = 0; j < (count - 1 - i); j++) { 524 if ((p_listp[j].p_hca_guid == 525 p_listp[j+1].p_hca_guid) && 526 (j+2 < count)) { 527 tmp = p_listp[j+1]; 528 p_listp[j+1] = p_listp[j+2]; 529 p_listp[j+2] = tmp; 530 } 531 } 532 } 533 } 534 535 /* 536 * If SGID is specified, then make sure that SGID info is first 537 * in the array. 538 */ 539 if (attr->pa_sgid.gid_guid && (p_listp->p_count > 1) && 540 (p_listp[0].p_sgid.gid_guid != attr->pa_sgid.gid_guid)) { 541 for (i = 1; i < count; i++) { 542 if (p_listp[i].p_sgid.gid_guid == 543 attr->pa_sgid.gid_guid) { 544 tmp = p_listp[i]; 545 p_listp[i] = p_listp[0]; 546 p_listp[0] = tmp; 547 } 548 } 549 } 550 551 _NOTE(COMPETING_THREADS_NOW) 552 553 IBTF_DPRINTF_L3(ibtf_cm, "ibtl_cm_get_active_plist: " 554 "Returned <%d> entries @0x%p", count, *port_list_p); 555 556 return (retval); 557 } 558 559 560 void 561 ibtl_cm_free_active_plist(ibtl_cm_port_list_t *plist) 562 { 563 int count; 564 565 IBTF_DPRINTF_L3(ibtf_cm, "ibtl_cm_free_active_plist(%p)", plist); 566 567 if (plist != NULL) { 568 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*plist)) 569 count = plist->p_count; 570 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*plist)) 571 572 kmem_free(plist, count * sizeof (ibtl_cm_port_list_t)); 573 } 574 } 575 576 /* 577 * Function: 578 * ibtl_cm_get_1st_full_pkey_ix 579 * Input: 580 * hca_guid HCA GUID. 581 * port Port Number. 582 * Output: 583 * None. 584 * Returns: 585 * P_Key Index of the first full member available from the P_Key table 586 * of the specified HCA<->Port. 587 * Description: 588 * A helper function to get P_Key Index of the first full member P_Key 589 * available on the specified HCA and Port combination. 590 */ 591 uint16_t 592 ibtl_cm_get_1st_full_pkey_ix(ib_guid_t hca_guid, uint8_t port) 593 { 594 ibtl_hca_devinfo_t *hca_devp; /* HCA Dev Info */ 595 uint16_t pkey_ix = 0; 596 597 IBTF_DPRINTF_L3(ibtf_cm, "ibtl_cm_get_1st_full_pkey_ix(%llX, %d)", 598 hca_guid, port); 599 600 mutex_enter(&ibtl_clnt_list_mutex); 601 hca_devp = ibtl_get_hcadevinfo(hca_guid); 602 603 if ((hca_devp != NULL) && (port <= hca_devp->hd_hca_attr->hca_nports) && 604 (port != 0)) { 605 pkey_ix = hca_devp->hd_portinfop[port - 1].p_def_pkey_ix; 606 } else { 607 IBTF_DPRINTF_L2(ibtf_cm, "ibtl_cm_get_1st_full_pkey_ix: " 608 "Invalid HCA (%llX), Port (%d) specified.", hca_guid, port); 609 } 610 mutex_exit(&ibtl_clnt_list_mutex); 611 612 return (pkey_ix); 613 } 614 615 616 ibt_status_t 617 ibtl_cm_get_local_comp_gids(ib_guid_t hca_guid, ib_gid_t gid, ib_gid_t **gids_p, 618 uint_t *num_gids_p) 619 { 620 ibtl_hca_devinfo_t *hdevp; /* HCA Dev Info */ 621 ibt_hca_portinfo_t *pinfop; 622 ib_gid_t sgid; 623 ib_gid_t *gidp = NULL; 624 int i, j, k; 625 int count = 0; 626 int gid_specified; 627 628 IBTF_DPRINTF_L3(ibtf_cm, "ibtl_cm_get_local_comp_gids(%llX, %llX:%llX)", 629 hca_guid, gid.gid_prefix, gid.gid_guid); 630 631 mutex_enter(&ibtl_clnt_list_mutex); 632 hdevp = ibtl_get_hcadevinfo(hca_guid); 633 634 if (hdevp == NULL) { 635 IBTF_DPRINTF_L3(ibtf_cm, "ibtl_cm_get_local_comp_gids: ", 636 "NO HCA (%llX) availble", hca_guid); 637 mutex_exit(&ibtl_clnt_list_mutex); 638 return (IBT_NO_HCAS_AVAILABLE); 639 } 640 641 if (gid.gid_prefix && gid.gid_guid) 642 gid_specified = 1; 643 else 644 gid_specified = 0; 645 646 for (i = 0; i < hdevp->hd_hca_attr->hca_nports; i++) { 647 pinfop = hdevp->hd_portinfop + i; 648 649 if (pinfop->p_linkstate != IBT_PORT_ACTIVE) 650 continue; 651 652 for (j = 0; j < pinfop->p_sgid_tbl_sz; j++) { 653 sgid = pinfop->p_sgid_tbl[j]; 654 if (sgid.gid_prefix && sgid.gid_guid) { 655 if (gid_specified && 656 ((gid.gid_prefix == sgid.gid_prefix) && 657 (gid.gid_guid == sgid.gid_guid))) { 658 /* 659 * Don't return the input specified 660 * GID 661 */ 662 continue; 663 } 664 count++; 665 } 666 } 667 } 668 669 if (count == 0) { 670 IBTF_DPRINTF_L2(ibtf_cm, "ibtl_cm_get_local_comp_gids: " 671 "Companion GIDs not available"); 672 mutex_exit(&ibtl_clnt_list_mutex); 673 return (IBT_GIDS_NOT_FOUND); 674 } 675 676 gidp = kmem_zalloc(count * sizeof (ib_gid_t), KM_SLEEP); 677 *num_gids_p = count; 678 *gids_p = gidp; 679 k = 0; 680 681 for (i = 0; i < hdevp->hd_hca_attr->hca_nports; i++) { 682 pinfop = hdevp->hd_portinfop + i; 683 684 if (pinfop->p_linkstate != IBT_PORT_ACTIVE) 685 continue; 686 687 for (j = 0; j < pinfop->p_sgid_tbl_sz; j++) { 688 sgid = pinfop->p_sgid_tbl[j]; 689 if (sgid.gid_prefix && sgid.gid_guid) { 690 if (gid_specified && 691 ((gid.gid_prefix == sgid.gid_prefix) && 692 (gid.gid_guid == sgid.gid_guid))) 693 continue; 694 695 gidp[k].gid_prefix = sgid.gid_prefix; 696 gidp[k].gid_guid = sgid.gid_guid; 697 698 IBTF_DPRINTF_L3(ibtf_cm, 699 "ibtl_cm_get_local_comp_gids: GID[%d]=" 700 "%llX:%llX", k, gidp[k].gid_prefix, 701 gidp[k].gid_guid); 702 k++; 703 if (k == count) 704 break; 705 } 706 } 707 if (k == count) 708 break; 709 } 710 mutex_exit(&ibtl_clnt_list_mutex); 711 712 return (IBT_SUCCESS); 713 } 714 715 716 int 717 ibtl_cm_is_multi_sm(ib_guid_t hca_guid) 718 { 719 ibtl_hca_devinfo_t *hdevp; /* HCA Dev Info */ 720 uint_t multi_sm; 721 722 mutex_enter(&ibtl_clnt_list_mutex); 723 hdevp = ibtl_get_hcadevinfo(hca_guid); 724 if (hdevp == NULL) { 725 IBTF_DPRINTF_L2(ibtf_cm, "ibtl_cm_is_multi_sm: NO HCA (%llX) " 726 "availble", hca_guid); 727 mutex_exit(&ibtl_clnt_list_mutex); 728 return (-1); 729 } 730 multi_sm = hdevp->hd_multism; 731 mutex_exit(&ibtl_clnt_list_mutex); 732 733 IBTF_DPRINTF_L3(ibtf_cm, "ibtl_cm_is_multi_sm(%llX): %d", hca_guid, 734 multi_sm); 735 736 return (multi_sm); 737 } 738