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/mgt/ibcm/ibcm_impl.h> 30 #include <sys/ib/ibtl/ibti.h> 31 32 /* 33 * ibcm_path.c 34 * 35 * ibt_get_paths() implement the Path Informations related functionality. 36 */ 37 38 /* Externs. */ 39 extern char cmlog[]; 40 41 /* ibcm_saa_service_rec() fills in ServiceID and DGID. */ 42 typedef struct ibcm_dest_s { 43 ib_gid_t d_gid; 44 ib_svc_id_t d_sid; 45 ibt_srv_data_t d_sdata; 46 ib_pkey_t d_pkey; 47 uint_t d_tag; /* 0 = Unicast, 1 = Multicast, 2 = LoopBack */ 48 } ibcm_dest_t; 49 50 /* Holds Destination information needed to fill in ibt_path_info_t. */ 51 typedef struct ibcm_dinfo_s { 52 uint8_t num_dest; 53 ib_pkey_t p_key; 54 ibcm_dest_t dest[1]; 55 } ibcm_dinfo_t; 56 57 _NOTE(SCHEME_PROTECTS_DATA("Temporary path storage", ibcm_dinfo_s)) 58 _NOTE(READ_ONLY_DATA(ibt_path_attr_s)) 59 60 typedef struct ibcm_path_tqargs_s { 61 ibt_path_attr_t attr; 62 ibt_path_info_t *paths; 63 uint8_t *num_paths_p; 64 ibt_path_handler_t func; 65 void *arg; 66 ibt_path_flags_t flags; 67 uint8_t max_paths; 68 } ibcm_path_tqargs_t; 69 70 71 /* Prototype Declarations. */ 72 static ibt_status_t ibcm_get_path_rec(ibcm_path_tqargs_t *, ibcm_dinfo_t *, 73 uint8_t *, ibt_path_info_t *); 74 75 static ibt_status_t ibcm_saa_path_rec(ibcm_path_tqargs_t *, 76 ibtl_cm_port_list_t *, ibcm_dinfo_t *, uint8_t *); 77 78 static ibt_status_t ibcm_update_cep_info(sa_path_record_t *, 79 ibtl_cm_port_list_t *, ibtl_cm_hca_port_t *, ibt_cep_path_t *); 80 81 static ibt_status_t ibcm_fillin_loopbackinfo(ibtl_cm_port_list_t *, 82 uint8_t index, ibcm_dinfo_t *, ibt_path_info_t *); 83 84 static ibt_status_t ibcm_saa_service_rec(ibcm_path_tqargs_t *, 85 ibtl_cm_port_list_t *, ibcm_dinfo_t *); 86 87 static ibt_status_t ibcm_get_single_pathrec(ibcm_path_tqargs_t *, 88 ibtl_cm_port_list_t *, ibcm_dinfo_t *, uint8_t, 89 uint8_t *, ibt_path_info_t *); 90 91 static ibt_status_t ibcm_get_multi_pathrec(ibcm_path_tqargs_t *, 92 ibtl_cm_port_list_t *, ibcm_dinfo_t *dinfo, 93 uint8_t *, ibt_path_info_t *); 94 95 static ibt_status_t ibcm_validate_path_attributes(ibt_path_attr_t *attrp, 96 ibt_path_flags_t flags, uint8_t max_paths); 97 98 static ibt_status_t ibcm_handle_get_path(ibt_path_attr_t *attrp, 99 ibt_path_flags_t flags, uint8_t max_paths, ibt_path_info_t *paths, 100 uint8_t *num_path_p, ibt_path_handler_t func, void *arg); 101 102 static void ibcm_process_async_get_paths(void *tq_arg); 103 104 static ibt_status_t ibcm_process_get_paths(void *tq_arg); 105 106 static ibt_status_t ibcm_get_comp_pgids(ib_gid_t, ib_gid_t, ib_guid_t, 107 ib_gid_t **, uint_t *); 108 109 110 /* 111 * Function: 112 * ibt_aget_paths 113 * Input: 114 * ibt_hdl The handle returned to the client by the IBTF from an 115 * ibt_attach() call. Can be used by the IBTF Policy module 116 * and CM in the determination of the "best" path to the 117 * specified destination for this class of driver. 118 * flags Path flags. 119 * attrp Points to an ibt_path_attr_t struct that contains 120 * required and optional attributes. 121 * func A pointer to an ibt_path_handler_t function to call 122 * when ibt_aget_paths() completes. 123 * arg The argument to 'func'. 124 * Returns: 125 * IBT_SUCCESS on early validation of attributes else appropriate error. 126 * Description: 127 * Finds the best path to a specified destination or service 128 * asynchronously (as determined by the IBTL) that satisfies the 129 * requirements specified in an ibt_path_attr_t struct. 130 * ibt_aget_paths() is a Non-Blocking version of ibt_get_paths(). 131 */ 132 ibt_status_t 133 ibt_aget_paths(ibt_clnt_hdl_t ibt_hdl, ibt_path_flags_t flags, 134 ibt_path_attr_t *attrp, uint8_t max_paths, ibt_path_handler_t func, 135 void *arg) 136 { 137 IBTF_DPRINTF_L3(cmlog, "ibt_aget_paths(%p, 0x%lX, %p, %d, %p)", 138 ibt_hdl, flags, attrp, max_paths, func); 139 140 if (func == NULL) { 141 IBTF_DPRINTF_L2(cmlog, "ibt_aget_paths: Function Pointer is " 142 "NULL - ERROR "); 143 return (IBT_INVALID_PARAM); 144 } 145 146 /* Memory for path info will be allocated in ibcm_process_get_paths() */ 147 return (ibcm_handle_get_path(attrp, flags, max_paths, NULL, NULL, 148 func, arg)); 149 } 150 151 152 /* 153 * ibt_get_paths() cache consists of one or more of: 154 * 155 * ib_gid_t dgid (attrp->pa_dgids[0]) 156 * ibt_path_attr_t attr 157 * ibt_path_flags_t flags 158 * ibt_path_info_t path 159 * 160 * If the first 3 match, max_paths is 1, sname is NULL, and sid is 0, 161 * then the path is returned immediately. 162 * 163 * Note that a compare of "attr" is non-trivial. Only accept ones 164 * that memcmp() succeeds, i.e., basically assume a bzero was done. 165 * 166 * Cache must be invalidated if PORT_DOWN event or GID_UNAVAIL occurs. 167 * Cache must be freed as part of _fini. 168 */ 169 170 #define IBCM_PATH_CACHE_SIZE 16 /* keep small for linear search */ 171 #define IBCM_PATH_CACHE_TIMEOUT 60 /* purge cache after 60 seconds */ 172 173 typedef struct ibcm_path_cache_s { 174 ib_gid_t dgid; 175 ibt_path_attr_t attr; 176 ibt_path_flags_t flags; 177 ibt_path_info_t path; 178 } ibcm_path_cache_t; 179 180 kmutex_t ibcm_path_cache_mutex; 181 int ibcm_path_cache_invalidate; /* invalidate cache on next ibt_get_paths */ 182 clock_t ibcm_path_cache_timeout = IBCM_PATH_CACHE_TIMEOUT; /* tunable */ 183 timeout_id_t ibcm_path_cache_timeout_id; 184 int ibcm_path_cache_size_init = IBCM_PATH_CACHE_SIZE; /* tunable */ 185 int ibcm_path_cache_size; 186 ibcm_path_cache_t *ibcm_path_cachep; 187 188 struct ibcm_path_cache_stat_s { 189 int hits; 190 int misses; 191 int adds; 192 int already_in_cache; 193 int bad_path_for_cache; 194 int purges; 195 int timeouts; 196 } ibcm_path_cache_stats; 197 198 /*ARGSUSED*/ 199 static void 200 ibcm_path_cache_timeout_cb(void *arg) 201 { 202 clock_t timeout_in_hz; 203 204 timeout_in_hz = drv_usectohz(ibcm_path_cache_timeout * 1000000); 205 mutex_enter(&ibcm_path_cache_mutex); 206 ibcm_path_cache_invalidate = 1; /* invalidate cache on next check */ 207 if (ibcm_path_cache_timeout_id) 208 ibcm_path_cache_timeout_id = timeout(ibcm_path_cache_timeout_cb, 209 NULL, timeout_in_hz); 210 /* else we're in _fini */ 211 mutex_exit(&ibcm_path_cache_mutex); 212 } 213 214 void 215 ibcm_path_cache_init(void) 216 { 217 clock_t timeout_in_hz; 218 int cache_size = ibcm_path_cache_size_init; 219 ibcm_path_cache_t *path_cachep; 220 221 timeout_in_hz = drv_usectohz(ibcm_path_cache_timeout * 1000000); 222 path_cachep = kmem_zalloc(cache_size * sizeof (*path_cachep), KM_SLEEP); 223 mutex_init(&ibcm_path_cache_mutex, NULL, MUTEX_DRIVER, NULL); 224 mutex_enter(&ibcm_path_cache_mutex); 225 ibcm_path_cache_size = cache_size; 226 ibcm_path_cachep = path_cachep; 227 ibcm_path_cache_timeout_id = timeout(ibcm_path_cache_timeout_cb, 228 NULL, timeout_in_hz); 229 mutex_exit(&ibcm_path_cache_mutex); 230 } 231 232 void 233 ibcm_path_cache_fini(void) 234 { 235 timeout_id_t tmp_timeout_id; 236 int cache_size; 237 ibcm_path_cache_t *path_cachep; 238 239 mutex_enter(&ibcm_path_cache_mutex); 240 if (ibcm_path_cache_timeout_id) { 241 tmp_timeout_id = ibcm_path_cache_timeout_id; 242 ibcm_path_cache_timeout_id = 0; /* no more timeouts */ 243 } 244 cache_size = ibcm_path_cache_size; 245 path_cachep = ibcm_path_cachep; 246 mutex_exit(&ibcm_path_cache_mutex); 247 if (tmp_timeout_id) 248 (void) untimeout(tmp_timeout_id); 249 mutex_destroy(&ibcm_path_cache_mutex); 250 kmem_free(path_cachep, cache_size * sizeof (*path_cachep)); 251 } 252 253 static ibcm_status_t 254 ibcm_path_cache_check(ibt_path_flags_t flags, ibt_path_attr_t *attrp, 255 uint8_t max_paths, ibt_path_info_t *path, uint8_t *num_paths_p) 256 { 257 int i; 258 ib_gid_t dgid; 259 ibcm_path_cache_t *path_cachep; 260 261 if (max_paths != 1 || attrp->pa_num_dgids != 1 || 262 attrp->pa_sname != NULL || attrp->pa_sid != 0) { 263 mutex_enter(&ibcm_path_cache_mutex); 264 ibcm_path_cache_stats.bad_path_for_cache++; 265 mutex_exit(&ibcm_path_cache_mutex); 266 return (IBCM_FAILURE); 267 } 268 269 dgid = attrp->pa_dgids[0]; 270 if ((dgid.gid_guid | dgid.gid_prefix) == 0ULL) 271 return (IBCM_FAILURE); 272 273 mutex_enter(&ibcm_path_cache_mutex); 274 if (ibcm_path_cache_invalidate) { /* invalidate all entries */ 275 ibcm_path_cache_stats.timeouts++; 276 ibcm_path_cache_invalidate = 0; 277 path_cachep = ibcm_path_cachep; 278 for (i = 0; i < ibcm_path_cache_size; i++, path_cachep++) { 279 path_cachep->dgid.gid_guid = 0ULL; 280 path_cachep->dgid.gid_prefix = 0ULL; 281 } 282 mutex_exit(&ibcm_path_cache_mutex); 283 return (IBCM_FAILURE); 284 } 285 286 path_cachep = ibcm_path_cachep; 287 for (i = 0; i < ibcm_path_cache_size; i++, path_cachep++) { 288 if (path_cachep->dgid.gid_guid == 0ULL) 289 break; /* end of search, no more valid cache entries */ 290 291 /* make pa_dgids pointers match, so we can use memcmp */ 292 path_cachep->attr.pa_dgids = attrp->pa_dgids; 293 if (path_cachep->flags != flags || 294 path_cachep->dgid.gid_guid != dgid.gid_guid || 295 path_cachep->dgid.gid_prefix != dgid.gid_prefix || 296 memcmp(&(path_cachep->attr), attrp, sizeof (*attrp)) != 0) { 297 /* make pa_dgids NULL again */ 298 path_cachep->attr.pa_dgids = NULL; 299 continue; 300 } 301 /* else we have a match */ 302 /* make pa_dgids NULL again */ 303 path_cachep->attr.pa_dgids = NULL; 304 *path = path_cachep->path; /* retval */ 305 if (num_paths_p) 306 *num_paths_p = 1; /* retval */ 307 ibcm_path_cache_stats.hits++; 308 mutex_exit(&ibcm_path_cache_mutex); 309 return (IBCM_SUCCESS); 310 } 311 ibcm_path_cache_stats.misses++; 312 mutex_exit(&ibcm_path_cache_mutex); 313 return (IBCM_FAILURE); 314 } 315 316 static void 317 ibcm_path_cache_add(ibt_path_flags_t flags, 318 ibt_path_attr_t *attrp, uint8_t max_paths, ibt_path_info_t *path) 319 { 320 int i; 321 ib_gid_t dgid; 322 ibcm_path_cache_t *path_cachep; 323 324 if (max_paths != 1 || attrp->pa_num_dgids != 1 || 325 attrp->pa_sname != NULL || attrp->pa_sid != 0) 326 return; 327 328 dgid = attrp->pa_dgids[0]; 329 if ((dgid.gid_guid | dgid.gid_prefix) == 0ULL) 330 return; 331 332 mutex_enter(&ibcm_path_cache_mutex); 333 path_cachep = ibcm_path_cachep; 334 for (i = 0; i < ibcm_path_cache_size; i++, path_cachep++) { 335 path_cachep->attr.pa_dgids = attrp->pa_dgids; 336 if (path_cachep->flags == flags && 337 path_cachep->dgid.gid_guid == dgid.gid_guid && 338 path_cachep->dgid.gid_prefix == dgid.gid_prefix && 339 memcmp(&(path_cachep->attr), attrp, sizeof (*attrp)) == 0) { 340 /* already in cache */ 341 ibcm_path_cache_stats.already_in_cache++; 342 path_cachep->attr.pa_dgids = NULL; 343 mutex_exit(&ibcm_path_cache_mutex); 344 return; 345 } 346 if (path_cachep->dgid.gid_guid != 0ULL) { 347 path_cachep->attr.pa_dgids = NULL; 348 continue; 349 } 350 /* else the rest of the entries are free, so use this one */ 351 ibcm_path_cache_stats.adds++; 352 path_cachep->flags = flags; 353 path_cachep->attr = *attrp; 354 path_cachep->attr.pa_dgids = NULL; 355 path_cachep->dgid = attrp->pa_dgids[0]; 356 path_cachep->path = *path; 357 mutex_exit(&ibcm_path_cache_mutex); 358 return; 359 } 360 mutex_exit(&ibcm_path_cache_mutex); 361 } 362 363 void 364 ibcm_path_cache_purge(void) 365 { 366 mutex_enter(&ibcm_path_cache_mutex); 367 ibcm_path_cache_invalidate = 1; /* invalidate cache on next check */ 368 ibcm_path_cache_stats.purges++; 369 mutex_exit(&ibcm_path_cache_mutex); 370 } 371 372 /* 373 * Function: 374 * ibt_get_paths 375 * Input: 376 * ibt_hdl The handle returned to the client by the IBTF from an 377 * ibt_attach() call. Can be used by the IBTF Policy module 378 * and CM in the determination of the "best" path to the 379 * specified destination for this class of driver. 380 * flags Path flags. 381 * attrp Points to an ibt_path_attr_t struct that contains 382 * required and optional attributes. 383 * max_paths The size of the "paths" array argument. Also, this 384 * is the limit on the number of paths returned. 385 * max_paths indicates the number of requested paths to 386 * the specified destination(s). 387 * Output: 388 * paths An array of ibt_path_info_t structs filled in by 389 * ibt_get_paths() as output parameters. Upon return, 390 * array elements with non-NULL HCA GUIDs are valid. 391 * num_paths_p If non-NULL, return the actual number of paths found. 392 * Returns: 393 * IBT_SUCCESS on Success else appropriate error. 394 * Description: 395 * Finds the best path to a specified destination (as determined by the 396 * IBTL) that satisfies the requirements specified in an ibt_path_attr_t 397 * struct. 398 * 399 * This routine can not be called from interrupt context. 400 */ 401 ibt_status_t 402 ibt_get_paths(ibt_clnt_hdl_t ibt_hdl, ibt_path_flags_t flags, 403 ibt_path_attr_t *attrp, uint8_t max_paths, ibt_path_info_t *paths, 404 uint8_t *num_paths_p) 405 { 406 ibt_status_t retval; 407 408 ASSERT(paths != NULL); 409 410 IBTF_DPRINTF_L3(cmlog, "ibt_get_paths(%p, 0x%lX, %p, %d)", 411 ibt_hdl, flags, attrp, max_paths); 412 413 if (paths == NULL) { 414 IBTF_DPRINTF_L2(cmlog, "ibt_get_paths: Path Info Pointer is " 415 "NULL - ERROR "); 416 return (IBT_INVALID_PARAM); 417 } 418 419 if (num_paths_p != NULL) 420 *num_paths_p = 0; 421 422 if (ibcm_path_cache_check(flags, attrp, max_paths, paths, 423 num_paths_p) == IBCM_SUCCESS) 424 return (IBT_SUCCESS); 425 426 retval = ibcm_handle_get_path(attrp, flags, max_paths, paths, 427 num_paths_p, NULL, NULL); 428 429 if (retval == IBT_SUCCESS) 430 ibcm_path_cache_add(flags, attrp, max_paths, paths); 431 return (retval); 432 } 433 434 435 static ibt_status_t 436 ibcm_handle_get_path(ibt_path_attr_t *attrp, ibt_path_flags_t flags, 437 uint8_t max_paths, ibt_path_info_t *paths, uint8_t *num_path_p, 438 ibt_path_handler_t func, void *arg) 439 { 440 ibcm_path_tqargs_t *path_tq; 441 int sleep_flag = ((func == NULL) ? KM_SLEEP : KM_NOSLEEP); 442 int len; 443 ibt_status_t retval; 444 445 retval = ibcm_validate_path_attributes(attrp, flags, max_paths); 446 if (retval != IBT_SUCCESS) 447 return (retval); 448 449 len = (attrp->pa_num_dgids * sizeof (ib_gid_t)) + 450 sizeof (ibcm_path_tqargs_t); 451 452 path_tq = kmem_alloc(len, sleep_flag); 453 if (path_tq == NULL) { 454 IBTF_DPRINTF_L2(cmlog, "ibcm_handle_get_path: " 455 "Unable to allocate memory for local usage."); 456 return (IBT_INSUFF_KERNEL_RESOURCE); 457 } 458 459 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*path_tq)) 460 461 bcopy(attrp, &path_tq->attr, sizeof (ibt_path_attr_t)); 462 463 if (attrp->pa_num_dgids) { 464 path_tq->attr.pa_dgids = (ib_gid_t *)(((uchar_t *)path_tq) + 465 sizeof (ibcm_path_tqargs_t)); 466 467 bcopy(attrp->pa_dgids, path_tq->attr.pa_dgids, 468 sizeof (ib_gid_t) * attrp->pa_num_dgids); 469 } else { 470 path_tq->attr.pa_dgids = NULL; 471 } 472 473 /* Ignore IBT_PATH_AVAIL flag, if only one path is requested. */ 474 if ((flags & IBT_PATH_AVAIL) && (max_paths == 1)) { 475 flags &= ~IBT_PATH_AVAIL; 476 477 IBTF_DPRINTF_L4(cmlog, "ibcm_handle_get_path: " 478 "Ignoring IBT_PATH_AVAIL flag, as only ONE path " 479 "information is requested."); 480 } 481 482 path_tq->flags = flags; 483 path_tq->max_paths = max_paths; 484 path_tq->paths = paths; 485 path_tq->num_paths_p = num_path_p; 486 path_tq->func = func; 487 path_tq->arg = arg; 488 489 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*path_tq)) 490 491 if (func != NULL) { /* Non-Blocking */ 492 IBTF_DPRINTF_L3(cmlog, "ibcm_handle_get_path: Non Blocking"); 493 if (taskq_dispatch(ibcm_taskq, ibcm_process_async_get_paths, 494 path_tq, TQ_NOSLEEP) == 0) { 495 IBTF_DPRINTF_L2(cmlog, "ibcm_handle_get_path: " 496 "Failed to dispatch the TaskQ"); 497 kmem_free(path_tq, len); 498 return (IBT_INSUFF_KERNEL_RESOURCE); 499 } else 500 return (IBT_SUCCESS); 501 } else { /* Blocking */ 502 IBTF_DPRINTF_L3(cmlog, "ibcm_handle_get_path: Blocking"); 503 return (ibcm_process_get_paths(path_tq)); 504 } 505 } 506 507 508 static void 509 ibcm_process_async_get_paths(void *tq_arg) 510 { 511 (void) ibcm_process_get_paths(tq_arg); 512 } 513 514 515 static ibt_status_t 516 ibcm_validate_path_attributes(ibt_path_attr_t *attrp, ibt_path_flags_t flags, 517 uint8_t max_paths) 518 { 519 uint_t i; 520 521 IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: Inputs are: " 522 "HCA (%llX, %d),\n\tSGID(%llX:%llX), SName=\"%s\",\n\tSID= %llX, " 523 "Maxpath= %d, Flags= 0x%X, #Dgid= %d, SDFlag= 0x%llX", 524 attrp->pa_hca_guid, attrp->pa_hca_port_num, 525 attrp->pa_sgid.gid_prefix, attrp->pa_sgid.gid_guid, 526 ((attrp->pa_sname != NULL) ? attrp->pa_sname : ""), attrp->pa_sid, 527 max_paths, flags, attrp->pa_num_dgids, attrp->pa_sd_flags); 528 529 /* 530 * Validate Path Flags. 531 * IBT_PATH_AVAIL & IBT_PATH_PERF are mutually exclusive. 532 */ 533 if ((flags & IBT_PATH_AVAIL) && (flags & IBT_PATH_PERF)) { 534 IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: " 535 "Invalid Flags: 0x%X,\n\t AVAIL and PERF flags cannot " 536 "specified together.", flags); 537 return (IBT_INVALID_PARAM); 538 } 539 540 /* Validate number of records requested. */ 541 if ((flags & (IBT_PATH_AVAIL | IBT_PATH_PERF)) && 542 (max_paths > IBT_MAX_SPECIAL_PATHS)) { 543 IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: " 544 "Max records that can be requested is <%d> \n" 545 "when IBT_PATH_AVAIL or IBT_PATH_PERF flag is specified.", 546 IBT_MAX_SPECIAL_PATHS); 547 return (IBT_INVALID_PARAM); 548 } 549 550 /* Only 2 destinations can be specified w/ APM flag. */ 551 if ((flags & IBT_PATH_APM) && (attrp->pa_num_dgids > 2)) { 552 IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes:\n\t Max " 553 "number of DGIDs that can be specified w/APM flag is 2"); 554 return (IBT_INVALID_PARAM); 555 } 556 557 /* 558 * Max_paths of "0" is invalid. 559 * w/ IBT_PATH_MULTI_SVC_DEST flag, max_paths must be greater than "1". 560 */ 561 if ((max_paths == 0) || 562 ((flags & IBT_PATH_MULTI_SVC_DEST) && (max_paths < 2))) { 563 IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: " 564 "Invalid number of records requested:\n flags 0x%X, " 565 "max_paths %d", flags, max_paths); 566 return (IBT_INVALID_PARAM); 567 } 568 569 /* 570 * If IBT_PATH_MULTI_SVC_DEST is set, then ServiceName and/or Service ID 571 * must be specified and DGIDs SHOULD NOT be specified. 572 */ 573 if ((flags & IBT_PATH_MULTI_SVC_DEST) && ((attrp->pa_num_dgids > 0) || 574 ((attrp->pa_sid == 0) && ((attrp->pa_sname == NULL) || 575 ((attrp->pa_sname != NULL) && (strlen(attrp->pa_sname) == 0)))))) { 576 IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: " 577 "Invalid Flags: 0x%X, IBT_PATH_MULTI_SVC_DEST flag set " 578 "but Service Name \n or Service ID NOT specified or DGIDs " 579 "are specified.", flags); 580 return (IBT_INVALID_PARAM); 581 } 582 583 /* 584 * User need to specify the destination information, which can be 585 * provided as one or more of the following. 586 * o ServiceName 587 * o ServiceID 588 * o Array of DGIDs w/Num of DGIDs, (max of 2) 589 */ 590 if ((attrp->pa_sid == 0) && (attrp->pa_num_dgids == 0) && 591 ((attrp->pa_sname == NULL) || ((attrp->pa_sname != NULL) && 592 (strlen(attrp->pa_sname) == 0)))) { 593 /* Destination information not provided, bail out. */ 594 IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: " 595 "Client's MUST supply DestInfo."); 596 return (IBT_INVALID_PARAM); 597 } 598 599 /* If DGIDs are provided, validate them. */ 600 if (attrp->pa_num_dgids > 0) { 601 if (attrp->pa_dgids == NULL) { 602 IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: " 603 "pa_dgids NULL, but pa_num_dgids : %d", 604 attrp->pa_num_dgids); 605 return (IBT_INVALID_PARAM); 606 } 607 608 /* Validate DGIDs */ 609 for (i = 0; i < attrp->pa_num_dgids; i++) { 610 ib_gid_t gid = attrp->pa_dgids[i]; 611 612 IBTF_DPRINTF_L3(cmlog, "ibcm_validate_path_attributes: " 613 "DGID[%d] = %llX:%llX", i, gid.gid_prefix, 614 gid.gid_guid); 615 616 /* APM request for MultiCast destination is invalid. */ 617 if ((gid.gid_prefix >> 56ULL & 0xFF) == 0xFF) { 618 if (flags & IBT_PATH_APM) { 619 IBTF_DPRINTF_L2(cmlog, 620 "ibcm_validate_path_attributes: " 621 "APM for MGIDs not supported."); 622 return (IBT_INVALID_PARAM); 623 } 624 } else if ((gid.gid_prefix == 0) || 625 (gid.gid_guid == 0)) { 626 IBTF_DPRINTF_L2(cmlog, 627 "ibcm_validate_path_attributes: ERROR: " 628 "Invalid DGIDs specified"); 629 return (IBT_INVALID_PARAM); 630 } 631 } 632 } 633 634 /* Check for valid Service Name length. */ 635 if ((attrp->pa_sname != NULL) && 636 (strlen(attrp->pa_sname) >= IB_SVC_NAME_LEN)) { 637 IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: " 638 "ServiceName too long"); 639 return (IBT_INVALID_PARAM); 640 } 641 642 /* If P_Key is specified, check for invalid p_key's */ 643 if (flags & IBT_PATH_PKEY) { 644 /* Limited P_Key is NOT supported as of now!. */ 645 if ((attrp->pa_pkey == IB_PKEY_INVALID_FULL) || 646 (attrp->pa_pkey & 0x8000) == 0) { 647 IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: " 648 "Specified P_Key is invalid: 0x%X", attrp->pa_pkey); 649 return (IBT_INVALID_PARAM); 650 } 651 IBTF_DPRINTF_L3(cmlog, "ibcm_validate_path_attributes: " 652 "P_Key= 0x%X", attrp->pa_pkey); 653 } 654 655 return (IBT_SUCCESS); 656 } 657 658 659 static ibt_status_t 660 ibcm_process_get_paths(void *tq_arg) 661 { 662 ibcm_path_tqargs_t *p_arg = (ibcm_path_tqargs_t *)tq_arg; 663 ibcm_dinfo_t *dinfo; 664 int len; 665 uint8_t max_paths, num_path; 666 ibt_status_t retval; 667 ib_gid_t *d_gids_p = NULL; 668 ibtl_cm_port_list_t *slistp = NULL; 669 uint_t dnum = 0, num_dest; 670 uint_t i, j; 671 ibcm_hca_info_t *hcap; 672 ibmf_saa_handle_t saa_handle; 673 674 IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_paths(%p, 0x%X, %d) ", 675 p_arg, p_arg->flags, p_arg->max_paths); 676 677 max_paths = num_path = p_arg->max_paths; 678 679 /* 680 * Prepare the Destination list based on the input DGIDs and 681 * other attributes. 682 * 683 * APM is requested and pa_dgids are specified. If multiple DGIDs are 684 * specified, check out whether they are companion to each other or if 685 * only one DGID is specified, then get the companion port GID for that. 686 */ 687 if (p_arg->attr.pa_num_dgids) { 688 if (p_arg->flags & IBT_PATH_APM) { 689 ib_gid_t c_gid, n_gid; 690 691 IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_paths: " 692 "DGIDs specified w/ APM Flag"); 693 694 c_gid = p_arg->attr.pa_dgids[0]; 695 if (p_arg->attr.pa_num_dgids > 1) 696 n_gid = p_arg->attr.pa_dgids[1]; 697 else 698 n_gid.gid_prefix = n_gid.gid_guid = 0; 699 700 retval = ibcm_get_comp_pgids(c_gid, n_gid, 0, &d_gids_p, 701 &dnum); 702 if ((retval != IBT_SUCCESS) && 703 (retval != IBT_GIDS_NOT_FOUND)) { 704 IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths:" 705 " Invalid DGIDs specified w/ APM Flag"); 706 goto path_error2; 707 } 708 IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_paths: " 709 "Found %d Comp DGID", dnum); 710 } 711 712 if (dnum) { 713 len = 1; 714 } else { 715 len = p_arg->attr.pa_num_dgids - 1; 716 } 717 num_dest = len + 1; 718 719 IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_paths: #dgid %d, dnum " 720 "%d, #dest %d", p_arg->attr.pa_num_dgids, dnum, num_dest); 721 } else { 722 if (p_arg->flags & IBT_PATH_MULTI_SVC_DEST) { 723 IBTF_DPRINTF_L4(cmlog, "ibcm_process_get_paths: " 724 "IBT_PATH_MULTI_SVC_DEST flags set"); 725 len = max_paths - 1; 726 } else if (p_arg->flags & IBT_PATH_APM) { 727 len = 1; 728 } else { 729 len = 0; 730 } 731 num_dest = 0; 732 } 733 734 /* Allocate memory and accumulate all destination information */ 735 len = (len * sizeof (ibcm_dest_t)) + sizeof (ibcm_dinfo_t); 736 737 dinfo = kmem_zalloc(len, KM_SLEEP); 738 dinfo->num_dest = num_dest; 739 if (p_arg->flags & IBT_PATH_PKEY) 740 dinfo->p_key = p_arg->attr.pa_pkey; 741 742 for (i = 0, j = 0; i < num_dest; i++) { 743 if (i < p_arg->attr.pa_num_dgids) 744 dinfo->dest[i].d_gid = p_arg->attr.pa_dgids[i]; 745 else 746 dinfo->dest[i].d_gid = d_gids_p[j++]; 747 } 748 749 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*p_arg)) 750 751 /* IBTF allocates memory for path_info in case of Async Get Paths */ 752 if (p_arg->paths == NULL) 753 p_arg->paths = kmem_zalloc(sizeof (ibt_path_info_t) * max_paths, 754 KM_SLEEP); 755 756 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*p_arg)) 757 758 /* Checkout whether user has specified SGID. */ 759 if (p_arg->attr.pa_sgid.gid_prefix && p_arg->attr.pa_sgid.gid_guid) { 760 ibtl_cm_hca_port_t hport; 761 762 IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_paths: SGID %llX:%llX", 763 p_arg->attr.pa_sgid.gid_prefix, 764 p_arg->attr.pa_sgid.gid_guid); 765 766 /* For the specified SGID, get HCA information. */ 767 retval = ibtl_cm_get_hca_port(p_arg->attr.pa_sgid, 768 p_arg->attr.pa_hca_guid, &hport); 769 if (retval != IBT_SUCCESS) { 770 IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths: " 771 "Get HCA Port Failed: %d", retval); 772 goto path_error; 773 } 774 775 if ((p_arg->attr.pa_hca_port_num != 0) && 776 (p_arg->attr.pa_hca_port_num != hport.hp_port)) { 777 IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths: " 778 "Mis-match input HCA PortNum v/s SGID"); 779 retval = IBT_HCA_PORT_INVALID; 780 goto path_error; 781 } 782 783 /* 784 * If a specific MTU is desired, then first check out whether 785 * this source port is capable of this MTU. 786 */ 787 if (p_arg->attr.pa_mtu.r_mtu) { 788 if ((p_arg->attr.pa_mtu.r_selector == IBT_GT) && 789 (p_arg->attr.pa_mtu.r_mtu >= hport.hp_mtu)) { 790 791 IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths:" 792 " Required MTU not available on this Port. " 793 "Requested IBT_GT 0x%x but avail 0x%x", 794 p_arg->attr.pa_mtu.r_mtu, hport.hp_mtu); 795 796 retval = IBT_INVALID_PARAM; 797 goto path_error; 798 } else if ((p_arg->attr.pa_mtu.r_selector == IBT_EQU) && 799 (p_arg->attr.pa_mtu.r_mtu > hport.hp_mtu)) { 800 IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths:" 801 " Required MTU not available on this Port " 802 "Requested IBT_EQU to 0x%x but avail 0x%x", 803 p_arg->attr.pa_mtu.r_mtu, hport.hp_mtu); 804 805 retval = IBT_INVALID_PARAM; 806 goto path_error; 807 } 808 } 809 810 if (p_arg->flags & IBT_PATH_APM) { 811 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*p_arg)) 812 p_arg->attr.pa_hca_guid = hport.hp_hca_guid; 813 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*p_arg)) 814 815 retval = ibtl_cm_get_active_plist(&p_arg->attr, 816 p_arg->flags, &slistp); 817 if (retval != IBT_SUCCESS) { 818 IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths:" 819 " ibtl_cm_get_active_plist returned error " 820 " %d", retval); 821 goto path_error; 822 } 823 } else { 824 slistp = kmem_zalloc(sizeof (ibtl_cm_port_list_t), 825 KM_SLEEP); 826 827 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*slistp)) 828 slistp->p_hca_guid = hport.hp_hca_guid; 829 slistp->p_mtu = hport.hp_mtu; 830 slistp->p_port_num = hport.hp_port; 831 slistp->p_base_lid = hport.hp_base_lid; 832 slistp->p_sgid = p_arg->attr.pa_sgid; 833 slistp->p_sgid_ix = hport.hp_sgid_ix; 834 slistp->p_count = 1; 835 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*slistp)) 836 } 837 } else { 838 /* Source GID is not specified, but so let's find them. */ 839 if (p_arg->attr.pa_hca_guid) 840 IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_paths: Get " 841 "Paths from HCA (%llX)", p_arg->attr.pa_hca_guid); 842 else 843 IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_paths: SRC " 844 "Point not specified, flags(%X)", p_arg->flags); 845 /* 846 * Get list of active HCA<->Port list, that matches input 847 * specified attr. 848 */ 849 retval = ibtl_cm_get_active_plist(&p_arg->attr, p_arg->flags, 850 &slistp); 851 if (retval != IBT_SUCCESS) { 852 IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths: " 853 "HCA capable of requested source attributes NOT " 854 "available."); 855 goto path_error; 856 } 857 } 858 859 IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_paths: HCA (%llX, %d)", 860 slistp->p_hca_guid, slistp->p_port_num); 861 862 hcap = ibcm_find_hca_entry(slistp->p_hca_guid); 863 if (hcap == NULL) { 864 IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths: " 865 "NO HCA found"); 866 retval = IBT_HCA_BUSY_DETACHING; 867 goto path_error; 868 } 869 870 /* Get SA Access Handle. */ 871 for (i = 0; i < slistp->p_count; i++) { 872 if (i == 0) { 873 /* Validate whether this HCA supports APM */ 874 if ((p_arg->flags & IBT_PATH_APM) && 875 (!(hcap->hca_caps & IBT_HCA_AUTO_PATH_MIG))) { 876 IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths:" 877 " HCA (%llX): APM NOT SUPPORTED ", 878 slistp[i].p_hca_guid); 879 retval = IBT_APM_NOT_SUPPORTED; 880 goto path_error1; 881 } 882 } 883 884 saa_handle = ibcm_get_saa_handle(hcap, slistp[i].p_port_num); 885 if (saa_handle == NULL) { 886 IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths: " 887 "SAA HDL NULL, HCA (%llX:%d) NOT ACTIVE", 888 slistp[i].p_hca_guid, slistp[i].p_port_num); 889 retval = IBT_HCA_PORT_NOT_ACTIVE; 890 goto path_error1; 891 } 892 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*slistp)) 893 slistp[i].p_saa_hdl = saa_handle; 894 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*slistp)) 895 } 896 897 /* 898 * If Service Name or Service ID are specified, first retrieve 899 * Service Records. 900 */ 901 if ((p_arg->attr.pa_sid != 0) || ((p_arg->attr.pa_sname != NULL) && 902 (strlen(p_arg->attr.pa_sname) != 0))) { 903 904 IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_paths: Get Service " 905 "Record for \n\t(%llX, \"%s\")", p_arg->attr.pa_sid, 906 ((p_arg->attr.pa_sname != NULL) ? 907 p_arg->attr.pa_sname : "")); 908 909 /* Get Service Records. */ 910 retval = ibcm_saa_service_rec(p_arg, slistp, dinfo); 911 if ((retval != IBT_SUCCESS) && (retval != IBT_INSUFF_DATA)) { 912 IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths: Status=" 913 "%d, Failed to get Service Record for \n\t" 914 "(%llX, \"%s\")", retval, p_arg->attr.pa_sid, 915 ((p_arg->attr.pa_sname != NULL) ? 916 p_arg->attr.pa_sname : "")); 917 goto path_error1; 918 } 919 } 920 921 /* Get Path Records. */ 922 retval = ibcm_saa_path_rec(p_arg, slistp, dinfo, &num_path); 923 924 path_error1: 925 ibcm_dec_hca_acc_cnt(hcap); 926 927 path_error: 928 if (slistp) 929 ibtl_cm_free_active_plist(slistp); 930 931 if (dinfo) 932 kmem_free(dinfo, len); 933 934 path_error2: 935 if ((retval != IBT_SUCCESS) && (retval != IBT_INSUFF_DATA)) 936 num_path = 0; 937 938 if (p_arg->num_paths_p != NULL) 939 *p_arg->num_paths_p = num_path; 940 941 if ((dnum) && (d_gids_p)) 942 kmem_free(d_gids_p, dnum * sizeof (ib_gid_t)); 943 944 if (p_arg->func) { /* Do these only for Async Get Paths */ 945 ibt_path_info_t *tmp_path_p; 946 947 if (retval == IBT_INSUFF_DATA) { 948 /* 949 * We allocated earlier memory based on "max_paths", 950 * but we got lesser path-records, so re-adjust that 951 * buffer so that caller can free the correct memory. 952 */ 953 tmp_path_p = kmem_alloc( 954 sizeof (ibt_path_info_t) * num_path, KM_SLEEP); 955 956 bcopy(p_arg->paths, tmp_path_p, 957 num_path * sizeof (ibt_path_info_t)); 958 959 kmem_free(p_arg->paths, 960 sizeof (ibt_path_info_t) * max_paths); 961 } else if (retval != IBT_SUCCESS) { 962 if (p_arg->paths) 963 kmem_free(p_arg->paths, 964 sizeof (ibt_path_info_t) * max_paths); 965 tmp_path_p = NULL; 966 } else { 967 tmp_path_p = p_arg->paths; 968 } 969 (*(p_arg->func))(p_arg->arg, retval, tmp_path_p, num_path); 970 } 971 972 len = (sizeof (ib_gid_t) * p_arg->attr.pa_num_dgids) + 973 sizeof (ibcm_path_tqargs_t); 974 975 if (p_arg && len) 976 kmem_free(p_arg, len); 977 978 IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths: done: status %d, " 979 "Found %d/%d Path Records", retval, num_path, max_paths); 980 981 return (retval); 982 } 983 984 985 /* 986 * Perform SA Access to retrieve Path Records. 987 */ 988 static ibt_status_t 989 ibcm_saa_path_rec(ibcm_path_tqargs_t *p_arg, ibtl_cm_port_list_t *sl, 990 ibcm_dinfo_t *dinfo, uint8_t *max_count) 991 { 992 uint8_t num_path = *max_count; 993 uint8_t num_path_plus; 994 uint_t extra, idx, rec_found = 0; 995 ibt_status_t retval = IBT_SUCCESS; 996 int unicast_dgid_present = 0; 997 uint8_t i; 998 999 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec(%p, %p, %p, 0x%X, %d)", 1000 p_arg, sl, dinfo, p_arg->flags, *max_count); 1001 1002 if ((dinfo->num_dest == 0) || (num_path == 0) || (sl == NULL)) { 1003 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec: Invalid Counters"); 1004 return (IBT_INVALID_PARAM); 1005 } 1006 1007 /* 1008 * Of the total needed "X" number of paths to "Y" number of destination 1009 * we need to get X/Y plus X%Y extra paths to each destination, 1010 * We do this so that we can choose the required number of path records 1011 * for the specific destination. 1012 */ 1013 num_path /= dinfo->num_dest; 1014 extra = (*max_count % dinfo->num_dest); 1015 1016 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec: numpath %d extra %d dest %d", 1017 num_path, extra, dinfo->num_dest); 1018 1019 /* 1020 * Find out whether we need to get PathRecord for a MGID as DGID or 1021 * qualifies for a LoopBack. 1022 */ 1023 for (idx = 0; idx < dinfo->num_dest; idx++) { 1024 ib_gid_t dgid = dinfo->dest[idx].d_gid; 1025 1026 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec: DGID[%d]: %llX:%llX", 1027 idx, dgid.gid_prefix, dgid.gid_guid); 1028 1029 if ((dgid.gid_prefix >> 56ULL & 0xFF) == 0xFF) { 1030 if (extra) 1031 num_path_plus = num_path + 1; 1032 else 1033 num_path_plus = num_path; 1034 1035 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec: Get %d Paths" 1036 "- MGID(%016llX%016llX)", num_path_plus, 1037 dgid.gid_prefix, dgid.gid_guid); 1038 1039 dinfo->dest[idx].d_tag = 1; /* MultiCast */ 1040 1041 /* Yes, it's Single PathRec query for MGID as DGID. */ 1042 retval = ibcm_get_single_pathrec(p_arg, sl, dinfo, idx, 1043 &num_path_plus, &p_arg->paths[rec_found]); 1044 if ((retval != IBT_SUCCESS) && 1045 (retval != IBT_INSUFF_DATA)) { 1046 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec: " 1047 "Failed to get PathRec for MGID %d", 1048 retval); 1049 continue; 1050 } 1051 if (extra) 1052 extra--; 1053 1054 rec_found += num_path_plus; 1055 } else { 1056 /* 1057 * Check out whether we are looking for loop-back path 1058 * info. In this case, we should not contact SA Access 1059 * for Path Records, but instead we need to "synthesize" 1060 * a loop back path record. 1061 */ 1062 for (i = 0; i < sl->p_count; i++) { 1063 if ((sl[i].p_sgid.gid_prefix == 1064 dgid.gid_prefix) && 1065 (sl[i].p_sgid.gid_guid == dgid.gid_guid)) { 1066 1067 dinfo->dest[idx].d_tag = 2; 1068 1069 /* Yes, it's loop back case. */ 1070 retval = ibcm_fillin_loopbackinfo( 1071 &sl[i], idx, dinfo, 1072 &p_arg->paths[rec_found]); 1073 if (retval != IBT_SUCCESS) 1074 break; 1075 1076 /* 1077 * We update only one record for 1078 * loop-back case. 1079 */ 1080 rec_found++; 1081 if (rec_found == *max_count) 1082 break; 1083 } 1084 } 1085 } 1086 if (rec_found == *max_count) 1087 break; 1088 } 1089 1090 for (i = 0; i < dinfo->num_dest; i++) { 1091 if (dinfo->dest[i].d_tag == 0) { 1092 unicast_dgid_present++; 1093 } 1094 } 1095 1096 num_path_plus = *max_count - rec_found; 1097 1098 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec: Recfound: %d, need to find " 1099 "%d, UniCastGID present %d", rec_found, num_path_plus, 1100 unicast_dgid_present); 1101 1102 if ((unicast_dgid_present != 0) && (num_path_plus > 0)) { 1103 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec: MultiSM=%X, #SRC=%d," 1104 "Dest%d", sl->p_multi, sl->p_count, unicast_dgid_present); 1105 1106 if ((sl->p_multi != IBTL_CM_SIMPLE_SETUP) || 1107 ((unicast_dgid_present == 1) && (sl->p_count == 1))) { 1108 /* 1109 * Use SinglePathRec if we are dealing w/ MultiSM or 1110 * request is for one SGID to one DGID. 1111 */ 1112 retval = ibcm_get_single_pathrec(p_arg, sl, dinfo, 0xFF, 1113 &num_path_plus, &p_arg->paths[rec_found]); 1114 } else { 1115 /* MultiPathRec will be used for other queries. */ 1116 retval = ibcm_get_multi_pathrec(p_arg, sl, dinfo, 1117 &num_path_plus, &p_arg->paths[rec_found]); 1118 } 1119 if ((retval != IBT_SUCCESS) && (retval != IBT_INSUFF_DATA)) { 1120 IBTF_DPRINTF_L2(cmlog, "ibcm_saa_path_rec: " 1121 "Failed to get PathRec: Status %d", retval); 1122 } else { 1123 rec_found += num_path_plus; 1124 } 1125 } 1126 1127 if ((rec_found == 0) && (retval == IBT_SUCCESS)) 1128 retval = IBT_PATH_RECORDS_NOT_FOUND; 1129 else if (rec_found != *max_count) 1130 retval = IBT_INSUFF_DATA; 1131 else if (rec_found != 0) 1132 retval = IBT_SUCCESS; 1133 1134 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec: done. Status = %d, " 1135 "Found %d/%d Paths", retval, rec_found, *max_count); 1136 1137 *max_count = rec_found; /* Update the return count. */ 1138 1139 return (retval); 1140 } 1141 1142 ibt_status_t 1143 ibcm_contact_sa_access(ibmf_saa_handle_t saa_handle, 1144 ibmf_saa_access_args_t *access_args, size_t *length, void **results_p) 1145 { 1146 int retry; 1147 int sa_retval; 1148 1149 IBTF_DPRINTF_L3(cmlog, "ibcm_contact_sa_access(%p, %p)", 1150 saa_handle, access_args); 1151 1152 ibcm_sa_access_enter(); 1153 1154 for (retry = 0; retry < ibcm_max_sa_retries; retry++) { 1155 sa_retval = ibmf_sa_access(saa_handle, access_args, 0, 1156 length, results_p); 1157 if (sa_retval != IBMF_TRANS_TIMEOUT) 1158 break; 1159 1160 IBTF_DPRINTF_L2(cmlog, "ibcm_contact_sa_access: " 1161 "ibmf_sa_access() - Timed Out (%d)", sa_retval); 1162 delay(ibcm_sa_timeout_delay); 1163 } 1164 1165 ibcm_sa_access_exit(); 1166 1167 if ((sa_retval == IBMF_SUCCESS) || (sa_retval == IBMF_NO_RECORDS) || 1168 (sa_retval == IBMF_REQ_INVALID)) { 1169 IBTF_DPRINTF_L3(cmlog, "ibcm_contact_sa_access: " 1170 "ibmf_sa_access() returned (%d)", sa_retval); 1171 return (IBT_SUCCESS); 1172 } else { 1173 IBTF_DPRINTF_L2(cmlog, "ibcm_contact_sa_access: " 1174 "ibmf_sa_access(): Failed (%d)", sa_retval); 1175 return (ibcm_ibmf_analyze_error(sa_retval)); 1176 } 1177 } 1178 1179 1180 static ibt_status_t 1181 ibcm_update_pri(sa_path_record_t *pr_resp, ibtl_cm_port_list_t *sl, 1182 ibcm_dinfo_t *dinfo, ibt_path_info_t *paths) 1183 { 1184 ibt_status_t retval = IBT_SUCCESS; 1185 int d, s; 1186 1187 retval = ibcm_update_cep_info(pr_resp, sl, NULL, 1188 &paths->pi_prim_cep_path); 1189 if (retval != IBT_SUCCESS) 1190 return (retval); 1191 1192 /* Update some leftovers */ 1193 paths->pi_prim_pkt_lt = pr_resp->PacketLifeTime; 1194 paths->pi_path_mtu = pr_resp->Mtu; 1195 1196 for (d = 0; d < dinfo->num_dest; d++) { 1197 if (pr_resp->DGID.gid_guid == dinfo->dest[d].d_gid.gid_guid) { 1198 paths->pi_sid = dinfo->dest[d].d_sid; 1199 if (paths->pi_sid != 0) { 1200 bcopy(&dinfo->dest[d].d_sdata, 1201 &paths->pi_sdata, sizeof (ibt_srv_data_t)); 1202 } 1203 break; 1204 } 1205 } 1206 1207 for (s = 0; s < sl->p_count; s++) { 1208 if (pr_resp->SGID.gid_guid == sl[s].p_sgid.gid_guid) { 1209 paths->pi_hca_guid = sl[s].p_hca_guid; 1210 } 1211 } 1212 1213 /* Set Alternate Path to invalid state. */ 1214 paths->pi_alt_cep_path.cep_hca_port_num = 0; 1215 paths->pi_alt_cep_path.cep_adds_vect.av_dlid = 0; 1216 1217 IBTF_DPRINTF_L5(cmlog, "Path: HCA GUID = 0x%llX", paths->pi_hca_guid); 1218 IBTF_DPRINTF_L5(cmlog, "Path: ServiceID = 0x%llX", paths->pi_sid); 1219 1220 return (retval); 1221 } 1222 1223 1224 static ibt_status_t 1225 ibcm_get_single_pathrec(ibcm_path_tqargs_t *p_arg, ibtl_cm_port_list_t *sl, 1226 ibcm_dinfo_t *dinfo, uint8_t idx, uint8_t *num_path, ibt_path_info_t *paths) 1227 { 1228 sa_path_record_t pathrec_req; 1229 sa_path_record_t *pr_resp; 1230 ibmf_saa_access_args_t access_args; 1231 uint64_t c_mask = 0; 1232 void *results_p; 1233 uint8_t num_rec; 1234 size_t length; 1235 ibt_status_t retval; 1236 int i, j, k; 1237 int found, p_fnd; 1238 ibt_path_attr_t *attrp = &p_arg->attr; 1239 ibmf_saa_handle_t saa_handle; 1240 1241 IBTF_DPRINTF_L3(cmlog, "ibcm_get_single_pathrec(%p, %p, %p, %d)", 1242 p_arg, sl, dinfo, *num_path); 1243 1244 bzero(&pathrec_req, sizeof (sa_path_record_t)); 1245 1246 /* Is Flow Label Specified. */ 1247 if (attrp->pa_flow) { 1248 pathrec_req.FlowLabel = attrp->pa_flow; 1249 c_mask |= SA_PR_COMPMASK_FLOWLABEL; 1250 } 1251 1252 /* Is HopLimit Specified. */ 1253 if (p_arg->flags & IBT_PATH_HOP) { 1254 pathrec_req.HopLimit = attrp->pa_hop; 1255 c_mask |= SA_PR_COMPMASK_HOPLIMIT; 1256 } 1257 1258 /* Is P_Key Specified. */ 1259 if (dinfo->p_key) { 1260 IBTF_DPRINTF_L3(cmlog, "ibcm_get_single_pathrec: " 1261 "Specified or Global PKEY 0x%X", dinfo->p_key); 1262 pathrec_req.P_Key = dinfo->p_key; 1263 c_mask |= SA_PR_COMPMASK_PKEY; 1264 } 1265 1266 /* Is TClass Specified. */ 1267 if (attrp->pa_tclass) { 1268 pathrec_req.TClass = attrp->pa_tclass; 1269 c_mask |= SA_PR_COMPMASK_TCLASS; 1270 } 1271 1272 /* Is SL specified. */ 1273 if (attrp->pa_sl) { 1274 pathrec_req.SL = attrp->pa_sl; 1275 c_mask |= SA_PR_COMPMASK_SL; 1276 } 1277 1278 /* If IBT_PATH_PERF is set, then mark all selectors to BEST. */ 1279 if (p_arg->flags & IBT_PATH_PERF) { 1280 pathrec_req.PacketLifeTimeSelector = IBT_BEST; 1281 pathrec_req.MtuSelector = IBT_BEST; 1282 pathrec_req.RateSelector = IBT_BEST; 1283 1284 c_mask |= SA_PR_COMPMASK_PKTLTSELECTOR | 1285 SA_PR_COMPMASK_RATESELECTOR | SA_PR_COMPMASK_MTUSELECTOR; 1286 } else { 1287 if (attrp->pa_pkt_lt.p_selector == IBT_BEST) { 1288 pathrec_req.PacketLifeTimeSelector = IBT_BEST; 1289 c_mask |= SA_PR_COMPMASK_PKTLTSELECTOR; 1290 } 1291 1292 if (attrp->pa_srate.r_selector == IBT_BEST) { 1293 pathrec_req.RateSelector = IBT_BEST; 1294 c_mask |= SA_PR_COMPMASK_RATESELECTOR; 1295 } 1296 1297 if (attrp->pa_mtu.r_selector == IBT_BEST) { 1298 pathrec_req.MtuSelector = IBT_BEST; 1299 c_mask |= SA_PR_COMPMASK_MTUSELECTOR; 1300 } 1301 } 1302 1303 /* 1304 * Honor individual selection of these attributes, 1305 * even if IBT_PATH_PERF is set. 1306 */ 1307 /* Check out whether Packet Life Time is specified. */ 1308 if (attrp->pa_pkt_lt.p_pkt_lt) { 1309 pathrec_req.PacketLifeTime = 1310 ibt_usec2ib(attrp->pa_pkt_lt.p_pkt_lt); 1311 pathrec_req.PacketLifeTimeSelector = 1312 attrp->pa_pkt_lt.p_selector; 1313 1314 c_mask |= SA_PR_COMPMASK_PKTLT | SA_PR_COMPMASK_PKTLTSELECTOR; 1315 } 1316 1317 /* Is SRATE specified. */ 1318 if (attrp->pa_srate.r_srate) { 1319 pathrec_req.Rate = attrp->pa_srate.r_srate; 1320 pathrec_req.RateSelector = attrp->pa_srate.r_selector; 1321 1322 c_mask |= SA_PR_COMPMASK_RATE | SA_PR_COMPMASK_RATESELECTOR; 1323 } 1324 1325 /* Is MTU specified. */ 1326 if (attrp->pa_mtu.r_mtu) { 1327 pathrec_req.Mtu = attrp->pa_mtu.r_mtu; 1328 pathrec_req.MtuSelector = attrp->pa_mtu.r_selector; 1329 1330 c_mask |= SA_PR_COMPMASK_MTU | SA_PR_COMPMASK_MTUSELECTOR; 1331 } 1332 1333 /* We always get REVERSIBLE paths. */ 1334 pathrec_req.Reversible = 1; 1335 c_mask |= SA_PR_COMPMASK_REVERSIBLE; 1336 1337 pathrec_req.NumbPath = *num_path; 1338 c_mask |= SA_PR_COMPMASK_NUMBPATH; 1339 1340 if (idx != 0xFF) { 1341 /* MGID */ 1342 pathrec_req.DGID = dinfo->dest[idx].d_gid; 1343 c_mask |= SA_PR_COMPMASK_DGID; 1344 } 1345 1346 p_fnd = found = 0; 1347 1348 for (i = 0; i < sl->p_count; i++) { 1349 /* SGID */ 1350 pathrec_req.SGID = sl[i].p_sgid; 1351 c_mask |= SA_PR_COMPMASK_SGID; 1352 saa_handle = sl[i].p_saa_hdl; 1353 1354 for (k = 0; k < dinfo->num_dest; k++) { 1355 if (idx == 0xFF) { /* DGID */ 1356 if (dinfo->dest[k].d_tag != 0) 1357 continue; 1358 1359 if (pathrec_req.SGID.gid_prefix != 1360 dinfo->dest[k].d_gid.gid_prefix) { 1361 IBTF_DPRINTF_L3(cmlog, 1362 "ibcm_get_single_pathrec: SGID_pfx=" 1363 "%llX, DGID_pfx=%llX doesn't match", 1364 pathrec_req.SGID.gid_prefix, 1365 dinfo->dest[k].d_gid.gid_prefix); 1366 continue; 1367 } else if (pathrec_req.SGID.gid_guid == 1368 pathrec_req.DGID.gid_guid) { 1369 IBTF_DPRINTF_L3(cmlog, 1370 "ibcm_get_single_pathrec: Why " 1371 "LoopBack request came here!!!! " 1372 "GID(%llX:%llX)", 1373 pathrec_req.SGID.gid_prefix, 1374 pathrec_req.SGID.gid_guid); 1375 continue; 1376 } 1377 1378 pathrec_req.DGID = dinfo->dest[k].d_gid; 1379 c_mask |= SA_PR_COMPMASK_DGID; 1380 1381 /* 1382 * If we had performed Service Look-up, then we 1383 * got P_Key from ServiceRecord, so get path 1384 * records that satisfy this particular P_Key. 1385 */ 1386 if ((dinfo->p_key == 0) && 1387 (dinfo->dest[k].d_pkey != 0)) { 1388 pathrec_req.P_Key = 1389 dinfo->dest[k].d_pkey; 1390 c_mask |= SA_PR_COMPMASK_PKEY; 1391 } 1392 } 1393 1394 IBTF_DPRINTF_L3(cmlog, "ibcm_get_single_pathrec: " 1395 "Get %d Path(s) between\n\tSGID(%llX:%llX) " 1396 "DGID(%llX:%llX)", pathrec_req.NumbPath, 1397 pathrec_req.SGID.gid_prefix, 1398 pathrec_req.SGID.gid_guid, 1399 pathrec_req.DGID.gid_prefix, 1400 pathrec_req.DGID.gid_guid); 1401 1402 IBTF_DPRINTF_L3(cmlog, "ibcm_get_single_pathrec: CMask" 1403 "=0x%llX, PKey=0x%X", c_mask, pathrec_req.P_Key); 1404 1405 /* Contact SA Access to retrieve Path Records. */ 1406 access_args.sq_attr_id = SA_PATHRECORD_ATTRID; 1407 access_args.sq_template = &pathrec_req; 1408 access_args.sq_access_type = IBMF_SAA_RETRIEVE; 1409 access_args.sq_template_length = 1410 sizeof (sa_path_record_t); 1411 access_args.sq_component_mask = c_mask; 1412 access_args.sq_callback = NULL; 1413 access_args.sq_callback_arg = NULL; 1414 1415 retval = ibcm_contact_sa_access(saa_handle, 1416 &access_args, &length, &results_p); 1417 if (retval != IBT_SUCCESS) { 1418 *num_path = 0; 1419 return (retval); 1420 } 1421 1422 num_rec = length / sizeof (sa_path_record_t); 1423 1424 IBTF_DPRINTF_L3(cmlog, "ibcm_get_single_pathrec: " 1425 "FOUND %d/%d path requested", num_rec, *num_path); 1426 1427 if ((results_p == NULL) || (num_rec == 0)) { 1428 if (idx != 0xFF) 1429 break; 1430 else 1431 continue; 1432 } 1433 1434 /* Update the PathInfo from the response. */ 1435 pr_resp = (sa_path_record_t *)results_p; 1436 for (j = 0; j < num_rec; j++, pr_resp++) { 1437 if ((p_fnd != 0) && 1438 (p_arg->flags & IBT_PATH_APM)) { 1439 IBTF_DPRINTF_L3(cmlog, 1440 "ibcm_get_single_pathrec: " 1441 "Fill Alternate Path"); 1442 retval = ibcm_update_cep_info(pr_resp, 1443 sl, NULL, 1444 &paths[found - 1].pi_alt_cep_path); 1445 if (retval != IBT_SUCCESS) 1446 continue; 1447 1448 /* Update some leftovers */ 1449 paths[found - 1].pi_alt_pkt_lt = 1450 pr_resp->PacketLifeTime; 1451 p_fnd = 0; 1452 } else { 1453 IBTF_DPRINTF_L3(cmlog, 1454 "ibcm_get_single_pathrec: " 1455 "Fill Primary Path"); 1456 1457 if (found == *num_path) 1458 break; 1459 1460 retval = ibcm_update_pri(pr_resp, sl, 1461 dinfo, &paths[found]); 1462 if (retval != IBT_SUCCESS) 1463 continue; 1464 p_fnd = 1; 1465 found++; 1466 } 1467 1468 } 1469 /* Deallocate the memory for results_p. */ 1470 kmem_free(results_p, length); 1471 1472 if (idx != 0xFF) 1473 break; /* We r here for MGID */ 1474 } 1475 if ((idx != 0xFF) && (found == *num_path)) 1476 break; /* We r here for MGID */ 1477 } 1478 1479 if (found == 0) 1480 retval = IBT_PATH_RECORDS_NOT_FOUND; 1481 else if (found != *num_path) 1482 retval = IBT_INSUFF_DATA; 1483 else 1484 retval = IBT_SUCCESS; 1485 1486 IBTF_DPRINTF_L3(cmlog, "ibcm_get_single_pathrec: done. Status %d, " 1487 "Found %d/%d Paths", retval, found, *num_path); 1488 1489 *num_path = found; 1490 1491 return (retval); 1492 } 1493 1494 1495 static ibt_status_t 1496 ibcm_get_multi_pathrec(ibcm_path_tqargs_t *p_arg, ibtl_cm_port_list_t *sl, 1497 ibcm_dinfo_t *dinfo, uint8_t *num_path, ibt_path_info_t *paths) 1498 { 1499 sa_multipath_record_t *mpr_req; 1500 sa_path_record_t *pr_resp; 1501 ibmf_saa_access_args_t access_args; 1502 void *results_p; 1503 uint64_t c_mask = 0; 1504 ib_gid_t *gid_ptr, *gid_s_ptr; 1505 size_t length; 1506 int template_len, found, num_rec; 1507 int i, k; 1508 ibt_status_t retval; 1509 uint8_t sgid_cnt, dgid_cnt; 1510 ibt_path_attr_t *attrp = &p_arg->attr; 1511 1512 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec(%p, %p, %p, %d)", 1513 attrp, sl, dinfo, *num_path); 1514 1515 for (i = 0, dgid_cnt = 0; i < dinfo->num_dest; i++) { 1516 if (dinfo->dest[i].d_tag == 0) 1517 dgid_cnt++; 1518 } 1519 1520 sgid_cnt = sl->p_count; 1521 1522 if ((sgid_cnt == 0) || (dgid_cnt == 0)) { 1523 IBTF_DPRINTF_L2(cmlog, "ibcm_get_multi_pathrec: sgid_cnt(%d) or" 1524 " dgid_cnt(%d) is zero", sgid_cnt, dgid_cnt); 1525 return (IBT_INVALID_PARAM); 1526 } 1527 1528 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: Get %d records between " 1529 "%d Src(s) <=> %d Dest(s)", *num_path, sgid_cnt, dgid_cnt); 1530 1531 /* 1532 * Calculate the size for multi-path records template, which includes 1533 * constant portion of the multipath record, plus variable size for 1534 * SGID (sgid_cnt) and DGID (dgid_cnt). 1535 */ 1536 template_len = ((dgid_cnt + sgid_cnt) * sizeof (ib_gid_t)) + 1537 sizeof (sa_multipath_record_t); 1538 1539 mpr_req = kmem_zalloc(template_len, KM_SLEEP); 1540 1541 ASSERT(mpr_req != NULL); 1542 1543 gid_ptr = (ib_gid_t *)(((uchar_t *)mpr_req) + 1544 sizeof (sa_multipath_record_t)); 1545 1546 /* Get the starting pointer where GIDs are stored. */ 1547 gid_s_ptr = gid_ptr; 1548 1549 /* SGID */ 1550 for (i = 0; i < sl->p_count; i++) { 1551 *gid_ptr = sl[i].p_sgid; 1552 1553 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: SGID[%d] = " 1554 "(%llX:%llX)", i, gid_ptr->gid_prefix, gid_ptr->gid_guid); 1555 1556 gid_ptr++; 1557 } 1558 1559 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mpr_req)) 1560 1561 mpr_req->SGIDCount = sgid_cnt; 1562 c_mask = SA_MPR_COMPMASK_SGIDCOUNT; 1563 1564 /* DGIDs */ 1565 for (i = 0; i < dinfo->num_dest; i++) { 1566 if (dinfo->dest[i].d_tag == 0) { 1567 *gid_ptr = dinfo->dest[i].d_gid; 1568 1569 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: " 1570 "DGID[%d] = (%llX:%llX)", i, gid_ptr->gid_prefix, 1571 gid_ptr->gid_guid); 1572 gid_ptr++; 1573 } 1574 } 1575 1576 mpr_req->DGIDCount = dgid_cnt; 1577 c_mask |= SA_MPR_COMPMASK_DGIDCOUNT; 1578 1579 /* Is Flow Label Specified. */ 1580 if (attrp->pa_flow) { 1581 mpr_req->FlowLabel = attrp->pa_flow; 1582 c_mask |= SA_MPR_COMPMASK_FLOWLABEL; 1583 } 1584 1585 /* Is HopLimit Specified. */ 1586 if (p_arg->flags & IBT_PATH_HOP) { 1587 mpr_req->HopLimit = attrp->pa_hop; 1588 c_mask |= SA_MPR_COMPMASK_HOPLIMIT; 1589 } 1590 1591 /* Is TClass Specified. */ 1592 if (attrp->pa_tclass) { 1593 mpr_req->TClass = attrp->pa_tclass; 1594 c_mask |= SA_MPR_COMPMASK_TCLASS; 1595 } 1596 1597 /* Is SL specified. */ 1598 if (attrp->pa_sl) { 1599 mpr_req->SL = attrp->pa_sl; 1600 c_mask |= SA_MPR_COMPMASK_SL; 1601 } 1602 1603 if (p_arg->flags & IBT_PATH_PERF) { 1604 mpr_req->PacketLifeTimeSelector = IBT_BEST; 1605 mpr_req->RateSelector = IBT_BEST; 1606 mpr_req->MtuSelector = IBT_BEST; 1607 1608 c_mask |= SA_MPR_COMPMASK_PKTLTSELECTOR | 1609 SA_MPR_COMPMASK_RATESELECTOR | SA_MPR_COMPMASK_MTUSELECTOR; 1610 } else { 1611 if (attrp->pa_pkt_lt.p_selector == IBT_BEST) { 1612 mpr_req->PacketLifeTimeSelector = IBT_BEST; 1613 c_mask |= SA_MPR_COMPMASK_PKTLTSELECTOR; 1614 } 1615 1616 if (attrp->pa_srate.r_selector == IBT_BEST) { 1617 mpr_req->RateSelector = IBT_BEST; 1618 c_mask |= SA_MPR_COMPMASK_RATESELECTOR; 1619 } 1620 1621 if (attrp->pa_mtu.r_selector == IBT_BEST) { 1622 mpr_req->MtuSelector = IBT_BEST; 1623 c_mask |= SA_MPR_COMPMASK_MTUSELECTOR; 1624 } 1625 } 1626 1627 /* 1628 * Honor individual selection of these attributes, 1629 * even if IBT_PATH_PERF is set. 1630 */ 1631 /* Check out whether Packet Life Time is specified. */ 1632 if (attrp->pa_pkt_lt.p_pkt_lt) { 1633 mpr_req->PacketLifeTime = 1634 ibt_usec2ib(attrp->pa_pkt_lt.p_pkt_lt); 1635 mpr_req->PacketLifeTimeSelector = 1636 attrp->pa_pkt_lt.p_selector; 1637 1638 c_mask |= SA_MPR_COMPMASK_PKTLT | 1639 SA_MPR_COMPMASK_PKTLTSELECTOR; 1640 } 1641 1642 /* Is SRATE specified. */ 1643 if (attrp->pa_srate.r_srate) { 1644 mpr_req->Rate = attrp->pa_srate.r_srate; 1645 mpr_req->RateSelector = attrp->pa_srate.r_selector; 1646 1647 c_mask |= SA_MPR_COMPMASK_RATE | 1648 SA_MPR_COMPMASK_RATESELECTOR; 1649 } 1650 1651 /* Is MTU specified. */ 1652 if (attrp->pa_mtu.r_mtu) { 1653 mpr_req->Mtu = attrp->pa_mtu.r_mtu; 1654 mpr_req->MtuSelector = attrp->pa_mtu.r_selector; 1655 1656 c_mask |= SA_MPR_COMPMASK_MTU | 1657 SA_MPR_COMPMASK_MTUSELECTOR; 1658 } 1659 1660 /* Is P_Key Specified or obtained during Service Look-up. */ 1661 if (dinfo->p_key) { 1662 mpr_req->P_Key = dinfo->p_key; 1663 c_mask |= SA_MPR_COMPMASK_PKEY; 1664 } 1665 1666 /* We always get REVERSIBLE paths. */ 1667 mpr_req->Reversible = 1; 1668 c_mask |= SA_MPR_COMPMASK_REVERSIBLE; 1669 1670 if (p_arg->flags & IBT_PATH_AVAIL) { 1671 mpr_req->IndependenceSelector = 1; 1672 c_mask |= SA_MPR_COMPMASK_INDEPSEL; 1673 } 1674 1675 /* we will not specify how many records we want. */ 1676 1677 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*mpr_req)) 1678 1679 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: CMask: %llX Pkey: %X", 1680 c_mask, mpr_req->P_Key); 1681 1682 /* Contact SA Access to retrieve Path Records. */ 1683 access_args.sq_attr_id = SA_MULTIPATHRECORD_ATTRID; 1684 access_args.sq_access_type = IBMF_SAA_RETRIEVE; 1685 access_args.sq_component_mask = c_mask; 1686 access_args.sq_template = mpr_req; 1687 access_args.sq_template_length = sizeof (sa_multipath_record_t); 1688 access_args.sq_callback = NULL; 1689 access_args.sq_callback_arg = NULL; 1690 1691 retval = ibcm_contact_sa_access(sl->p_saa_hdl, &access_args, &length, 1692 &results_p); 1693 if (retval != IBT_SUCCESS) { 1694 *num_path = 0; /* Update the return count. */ 1695 kmem_free(mpr_req, template_len); 1696 return (retval); 1697 } 1698 1699 num_rec = length / sizeof (sa_path_record_t); 1700 1701 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: Found %d Paths", 1702 num_rec); 1703 1704 found = 0; 1705 if ((results_p != NULL) && (num_rec > 0)) { 1706 /* Update the PathInfo with the response Path Records */ 1707 pr_resp = (sa_path_record_t *)results_p; 1708 1709 for (i = 0; i < num_rec; i++) { 1710 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: " 1711 "P[%d]: SG %llX, DG %llX", i, 1712 pr_resp[i].SGID.gid_guid, pr_resp[i].DGID.gid_guid); 1713 } 1714 1715 if (p_arg->flags & IBT_PATH_APM) { 1716 sa_path_record_t *p_resp = NULL, *a_resp = NULL; 1717 int p_found = 0, a_found = 0; 1718 ib_gid_t p_sg, a_sg, p_dg, a_dg; 1719 int s_spec; 1720 1721 s_spec = p_arg->attr.pa_sgid.gid_guid != 0 ? 1 : 0; 1722 1723 p_sg = gid_s_ptr[0]; 1724 if (sgid_cnt > 1) 1725 a_sg = gid_s_ptr[1]; 1726 else 1727 a_sg = p_sg; 1728 1729 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: " 1730 "REQ: P_SG: %llX, A_SG: %llX", 1731 p_sg.gid_guid, a_sg.gid_guid); 1732 1733 p_dg = gid_s_ptr[sgid_cnt]; 1734 if (dgid_cnt > 1) 1735 a_dg = gid_s_ptr[sgid_cnt + 1]; 1736 else 1737 a_dg = p_dg; 1738 1739 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: " 1740 "REQ: P_DG: %llX, A_DG: %llX", 1741 p_dg.gid_guid, a_dg.gid_guid); 1742 1743 /* 1744 * If SGID and/or DGID is specified by user, make sure 1745 * he gets his primary-path on those node points. 1746 */ 1747 for (i = 0; i < num_rec; i++, pr_resp++) { 1748 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec:" 1749 " PF %d, AF %d,\n\t\t P[%d] = SG: %llX, " 1750 "DG: %llX", p_found, a_found, i, 1751 pr_resp->SGID.gid_guid, 1752 pr_resp->DGID.gid_guid); 1753 1754 if ((!p_found) && 1755 (p_dg.gid_guid == pr_resp->DGID.gid_guid)) { 1756 IBTF_DPRINTF_L3(cmlog, 1757 "ibcm_get_multi_pathrec: " 1758 "Pri DGID Match.. "); 1759 if ((s_spec == 0) || (p_sg.gid_guid == 1760 pr_resp->SGID.gid_guid)) { 1761 p_found = 1; 1762 p_resp = pr_resp; 1763 IBTF_DPRINTF_L3(cmlog, 1764 "ibcm_get_multi_pathrec: " 1765 "Primary Path Found"); 1766 1767 if (a_found) 1768 break; 1769 else 1770 continue; 1771 } 1772 IBTF_DPRINTF_L3(cmlog, 1773 "ibcm_get_multi_pathrec:" 1774 "Pri SGID Don't Match.. "); 1775 } 1776 1777 if ((!a_found) && 1778 (a_dg.gid_guid == pr_resp->DGID.gid_guid)) { 1779 IBTF_DPRINTF_L3(cmlog, 1780 "ibcm_get_multi_pathrec:" 1781 "Alt DGID Match.. "); 1782 if ((s_spec == 0) || (a_sg.gid_guid == 1783 pr_resp->SGID.gid_guid)) { 1784 a_found = 1; 1785 a_resp = pr_resp; 1786 1787 IBTF_DPRINTF_L3(cmlog, 1788 "ibcm_get_multi_pathrec:" 1789 "Alternate Path Found "); 1790 1791 if (p_found) 1792 break; 1793 else 1794 continue; 1795 } 1796 IBTF_DPRINTF_L3(cmlog, 1797 "ibcm_get_multi_pathrec:" 1798 "Alt SGID Don't Match.. "); 1799 } 1800 } 1801 1802 if ((p_found == 0) && (a_found == 0)) { 1803 IBTF_DPRINTF_L2(cmlog, "ibcm_get_multi_pathrec:" 1804 " Path to desired node points NOT " 1805 "Available."); 1806 retval = IBT_PATH_RECORDS_NOT_FOUND; 1807 goto get_multi_pathrec_end; 1808 } 1809 1810 if ((p_resp == NULL) && (a_resp != NULL)) { 1811 p_resp = a_resp; 1812 a_resp = NULL; 1813 } 1814 1815 /* Fill in Primary Path */ 1816 retval = ibcm_update_pri(p_resp, sl, dinfo, 1817 &paths[found]); 1818 if (retval != IBT_SUCCESS) 1819 goto get_multi_pathrec_end; 1820 1821 /* Fill in Alternate Path */ 1822 if (a_resp != NULL) { 1823 /* a_resp will point to AltPathInfo buffer. */ 1824 retval = ibcm_update_cep_info(a_resp, sl, 1825 NULL, &paths[found].pi_alt_cep_path); 1826 if (retval != IBT_SUCCESS) 1827 goto get_multi_pathrec_end; 1828 1829 /* Update some leftovers */ 1830 paths[found].pi_alt_pkt_lt = 1831 a_resp->PacketLifeTime; 1832 } else { 1833 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec:" 1834 " Alternate Path NOT Available."); 1835 retval = IBT_INSUFF_DATA; 1836 } 1837 found++; 1838 } else { /* If NOT APM */ 1839 boolean_t check_pkey = B_FALSE; 1840 1841 /* mark flag whether to validate PKey or not. */ 1842 if ((dinfo->p_key == 0) && (dinfo->dest[0].d_pkey != 0)) 1843 check_pkey = B_TRUE; 1844 1845 for (i = 0; i < num_rec; i++, pr_resp++) { 1846 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec:" 1847 " PKeyCheck - %s, PKey=0x%X, DGID(%llX)", 1848 ((check_pkey == B_TRUE)?"REQD":"NOT_REQD"), 1849 pr_resp->P_Key, pr_resp->DGID.gid_guid); 1850 1851 if (check_pkey == B_TRUE) { 1852 boolean_t match_found = B_FALSE; 1853 1854 /* For all DGIDs */ 1855 for (k = 0; k < dinfo->num_dest; k++) { 1856 if (dinfo->dest[k].d_tag != 0) 1857 continue; 1858 1859 if ((dinfo->dest[k].d_gid. 1860 gid_guid == 1861 pr_resp->DGID.gid_guid) && 1862 (dinfo->dest[k].d_pkey == 1863 pr_resp->P_Key)) { 1864 match_found = B_TRUE; 1865 break; 1866 } 1867 } 1868 if (match_found == B_FALSE) 1869 continue; 1870 } 1871 /* Fill in Primary Path */ 1872 retval = ibcm_update_pri(pr_resp, sl, dinfo, 1873 &paths[found]); 1874 if (retval != IBT_SUCCESS) 1875 continue; 1876 1877 if (++found == *num_path) 1878 break; 1879 } 1880 } 1881 get_multi_pathrec_end: 1882 kmem_free(results_p, length); 1883 } 1884 kmem_free(mpr_req, template_len); 1885 1886 if (found == 0) 1887 retval = IBT_PATH_RECORDS_NOT_FOUND; 1888 else if (found != *num_path) 1889 retval = IBT_INSUFF_DATA; 1890 else 1891 retval = IBT_SUCCESS; 1892 1893 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: Done (status %d). " 1894 "Found %d/%d Paths", retval, found, *num_path); 1895 1896 *num_path = found; /* Update the return count. */ 1897 1898 return (retval); 1899 } 1900 1901 1902 /* 1903 * Here we "synthesize" loop back path record information. 1904 * 1905 * Currently the synthesize values are assumed as follows: 1906 * SLID, DLID = Base LID from Query HCA Port. 1907 * FlowLabel, HopLimit, TClass = 0, as GRH is False. 1908 * RawTraffic = 0. 1909 * P_Key = first valid one in P_Key table as obtained from Query HCA Port. 1910 * SL = as from Query HCA Port. 1911 * MTU = from Query HCA Port. 1912 * Rate = 2 (arbitrary). 1913 * PacketLifeTime = 0 (4.096 usec). 1914 */ 1915 static ibt_status_t 1916 ibcm_fillin_loopbackinfo(ibtl_cm_port_list_t *sl, uint8_t index, 1917 ibcm_dinfo_t *dinfo, ibt_path_info_t *paths) 1918 { 1919 ibt_status_t retval; 1920 ib_pkey_t pkey = 0; 1921 1922 IBTF_DPRINTF_L3(cmlog, "ibcm_fillin_loopbackinfo(%p, %p)", sl, dinfo); 1923 1924 /* Synthesize path record with appropriate loop back information. */ 1925 if (dinfo->p_key) 1926 pkey = dinfo->p_key; 1927 else 1928 pkey = dinfo->dest[index].d_pkey; 1929 if (pkey) { 1930 /* Convert P_Key to P_Key_Index */ 1931 retval = ibt_pkey2index_byguid(sl->p_hca_guid, sl->p_port_num, 1932 pkey, &paths->pi_prim_cep_path.cep_pkey_ix); 1933 if (retval != IBT_SUCCESS) { 1934 /* Failed to get pkey_index from pkey */ 1935 IBTF_DPRINTF_L2(cmlog, "ibcm_fillin_loopbackinfo: " 1936 "Pkey2Index (P_Key = %X) conversion failed: %d", 1937 pkey, retval); 1938 return (retval); 1939 } 1940 } else { 1941 paths->pi_prim_cep_path.cep_pkey_ix = 1942 ibtl_cm_get_1st_full_pkey_ix(sl->p_hca_guid, 1943 sl->p_port_num); 1944 IBTF_DPRINTF_L3(cmlog, "ibcm_fillin_loopbackinfo: " 1945 "1st Full Member P_Key_ix = %d", 1946 paths->pi_prim_cep_path.cep_pkey_ix); 1947 } 1948 1949 paths->pi_hca_guid = sl->p_hca_guid; 1950 paths->pi_prim_cep_path.cep_adds_vect.av_dgid = 1951 dinfo->dest[index].d_gid; 1952 paths->pi_prim_cep_path.cep_adds_vect.av_sgid = sl->p_sgid; 1953 paths->pi_prim_cep_path.cep_adds_vect.av_srate = IBT_SRATE_1X; 1954 paths->pi_prim_cep_path.cep_adds_vect.av_srvl = 0; /* SL */ 1955 1956 paths->pi_prim_cep_path.cep_adds_vect.av_send_grh = B_FALSE; 1957 paths->pi_prim_cep_path.cep_adds_vect.av_flow = 0; 1958 paths->pi_prim_cep_path.cep_adds_vect.av_tclass = 0; 1959 paths->pi_prim_cep_path.cep_adds_vect.av_hop = 0; 1960 1961 /* SLID and DLID will be equal to BLID. */ 1962 paths->pi_prim_cep_path.cep_adds_vect.av_dlid = sl->p_base_lid; 1963 paths->pi_prim_cep_path.cep_adds_vect.av_src_path = 0; 1964 paths->pi_prim_cep_path.cep_adds_vect.av_sgid_ix = sl->p_sgid_ix; 1965 paths->pi_prim_cep_path.cep_adds_vect.av_port_num = 1966 paths->pi_prim_cep_path.cep_hca_port_num = sl->p_port_num; 1967 paths->pi_prim_cep_path.cep_timeout = 0; /* To be filled in by CM. */ 1968 paths->pi_path_mtu = sl->p_mtu; /* MTU */ 1969 paths->pi_prim_pkt_lt = 0; /* Packet Life Time. */ 1970 paths->pi_alt_pkt_lt = 0; /* Packet Life Time. */ 1971 1972 paths->pi_sid = dinfo->dest[index].d_sid; 1973 1974 if (paths->pi_sid != 0) 1975 bcopy(&dinfo->dest[index].d_sdata, &paths->pi_sdata, 1976 sizeof (ibt_srv_data_t)); 1977 1978 IBTF_DPRINTF_L3(cmlog, "ibcm_fillin_loopbackinfo: HCA %llX:%d SID %llX" 1979 "\n\t SGID %llX:%llX DGID %llX:%llX", paths->pi_hca_guid, 1980 paths->pi_prim_cep_path.cep_hca_port_num, paths->pi_sid, 1981 sl->p_sgid.gid_prefix, sl->p_sgid.gid_guid, 1982 dinfo->dest[index].d_gid.gid_prefix, 1983 dinfo->dest[index].d_gid.gid_guid); 1984 1985 /* Set Alternate Path to invalid state. */ 1986 paths->pi_alt_cep_path.cep_hca_port_num = 0; 1987 paths->pi_alt_cep_path.cep_adds_vect.av_dlid = 0; 1988 1989 return (IBT_SUCCESS); 1990 } 1991 1992 1993 /* 1994 * Update the output path records buffer with the values as obtained from 1995 * SA Access retrieve call results for Path Records. 1996 */ 1997 static ibt_status_t 1998 ibcm_update_cep_info(sa_path_record_t *prec_resp, ibtl_cm_port_list_t *sl, 1999 ibtl_cm_hca_port_t *hport, ibt_cep_path_t *cep_p) 2000 { 2001 ibt_status_t retval; 2002 int i; 2003 2004 IBCM_DUMP_PATH_REC(prec_resp); 2005 2006 /* 2007 * If path's packet life time is more than 4 seconds, IBCM cannot 2008 * handle this path connection, so discard this path record. 2009 */ 2010 if (prec_resp->PacketLifeTime > ibcm_max_ib_pkt_lt) { 2011 IBTF_DPRINTF_L2(cmlog, "ibcm_update_cep_info: Path's Packet " 2012 "LifeTime too high %d, Maximum allowed %d IB Time (4 sec)", 2013 prec_resp->PacketLifeTime, ibcm_max_ib_pkt_lt); 2014 return (IBT_PATH_PKT_LT_TOO_HIGH); 2015 } 2016 2017 if ((prec_resp->Mtu > IB_MTU_4K) || (prec_resp->Mtu < IB_MTU_256)) { 2018 IBTF_DPRINTF_L2(cmlog, "ibcm_update_cep_info: MTU (%d) from " 2019 "pathrecord is invalid, reject it.", prec_resp->Mtu); 2020 return (ibt_get_module_failure(IBT_FAILURE_IBCM, 0)); 2021 } 2022 2023 /* Source Node Information. */ 2024 cep_p->cep_adds_vect.av_sgid = prec_resp->SGID; 2025 if (hport != NULL) { 2026 /* Convert P_Key to P_Key_Index */ 2027 retval = ibt_pkey2index_byguid(hport->hp_hca_guid, 2028 hport->hp_port, prec_resp->P_Key, &cep_p->cep_pkey_ix); 2029 if (retval != IBT_SUCCESS) { 2030 /* Failed to get pkey_index from pkey */ 2031 IBTF_DPRINTF_L2(cmlog, "ibcm_update_cep_info: " 2032 "Pkey2Index conversion failed: %d", retval); 2033 return (retval); 2034 } 2035 cep_p->cep_adds_vect.av_sgid_ix = hport->hp_sgid_ix; 2036 cep_p->cep_adds_vect.av_src_path = 2037 prec_resp->SLID - hport->hp_base_lid; 2038 cep_p->cep_adds_vect.av_port_num = cep_p->cep_hca_port_num = 2039 hport->hp_port; 2040 } else if (sl != NULL) { 2041 for (i = 0; i < sl->p_count; i++) { 2042 if (prec_resp->SGID.gid_guid == sl[i].p_sgid.gid_guid) { 2043 /* Convert P_Key to P_Key_Index */ 2044 retval = ibt_pkey2index_byguid(sl[i].p_hca_guid, 2045 sl[i].p_port_num, prec_resp->P_Key, 2046 &cep_p->cep_pkey_ix); 2047 if (retval != IBT_SUCCESS) { 2048 /* Failed to get pkey_index from pkey */ 2049 IBTF_DPRINTF_L2(cmlog, 2050 "ibcm_update_cep_info: Pkey2Index " 2051 "conversion failed: %d", retval); 2052 return (retval); 2053 } 2054 2055 cep_p->cep_adds_vect.av_sgid_ix = 2056 sl[i].p_sgid_ix; 2057 cep_p->cep_adds_vect.av_src_path = 2058 prec_resp->SLID - sl[i].p_base_lid; 2059 cep_p->cep_adds_vect.av_port_num = 2060 sl[i].p_port_num; 2061 cep_p->cep_hca_port_num = sl[i].p_port_num; 2062 2063 break; 2064 } 2065 } 2066 } else { 2067 IBTF_DPRINTF_L2(cmlog, "ibcm_update_cep_info: Sl or Hport " 2068 "must be non-null"); 2069 return (IBT_INVALID_PARAM); 2070 } 2071 2072 switch (prec_resp->Rate) { 2073 case IBT_SRATE_1X: 2074 case IBT_SRATE_4X: 2075 case IBT_SRATE_12X: 2076 cep_p->cep_adds_vect.av_srate = prec_resp->Rate; 2077 break; 2078 default: 2079 IBTF_DPRINTF_L2(cmlog, "ibcm_update_cep_info: SRate (%d) from " 2080 "pathrecord is invalid, reject it.", prec_resp->Rate); 2081 return (IBT_STATIC_RATE_INVALID); 2082 } 2083 /* 2084 * If both Source and Destination GID prefix are same, then GRH is not 2085 * valid, so make it as false, else set this field as true. 2086 */ 2087 if (prec_resp->SGID.gid_prefix == prec_resp->DGID.gid_prefix) 2088 cep_p->cep_adds_vect.av_send_grh = B_FALSE; 2089 else 2090 cep_p->cep_adds_vect.av_send_grh = B_TRUE; 2091 2092 /* SGID and SGID Index. */ 2093 cep_p->cep_adds_vect.av_sgid = prec_resp->SGID; 2094 cep_p->cep_adds_vect.av_flow = prec_resp->FlowLabel; 2095 cep_p->cep_adds_vect.av_tclass = prec_resp->TClass; 2096 cep_p->cep_adds_vect.av_hop = prec_resp->HopLimit; 2097 2098 /* Address Vector Definition. */ 2099 cep_p->cep_adds_vect.av_dlid = prec_resp->DLID; 2100 cep_p->cep_adds_vect.av_srvl = prec_resp->SL; 2101 2102 /* DGID */ 2103 cep_p->cep_adds_vect.av_dgid = prec_resp->DGID; 2104 2105 /* CEP Timeout is NOT filled in by PATH routines. */ 2106 cep_p->cep_timeout = 0; 2107 2108 IBTF_DPRINTF_L3(cmlog, "ibcm_update_cep_info: Done. Port[%d]\n" 2109 "SGID=%llX:%llX DGID=%llX:%llX", 2110 cep_p->cep_adds_vect.av_port_num, 2111 prec_resp->SGID.gid_prefix, prec_resp->SGID.gid_guid, 2112 prec_resp->DGID.gid_prefix, prec_resp->DGID.gid_guid); 2113 2114 return (IBT_SUCCESS); 2115 } 2116 2117 2118 static void 2119 ibcm_fill_svcinfo(sa_service_record_t *sr_resp, ibcm_dest_t *dest) 2120 { 2121 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*dest)) 2122 2123 dest->d_gid = sr_resp->ServiceGID; 2124 dest->d_sid = sr_resp->ServiceID; 2125 ibcm_swizzle_to_srv(sr_resp->ServiceData, &dest->d_sdata); 2126 dest->d_pkey = sr_resp->ServiceP_Key; 2127 2128 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*dest)) 2129 2130 IBTF_DPRINTF_L3(cmlog, "ibcm_fill_svcinfo: SID(%llX), GID(%llX:%llX)" 2131 "\n\tSvcPKey 0x%X", dest->d_sid, dest->d_gid.gid_prefix, 2132 dest->d_gid.gid_guid, dest->d_pkey); 2133 } 2134 2135 2136 static ib_gid_t 2137 ibcm_saa_get_agid(ibtl_cm_port_list_t *sl, ib_gid_t *gidp, uint_t ngid) 2138 { 2139 int k, l; 2140 ib_gid_t a_gid; 2141 2142 a_gid.gid_prefix = a_gid.gid_guid = 0; 2143 2144 for (k = 0; k < sl->p_count; k++) { 2145 for (l = 0; l < ngid; l++) { 2146 2147 if (gidp->gid_prefix == sl->p_sgid.gid_prefix) { 2148 a_gid = *gidp; 2149 break; 2150 } 2151 if (a_gid.gid_guid && a_gid.gid_prefix) 2152 break; 2153 gidp++; 2154 } 2155 if (a_gid.gid_guid && a_gid.gid_prefix) 2156 break; 2157 sl++; 2158 } 2159 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_get_agid: AltGID = %llX:%llX", 2160 a_gid.gid_prefix, a_gid.gid_guid); 2161 2162 return (a_gid); 2163 } 2164 2165 /* 2166 * Perform SA Access to retrieve Service Records. 2167 * On Success, returns ServiceID and ServiceGID info in '*dinfo'. 2168 */ 2169 static ibt_status_t 2170 ibcm_saa_service_rec(ibcm_path_tqargs_t *p_arg, ibtl_cm_port_list_t *sl, 2171 ibcm_dinfo_t *dinfo) 2172 { 2173 sa_service_record_t svcrec_req; 2174 sa_service_record_t *svcrec_resp; 2175 void *results_p; 2176 uint64_t component_mask = 0; 2177 size_t length; 2178 uint8_t i, j, k, rec_found, s; 2179 ibmf_saa_access_args_t access_args; 2180 ibt_status_t retval; 2181 ibt_path_attr_t *attrp = &p_arg->attr; 2182 uint64_t tmp_sd_flag = attrp->pa_sd_flags; 2183 uint8_t num_req; 2184 2185 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec(%p, %p)", p_arg, sl); 2186 2187 bzero(&svcrec_req, sizeof (svcrec_req)); 2188 2189 /* Service Name */ 2190 if ((attrp->pa_sname != NULL) && (strlen(attrp->pa_sname) != 0)) { 2191 (void) strncpy((char *)(svcrec_req.ServiceName), 2192 attrp->pa_sname, IB_SVC_NAME_LEN); 2193 2194 component_mask |= SA_SR_COMPMASK_NAME; 2195 } 2196 2197 /* Service ID */ 2198 if (attrp->pa_sid) { 2199 svcrec_req.ServiceID = attrp->pa_sid; 2200 component_mask |= SA_SR_COMPMASK_ID; 2201 } 2202 2203 /* Is P_Key Specified. */ 2204 if (p_arg->flags & IBT_PATH_PKEY) { 2205 svcrec_req.ServiceP_Key = attrp->pa_pkey; 2206 component_mask |= SA_SR_COMPMASK_PKEY; 2207 } 2208 2209 /* Is ServiceData Specified. */ 2210 if (attrp->pa_sd_flags != IBT_NO_SDATA) { 2211 /* Handle endianess for service data. */ 2212 ibcm_swizzle_from_srv(&attrp->pa_sdata, svcrec_req.ServiceData); 2213 2214 /* 2215 * Lets not interpret each and every ServiceData flags, 2216 * just pass it on to SAA. Shift the flag, to suit 2217 * SA_SR_COMPMASK_ALL_DATA definition. 2218 */ 2219 component_mask |= (tmp_sd_flag << 7); 2220 } 2221 2222 if (dinfo->num_dest == 1) { 2223 2224 /* If a single DGID is specified, provide it */ 2225 svcrec_req.ServiceGID = dinfo->dest->d_gid; 2226 component_mask |= SA_SR_COMPMASK_GID; 2227 2228 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec:%llX:%llX", 2229 svcrec_req.ServiceGID.gid_prefix, 2230 svcrec_req.ServiceGID.gid_guid); 2231 } 2232 2233 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: " 2234 "Perform SA Access: Mask: 0x%X", component_mask); 2235 2236 /* 2237 * Call in SA Access retrieve routine to get Service Records. 2238 * 2239 * SA Access framework allocated memory for the "results_p". 2240 * Make sure to deallocate once we are done with the results_p. 2241 * The size of the buffer allocated will be as returned in 2242 * "length" field. 2243 */ 2244 access_args.sq_attr_id = SA_SERVICERECORD_ATTRID; 2245 access_args.sq_access_type = IBMF_SAA_RETRIEVE; 2246 access_args.sq_component_mask = component_mask; 2247 access_args.sq_template = &svcrec_req; 2248 access_args.sq_template_length = sizeof (sa_service_record_t); 2249 access_args.sq_callback = NULL; 2250 access_args.sq_callback_arg = NULL; 2251 2252 for (s = 0; s < sl->p_count; s++) { 2253 retval = ibcm_contact_sa_access(sl[s].p_saa_hdl, &access_args, 2254 &length, &results_p); 2255 if (retval != IBT_SUCCESS) 2256 if (sl[s].p_multi & IBTL_CM_MULTI_SM) 2257 continue; 2258 else 2259 return (retval); 2260 2261 if ((results_p == NULL) || (length == 0)) { 2262 IBTF_DPRINTF_L2(cmlog, "ibcm_saa_service_rec: SvcRec " 2263 "Not Found: res_p %p, len %d", results_p, length); 2264 if (sl[s].p_multi & IBTL_CM_MULTI_SM) { 2265 retval = IBT_SERVICE_RECORDS_NOT_FOUND; 2266 continue; 2267 } else 2268 return (IBT_SERVICE_RECORDS_NOT_FOUND); 2269 } 2270 2271 /* if we are here, we got some records. so break. */ 2272 break; 2273 } 2274 2275 if (retval != IBT_SUCCESS) 2276 return (retval); 2277 2278 num_req = length / sizeof (sa_service_record_t); 2279 2280 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: Got %d Service Records.", 2281 num_req); 2282 2283 svcrec_resp = (sa_service_record_t *)results_p; 2284 rec_found = 0; 2285 2286 /* Update the return values. */ 2287 if (dinfo->num_dest) { 2288 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: Get ServiceRec " 2289 "for Specified DGID: %d", dinfo->num_dest); 2290 2291 for (i = 0; i < num_req; i++, svcrec_resp++) { 2292 /* Limited P_Key is NOT supported as of now!. */ 2293 if ((svcrec_resp->ServiceP_Key & 0x8000) == 0) { 2294 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: " 2295 "SvcPkey 0x%X limited, reject the record.", 2296 svcrec_resp->ServiceP_Key); 2297 continue; 2298 } 2299 2300 for (j = 0; j < dinfo->num_dest; j++) { 2301 if (dinfo->dest[j].d_gid.gid_guid == 2302 svcrec_resp->ServiceGID.gid_guid) { 2303 ibcm_fill_svcinfo(svcrec_resp, 2304 &dinfo->dest[j]); 2305 rec_found++; 2306 } 2307 if (rec_found == dinfo->num_dest) 2308 break; 2309 } 2310 if (rec_found == dinfo->num_dest) 2311 break; 2312 } 2313 if (rec_found != dinfo->num_dest) { 2314 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: Did NOT " 2315 "find ServiceRec for all DGIDs: (%d/%d)", rec_found, 2316 dinfo->num_dest); 2317 retval = IBT_INSUFF_DATA; 2318 } 2319 } else if (p_arg->flags & IBT_PATH_APM) { 2320 ib_gid_t p_gid, a_gid, last_p_gid; 2321 ib_gid_t *gidp = NULL; 2322 uint_t n_gids; 2323 sa_service_record_t *stmp; 2324 boolean_t pri_fill_done = B_FALSE; 2325 boolean_t alt_fill_done = B_FALSE; 2326 ib_pkey_t p_pkey = 0, a_pkey = 0; 2327 2328 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: Need to " 2329 "find ServiceRec that can satisfy APM"); 2330 2331 p_gid.gid_prefix = p_gid.gid_guid = 0; 2332 a_gid.gid_prefix = a_gid.gid_guid = 0; 2333 last_p_gid.gid_prefix = last_p_gid.gid_guid = 0; 2334 2335 for (i = 0; i < num_req; i++, svcrec_resp++) { 2336 ibt_status_t ret; 2337 boolean_t local_node_check_done = B_FALSE; 2338 2339 /* Limited P_Key is NOT supported as of now!. */ 2340 if ((svcrec_resp->ServiceP_Key & 0x8000) == 0) { 2341 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: " 2342 "SvcPkey 0x%X limited, reject the record.", 2343 svcrec_resp->ServiceP_Key); 2344 continue; 2345 } 2346 2347 p_gid = svcrec_resp->ServiceGID; 2348 2349 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: " 2350 "Let DGID(%llX:%llX) be Primary", 2351 p_gid.gid_prefix, p_gid.gid_guid); 2352 2353 /* Let's avoid LoopBack Nodes. */ 2354 if (p_gid.gid_guid == sl->p_sgid.gid_guid) { 2355 local_node_check_done = B_TRUE; 2356 2357 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: " 2358 "Lets Avoid Local Node, " 2359 "search for remote node."); 2360 } 2361 2362 if (local_node_check_done == B_TRUE) { 2363 if ((i + 1) < num_req) { 2364 p_gid.gid_prefix = 0; 2365 p_gid.gid_guid = 0; 2366 continue; 2367 } else if (last_p_gid.gid_prefix != 0) { 2368 p_gid = last_p_gid; 2369 break; 2370 } 2371 } 2372 2373 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: " 2374 "Finally let Primary DGID = %llX:%llX", 2375 p_gid.gid_prefix, p_gid.gid_guid); 2376 2377 ret = ibt_get_companion_port_gids(p_gid, 0, 0, 2378 &gidp, &n_gids); 2379 if (ret == IBT_SUCCESS) { 2380 IBTF_DPRINTF_L3(cmlog, 2381 "ibcm_saa_service_rec: Found %d " 2382 "CompGID for %llX:%llX", n_gids, 2383 p_gid.gid_prefix, p_gid.gid_guid); 2384 2385 stmp = (sa_service_record_t *)results_p; 2386 a_gid.gid_prefix = a_gid.gid_guid = 0; 2387 2388 if (sl->p_multi & IBTL_CM_MULTI_SM) { 2389 /* validate sn_pfx */ 2390 a_gid = ibcm_saa_get_agid(sl, 2391 gidp, n_gids); 2392 } else { 2393 for (k = 0; k < num_req; k++) { 2394 ib_gid_t sg = stmp->ServiceGID; 2395 2396 IBTF_DPRINTF_L3(cmlog, 2397 "ibcm_saa_service_rec: " 2398 "SvcGID[%d] = %llX:%llX", k, 2399 sg.gid_prefix, sg.gid_guid); 2400 2401 for (j = 0; j < n_gids; j++) { 2402 if (gidp[j].gid_guid == 2403 sg.gid_guid) { 2404 a_gid = gidp[j]; 2405 break; 2406 } 2407 } 2408 if (a_gid.gid_guid) 2409 break; 2410 stmp++; 2411 } 2412 if (a_gid.gid_guid == 0) { 2413 /* Rec not found for Alt. */ 2414 for (j = 0; j < n_gids; j++) { 2415 if (gidp[j].gid_prefix 2416 == p_gid.gid_prefix) { 2417 a_gid = gidp[j]; 2418 break; 2419 } 2420 } 2421 } 2422 } 2423 kmem_free(gidp, 2424 n_gids * sizeof (ib_gid_t)); 2425 2426 if (a_gid.gid_guid) 2427 break; 2428 } else if (ret == IBT_GIDS_NOT_FOUND) { 2429 last_p_gid = p_gid; 2430 IBTF_DPRINTF_L3(cmlog, 2431 "ibcm_saa_service_rec: Didn't find " 2432 "CompGID for %llX:%llX, ret=%d", 2433 p_gid.gid_prefix, p_gid.gid_guid, 2434 ret); 2435 } else { 2436 IBTF_DPRINTF_L3(cmlog, 2437 "ibcm_saa_service_rec: Call to " 2438 "ibt_get_companion_port_gids(%llX:" 2439 "%llX) Failed = %d", 2440 p_gid.gid_prefix, p_gid.gid_guid, 2441 ret); 2442 } 2443 } 2444 2445 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: \n\t" 2446 "Pri DGID(%llX:%llX), Alt DGID(%llX:%llX)", 2447 p_gid.gid_prefix, p_gid.gid_guid, a_gid.gid_prefix, 2448 a_gid.gid_guid); 2449 2450 svcrec_resp = (sa_service_record_t *)results_p; 2451 2452 for (i = 0, j = 0; i < num_req; i++, svcrec_resp++) { 2453 /* Limited P_Key is NOT supported as of now!. */ 2454 if ((svcrec_resp->ServiceP_Key & 0x8000) == 0) { 2455 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: " 2456 "SvcPkey 0x%X limited, reject the record.", 2457 svcrec_resp->ServiceP_Key); 2458 continue; 2459 } 2460 2461 if ((pri_fill_done == B_FALSE) && 2462 (p_gid.gid_guid == 2463 svcrec_resp->ServiceGID.gid_guid)) { 2464 p_pkey = svcrec_resp->ServiceP_Key; 2465 if ((a_pkey != 0) && 2466 (a_pkey != p_pkey)) { 2467 IBTF_DPRINTF_L3(cmlog, 2468 "ibcm_saa_service_rec: " 2469 "Pri(0x%X) & Alt (0x%X) " 2470 "PKey must match.", 2471 p_pkey, a_pkey); 2472 p_pkey = 0; 2473 continue; 2474 } 2475 ibcm_fill_svcinfo(svcrec_resp, 2476 &dinfo->dest[j++]); 2477 rec_found++; 2478 pri_fill_done = B_TRUE; 2479 } else if ((alt_fill_done == B_FALSE) && 2480 (a_gid.gid_guid == 2481 svcrec_resp->ServiceGID.gid_guid)) { 2482 a_pkey = svcrec_resp->ServiceP_Key; 2483 if ((p_pkey != 0) && 2484 (a_pkey != p_pkey)) { 2485 IBTF_DPRINTF_L3(cmlog, 2486 "ibcm_saa_service_rec: " 2487 "Pri(0x%X) & Alt (0x%X) " 2488 "PKey must match.", 2489 p_pkey, a_pkey); 2490 a_pkey = 0; 2491 continue; 2492 } 2493 ibcm_fill_svcinfo(svcrec_resp, 2494 &dinfo->dest[j++]); 2495 rec_found++; 2496 alt_fill_done = B_TRUE; 2497 } 2498 2499 if (rec_found == 2) 2500 break; 2501 } 2502 if ((alt_fill_done == B_FALSE) && (a_gid.gid_guid)) { 2503 dinfo->dest[j].d_gid = a_gid; 2504 dinfo->dest[j].d_pkey = p_pkey; 2505 rec_found++; 2506 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: " 2507 "Let Alt Pkey=%X, DGID=%llX:%llX", p_pkey, 2508 a_gid.gid_prefix, a_gid.gid_guid); 2509 } 2510 2511 if (rec_found == 1) 2512 retval = IBT_INSUFF_DATA; 2513 } else if (p_arg->flags & IBT_PATH_MULTI_SVC_DEST) { 2514 for (i = 0; i < num_req; i++, svcrec_resp++) { 2515 /* Limited P_Key is NOT supported as of now!. */ 2516 if ((svcrec_resp->ServiceP_Key & 0x8000) == 0) { 2517 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: " 2518 "SvcPkey 0x%X limited, reject the record.", 2519 svcrec_resp->ServiceP_Key); 2520 continue; 2521 } 2522 ibcm_fill_svcinfo(svcrec_resp, 2523 &dinfo->dest[rec_found]); 2524 rec_found++; 2525 if (rec_found == p_arg->max_paths) 2526 break; 2527 } 2528 2529 if (rec_found < p_arg->max_paths) 2530 retval = IBT_INSUFF_DATA; 2531 } else { 2532 for (i = 0; i < num_req; i++) { 2533 /* Limited P_Key is NOT supported as of now!. */ 2534 if ((svcrec_resp->ServiceP_Key & 0x8000) == 0) { 2535 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: " 2536 "SvcPkey 0x%X limited, reject the record.", 2537 svcrec_resp->ServiceP_Key); 2538 svcrec_resp++; 2539 continue; 2540 } 2541 2542 ibcm_fill_svcinfo(svcrec_resp, &dinfo->dest[0]); 2543 rec_found = 1; 2544 2545 /* Avoid having loopback node */ 2546 if (svcrec_resp->ServiceGID.gid_guid != 2547 sl->p_sgid.gid_guid) { 2548 break; 2549 } else { 2550 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: " 2551 "avoid LoopBack node."); 2552 svcrec_resp++; 2553 } 2554 } 2555 } 2556 2557 /* Deallocate the memory for results_p. */ 2558 kmem_free(results_p, length); 2559 if (dinfo->num_dest == 0) 2560 dinfo->num_dest = rec_found; 2561 2562 /* 2563 * Check out whether all Service Path we looking for are on the same 2564 * P_key. If yes, then set the global p_key field with that value, 2565 * to make it easy during SA Path Query. 2566 */ 2567 if ((dinfo->num_dest) && (dinfo->p_key == 0)) { 2568 ib_pkey_t pk = dinfo->dest[0].d_pkey; 2569 2570 if (dinfo->num_dest == 1) { 2571 dinfo->p_key = pk; 2572 } else { 2573 for (i = 1; i < (dinfo->num_dest - 1); i++) { 2574 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: " 2575 "pk= 0x%X, pk[%d]= 0x%X", pk, i, 2576 dinfo->dest[i].d_pkey); 2577 if (pk != dinfo->dest[i].d_pkey) { 2578 dinfo->p_key = 0; 2579 break; 2580 } else { 2581 dinfo->p_key = pk; 2582 } 2583 } 2584 } 2585 } 2586 2587 if (rec_found == 0) { 2588 IBTF_DPRINTF_L2(cmlog, "ibcm_saa_service_rec: " 2589 "ServiceRec NOT Found"); 2590 retval = IBT_SERVICE_RECORDS_NOT_FOUND; 2591 } 2592 2593 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: done. Status %d, " 2594 "PKey 0x%X, Found %d SvcRec", retval, dinfo->p_key, rec_found); 2595 2596 return (retval); 2597 } 2598 2599 2600 static boolean_t 2601 ibcm_compare_paths(sa_path_record_t *pr_resp, ibt_cep_path_t *rc_path, 2602 ibtl_cm_hca_port_t *c_hp) 2603 { 2604 if ((rc_path->cep_hca_port_num == c_hp->hp_port) && 2605 (rc_path->cep_adds_vect.av_src_path == 2606 (pr_resp->SLID - c_hp->hp_base_lid)) && 2607 (rc_path->cep_adds_vect.av_dlid == pr_resp->DLID) && 2608 (rc_path->cep_adds_vect.av_srate == pr_resp->Rate)) { 2609 return (B_TRUE); 2610 } else { 2611 return (B_FALSE); 2612 } 2613 } 2614 2615 /* 2616 * ibcm_get_comp_pgids() routine gets the companion port for 'gid'. 2617 * 2618 * On success: 2619 * If 'n_gid' is specified, then verify whether 'n_gid' is indeed a 2620 * companion portgid of 'gid'. If matches return success or else error. 2621 * 2622 * If 'n_gid' is NOT specified, then return back SUCCESS along with 2623 * obtained Companion PortGids 'gid_p', where 'num' indicated number 2624 * of companion portgids returned in 'gid_p'. 2625 */ 2626 2627 static ibt_status_t 2628 ibcm_get_comp_pgids(ib_gid_t gid, ib_gid_t n_gid, ib_guid_t hca_guid, 2629 ib_gid_t **gid_p, uint_t *num) 2630 { 2631 ibt_status_t ret; 2632 int i; 2633 2634 ret = ibt_get_companion_port_gids(gid, hca_guid, 0, gid_p, num); 2635 if ((ret != IBT_SUCCESS) && (ret != IBT_GIDS_NOT_FOUND)) { 2636 IBTF_DPRINTF_L2(cmlog, "ibcm_get_comp_pgids: " 2637 "ibt_get_companion_port_gids(%llX:%llX) Failed: %d", 2638 gid.gid_prefix, gid.gid_guid, ret); 2639 } else if ((ret == IBT_GIDS_NOT_FOUND) && (n_gid.gid_guid != 0)) { 2640 IBTF_DPRINTF_L2(cmlog, "ibcm_get_comp_pgids: Specified GID " 2641 "(%llX:%llX) is NOT a Companion \n\t to current channel's " 2642 "GID(%llX:%llX)", n_gid.gid_prefix, n_gid.gid_guid, 2643 gid.gid_prefix, gid.gid_guid); 2644 ret = IBT_INVALID_PARAM; 2645 } else if (n_gid.gid_guid != 0) { 2646 /* 2647 * We found some Comp GIDs and n_gid is specified. Validate 2648 * whether the 'n_gid' specified is indeed the companion port 2649 * GID of 'gid'. 2650 */ 2651 for (i = 0; i < *num; i++) { 2652 if ((n_gid.gid_prefix == gid_p[i]->gid_prefix) && 2653 (n_gid.gid_guid == gid_p[i]->gid_guid)) { 2654 IBTF_DPRINTF_L3(cmlog, "ibcm_get_comp_pgids: " 2655 "Matching Found!. Done."); 2656 return (IBT_SUCCESS); 2657 } 2658 } 2659 IBTF_DPRINTF_L2(cmlog, "ibcm_get_comp_pgids: GID (%llX:%llX)\n" 2660 "\t and (%llX:%llX) are NOT Companion Port GIDS", 2661 n_gid.gid_prefix, n_gid.gid_guid, gid.gid_prefix, 2662 gid.gid_guid); 2663 ret = IBT_INVALID_PARAM; 2664 } else { 2665 ret = IBT_SUCCESS; 2666 } 2667 2668 IBTF_DPRINTF_L3(cmlog, "ibcm_get_comp_pgids: done. Status = %d", ret); 2669 return (ret); 2670 } 2671 2672 /* 2673 * Function: 2674 * ibt_get_alt_path 2675 * Input: 2676 * rc_chan An RC channel handle returned in a previous call 2677 * ibt_alloc_rc_channel(9F), specifies the channel to open. 2678 * flags Path flags. 2679 * attrp A pointer to an ibt_alt_path_attr_t(9S) structure that 2680 * specifies required attributes of the selected path(s). 2681 * Output: 2682 * api_p An ibt_alt_path_info_t(9S) struct filled in as output 2683 * parameters. 2684 * Returns: 2685 * IBT_SUCCESS on Success else appropriate error. 2686 * Description: 2687 * Finds the best alternate path to a specified channel (as determined by 2688 * the IBTL) that satisfies the requirements specified in an 2689 * ibt_alt_path_attr_t struct. The specified channel must have been 2690 * previously opened successfully using ibt_open_rc_channel. 2691 * This function also ensures that the service being accessed by the 2692 * channel is available at the selected alternate port. 2693 * 2694 * Note: The apa_dgid must be on the same destination channel adapter, 2695 * if specified. 2696 * This routine can not be called from interrupt context. 2697 */ 2698 ibt_status_t 2699 ibt_get_alt_path(ibt_channel_hdl_t rc_chan, ibt_path_flags_t flags, 2700 ibt_alt_path_attr_t *attrp, ibt_alt_path_info_t *api_p) 2701 { 2702 sa_multipath_record_t *mpr_req; 2703 sa_path_record_t *pr_resp; 2704 ibmf_saa_access_args_t access_args; 2705 ibt_qp_query_attr_t qp_attr; 2706 ibtl_cm_hca_port_t c_hp, n_hp; 2707 ibcm_hca_info_t *hcap; 2708 void *results_p; 2709 uint64_t c_mask = 0; 2710 ib_gid_t *gid_ptr = NULL; 2711 ib_gid_t *sgids_p = NULL, *dgids_p = NULL; 2712 ib_gid_t cur_dgid, cur_sgid; 2713 ib_gid_t new_dgid, new_sgid; 2714 ibmf_saa_handle_t saa_handle; 2715 size_t length; 2716 int i, j, template_len, rec_found; 2717 uint_t snum = 0, dnum = 0, num_rec; 2718 ibt_status_t retval; 2719 ib_mtu_t prim_mtu; 2720 2721 IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path(%p, %x, %p, %p)", 2722 rc_chan, flags, attrp, api_p); 2723 2724 /* validate channel */ 2725 if (IBCM_INVALID_CHANNEL(rc_chan)) { 2726 IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: invalid channel"); 2727 return (IBT_CHAN_HDL_INVALID); 2728 } 2729 2730 if (api_p == NULL) { 2731 IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: invalid attribute: " 2732 " AltPathInfo can't be NULL"); 2733 return (IBT_INVALID_PARAM); 2734 } 2735 2736 retval = ibt_query_qp(rc_chan, &qp_attr); 2737 if (retval != IBT_SUCCESS) { 2738 IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: ibt_query_qp(%p) " 2739 "failed %d", rc_chan, retval); 2740 return (retval); 2741 } 2742 2743 if (qp_attr.qp_info.qp_trans != IBT_RC_SRV) { 2744 IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: " 2745 "Invalid Channel type: Applicable only to RC Channel"); 2746 return (IBT_CHAN_SRV_TYPE_INVALID); 2747 } 2748 2749 cur_dgid = 2750 qp_attr.qp_info.qp_transport.rc.rc_path.cep_adds_vect.av_dgid; 2751 cur_sgid = 2752 qp_attr.qp_info.qp_transport.rc.rc_path.cep_adds_vect.av_sgid; 2753 prim_mtu = qp_attr.qp_info.qp_transport.rc.rc_path_mtu; 2754 2755 /* If optional attributes are specified, validate them. */ 2756 if (attrp) { 2757 new_dgid = attrp->apa_dgid; 2758 new_sgid = attrp->apa_sgid; 2759 } else { 2760 new_dgid.gid_prefix = 0; 2761 new_dgid.gid_guid = 0; 2762 new_sgid.gid_prefix = 0; 2763 new_sgid.gid_guid = 0; 2764 } 2765 2766 if ((new_dgid.gid_prefix != 0) && (new_sgid.gid_prefix != 0) && 2767 (new_dgid.gid_prefix != new_sgid.gid_prefix)) { 2768 IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: Specified SGID's " 2769 "SNprefix (%llX) doesn't match with \n specified DGID's " 2770 "SNprefix: %llX", new_sgid.gid_prefix, new_dgid.gid_prefix); 2771 return (IBT_INVALID_PARAM); 2772 } 2773 2774 /* For the specified SGID, get HCA information. */ 2775 retval = ibtl_cm_get_hca_port(cur_sgid, 0, &c_hp); 2776 if (retval != IBT_SUCCESS) { 2777 IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: " 2778 "Get HCA Port Failed: %d", retval); 2779 return (retval); 2780 } 2781 2782 hcap = ibcm_find_hca_entry(c_hp.hp_hca_guid); 2783 if (hcap == NULL) { 2784 IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: NO HCA found"); 2785 return (IBT_HCA_BUSY_DETACHING); 2786 } 2787 2788 /* Validate whether this HCA support APM */ 2789 if (!(hcap->hca_caps & IBT_HCA_AUTO_PATH_MIG)) { 2790 IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: " 2791 "HCA (%llX) - APM NOT SUPPORTED ", c_hp.hp_hca_guid); 2792 retval = IBT_APM_NOT_SUPPORTED; 2793 goto get_alt_path_done; 2794 } 2795 2796 /* Get Companion Port GID of the current Channel's SGID */ 2797 if ((new_sgid.gid_guid == 0) || ((new_sgid.gid_guid != 0) && 2798 (new_sgid.gid_guid != cur_sgid.gid_guid))) { 2799 IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path: SRC: " 2800 "Get Companion PortGids for - %llX:%llX", 2801 cur_sgid.gid_prefix, cur_sgid.gid_guid); 2802 2803 retval = ibcm_get_comp_pgids(cur_sgid, new_sgid, 2804 c_hp.hp_hca_guid, &sgids_p, &snum); 2805 if (retval != IBT_SUCCESS) 2806 goto get_alt_path_done; 2807 } 2808 2809 /* Get Companion Port GID of the current Channel's DGID */ 2810 if ((new_dgid.gid_guid == 0) || ((new_dgid.gid_guid != 0) && 2811 (new_dgid.gid_guid != cur_dgid.gid_guid))) { 2812 2813 IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path: DEST: " 2814 "Get Companion PortGids for - %llX:%llX", 2815 cur_dgid.gid_prefix, cur_dgid.gid_guid); 2816 2817 retval = ibcm_get_comp_pgids(cur_dgid, new_dgid, 0, &dgids_p, 2818 &dnum); 2819 if (retval != IBT_SUCCESS) 2820 goto get_alt_path_done; 2821 } 2822 2823 if ((new_dgid.gid_guid == 0) || (new_sgid.gid_guid == 0)) { 2824 if (new_sgid.gid_guid == 0) { 2825 for (i = 0; i < snum; i++) { 2826 if (new_dgid.gid_guid == 0) { 2827 for (j = 0; j < dnum; j++) { 2828 if (sgids_p[i].gid_prefix == 2829 dgids_p[j].gid_prefix) { 2830 new_dgid = dgids_p[j]; 2831 new_sgid = sgids_p[i]; 2832 2833 goto get_alt_proceed; 2834 } 2835 } 2836 /* Current DGID */ 2837 if (sgids_p[i].gid_prefix == 2838 cur_dgid.gid_prefix) { 2839 new_sgid = sgids_p[i]; 2840 goto get_alt_proceed; 2841 } 2842 } else { 2843 if (sgids_p[i].gid_prefix == 2844 new_dgid.gid_prefix) { 2845 new_sgid = sgids_p[i]; 2846 goto get_alt_proceed; 2847 } 2848 } 2849 } 2850 /* Current SGID */ 2851 if (new_dgid.gid_guid == 0) { 2852 for (j = 0; j < dnum; j++) { 2853 if (cur_sgid.gid_prefix == 2854 dgids_p[j].gid_prefix) { 2855 new_dgid = dgids_p[j]; 2856 2857 goto get_alt_proceed; 2858 } 2859 } 2860 } 2861 } else if (new_dgid.gid_guid == 0) { 2862 for (i = 0; i < dnum; i++) { 2863 if (dgids_p[i].gid_prefix == 2864 new_sgid.gid_prefix) { 2865 new_dgid = dgids_p[i]; 2866 goto get_alt_proceed; 2867 } 2868 } 2869 /* Current DGID */ 2870 if (cur_dgid.gid_prefix == new_sgid.gid_prefix) { 2871 goto get_alt_proceed; 2872 } 2873 } 2874 /* 2875 * hmm... No Companion Ports available. 2876 * so we will be using current or specified attributes only. 2877 */ 2878 } 2879 2880 get_alt_proceed: 2881 2882 if (new_sgid.gid_guid != 0) { 2883 retval = ibtl_cm_get_hca_port(new_sgid, 0, &n_hp); 2884 if (retval != IBT_SUCCESS) { 2885 IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: " 2886 "Get HCA Port Failed: %d", retval); 2887 goto get_alt_path_done; 2888 } 2889 } 2890 2891 /* Calculate the size for multi-path records template */ 2892 template_len = (2 * sizeof (ib_gid_t)) + sizeof (sa_multipath_record_t); 2893 2894 mpr_req = kmem_zalloc(template_len, KM_SLEEP); 2895 2896 ASSERT(mpr_req != NULL); 2897 2898 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mpr_req)) 2899 2900 gid_ptr = (ib_gid_t *)(((uchar_t *)mpr_req) + 2901 sizeof (sa_multipath_record_t)); 2902 2903 /* SGID */ 2904 if (new_sgid.gid_guid == 0) 2905 *gid_ptr = cur_sgid; 2906 else 2907 *gid_ptr = new_sgid; 2908 2909 IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path: Get Path Between " 2910 " SGID : %llX:%llX", gid_ptr->gid_prefix, gid_ptr->gid_guid); 2911 2912 gid_ptr++; 2913 2914 /* DGID */ 2915 if (new_dgid.gid_guid == 0) 2916 *gid_ptr = cur_dgid; 2917 else 2918 *gid_ptr = new_dgid; 2919 2920 IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path:\t\t DGID : %llX:%llX", 2921 gid_ptr->gid_prefix, gid_ptr->gid_guid); 2922 2923 mpr_req->SGIDCount = 1; 2924 c_mask = SA_MPR_COMPMASK_SGIDCOUNT; 2925 2926 mpr_req->DGIDCount = 1; 2927 c_mask |= SA_MPR_COMPMASK_DGIDCOUNT; 2928 2929 /* Is Flow Label Specified. */ 2930 if (attrp) { 2931 if (attrp->apa_flow) { 2932 mpr_req->FlowLabel = attrp->apa_flow; 2933 c_mask |= SA_MPR_COMPMASK_FLOWLABEL; 2934 } 2935 2936 /* Is HopLimit Specified. */ 2937 if (flags & IBT_PATH_HOP) { 2938 mpr_req->HopLimit = attrp->apa_hop; 2939 c_mask |= SA_MPR_COMPMASK_HOPLIMIT; 2940 } 2941 2942 /* Is TClass Specified. */ 2943 if (attrp->apa_tclass) { 2944 mpr_req->TClass = attrp->apa_tclass; 2945 c_mask |= SA_MPR_COMPMASK_TCLASS; 2946 } 2947 2948 /* Is SL specified. */ 2949 if (attrp->apa_sl) { 2950 mpr_req->SL = attrp->apa_sl; 2951 c_mask |= SA_MPR_COMPMASK_SL; 2952 } 2953 2954 if (flags & IBT_PATH_PERF) { 2955 mpr_req->PacketLifeTimeSelector = IBT_BEST; 2956 mpr_req->RateSelector = IBT_BEST; 2957 2958 c_mask |= SA_MPR_COMPMASK_PKTLTSELECTOR | 2959 SA_MPR_COMPMASK_RATESELECTOR; 2960 } else { 2961 if (attrp->apa_pkt_lt.p_selector == IBT_BEST) { 2962 mpr_req->PacketLifeTimeSelector = IBT_BEST; 2963 c_mask |= SA_MPR_COMPMASK_PKTLTSELECTOR; 2964 } 2965 2966 if (attrp->apa_srate.r_selector == IBT_BEST) { 2967 mpr_req->RateSelector = IBT_BEST; 2968 c_mask |= SA_MPR_COMPMASK_RATESELECTOR; 2969 } 2970 } 2971 2972 /* 2973 * Honor individual selection of these attributes, 2974 * even if IBT_PATH_PERF is set. 2975 */ 2976 /* Check out whether Packet Life Time is specified. */ 2977 if (attrp->apa_pkt_lt.p_pkt_lt) { 2978 mpr_req->PacketLifeTime = 2979 ibt_usec2ib(attrp->apa_pkt_lt.p_pkt_lt); 2980 mpr_req->PacketLifeTimeSelector = 2981 attrp->apa_pkt_lt.p_selector; 2982 2983 c_mask |= SA_MPR_COMPMASK_PKTLT | 2984 SA_MPR_COMPMASK_PKTLTSELECTOR; 2985 } 2986 2987 /* Is SRATE specified. */ 2988 if (attrp->apa_srate.r_srate) { 2989 mpr_req->Rate = attrp->apa_srate.r_srate; 2990 mpr_req->RateSelector = attrp->apa_srate.r_selector; 2991 2992 c_mask |= SA_MPR_COMPMASK_RATE | 2993 SA_MPR_COMPMASK_RATESELECTOR; 2994 } 2995 } 2996 2997 /* Alt PathMTU can be GT or EQU to current channel's Pri PathMTU */ 2998 2999 /* P_Key must be same as that of primary path */ 3000 retval = ibt_index2pkey_byguid(c_hp.hp_hca_guid, c_hp.hp_port, 3001 qp_attr.qp_info.qp_transport.rc.rc_path.cep_pkey_ix, 3002 &mpr_req->P_Key); 3003 if (retval != IBT_SUCCESS) { 3004 IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: Idx2Pkey Failed: %d", 3005 retval); 3006 goto get_alt_path_done; 3007 } 3008 c_mask |= SA_MPR_COMPMASK_PKEY; 3009 3010 mpr_req->Reversible = 1; /* We always get REVERSIBLE paths. */ 3011 mpr_req->IndependenceSelector = 1; 3012 c_mask |= SA_MPR_COMPMASK_REVERSIBLE | SA_MPR_COMPMASK_INDEPSEL; 3013 3014 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*mpr_req)) 3015 3016 IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path: CMask: 0x%llX", c_mask); 3017 3018 /* NOTE: We will **NOT** specify how many records we want. */ 3019 3020 IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path: Primary: MTU %d, PKey[%d]=" 3021 "0x%X\n\tSGID = %llX:%llX, DGID = %llX:%llX", prim_mtu, 3022 qp_attr.qp_info.qp_transport.rc.rc_path.cep_pkey_ix, mpr_req->P_Key, 3023 cur_sgid.gid_prefix, cur_sgid.gid_guid, cur_dgid.gid_prefix, 3024 cur_dgid.gid_guid); 3025 3026 /* Get SA Access Handle. */ 3027 if (new_sgid.gid_guid != 0) 3028 saa_handle = ibcm_get_saa_handle(hcap, n_hp.hp_port); 3029 else 3030 saa_handle = ibcm_get_saa_handle(hcap, c_hp.hp_port); 3031 if (saa_handle == NULL) { 3032 retval = IBT_HCA_PORT_NOT_ACTIVE; 3033 goto get_alt_path_done; 3034 } 3035 3036 /* Contact SA Access to retrieve Path Records. */ 3037 access_args.sq_attr_id = SA_MULTIPATHRECORD_ATTRID; 3038 access_args.sq_access_type = IBMF_SAA_RETRIEVE; 3039 access_args.sq_component_mask = c_mask; 3040 access_args.sq_template = mpr_req; 3041 access_args.sq_template_length = sizeof (sa_multipath_record_t); 3042 access_args.sq_callback = NULL; 3043 access_args.sq_callback_arg = NULL; 3044 3045 retval = ibcm_contact_sa_access(saa_handle, &access_args, &length, 3046 &results_p); 3047 if (retval != IBT_SUCCESS) { 3048 goto get_alt_path_done; 3049 } 3050 3051 num_rec = length / sizeof (sa_path_record_t); 3052 3053 kmem_free(mpr_req, template_len); 3054 3055 IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path: Found %d Paths", num_rec); 3056 3057 rec_found = 0; 3058 if ((results_p != NULL) && (num_rec > 0)) { 3059 /* Update the PathInfo with the response Path Records */ 3060 pr_resp = (sa_path_record_t *)results_p; 3061 for (i = 0; i < num_rec; i++, pr_resp++) { 3062 if (prim_mtu > pr_resp->Mtu) { 3063 IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: " 3064 "Alt PathMTU(%d) must be GT or EQU to Pri " 3065 "PathMTU(%d). Ignore this rec", 3066 pr_resp->Mtu, prim_mtu); 3067 continue; 3068 } 3069 3070 if ((new_sgid.gid_guid == 0) && 3071 (new_dgid.gid_guid == 0)) { 3072 /* Reject PathRec if it same as Primary Path. */ 3073 if (ibcm_compare_paths(pr_resp, 3074 &qp_attr.qp_info.qp_transport.rc.rc_path, 3075 &c_hp) == B_TRUE) { 3076 IBTF_DPRINTF_L3(cmlog, 3077 "ibt_get_alt_path: PathRec obtained" 3078 " is similar to Prim Path, ignore " 3079 "this record"); 3080 continue; 3081 } 3082 } 3083 3084 if (new_sgid.gid_guid == 0) { 3085 retval = ibcm_update_cep_info(pr_resp, NULL, 3086 &c_hp, &api_p->ap_alt_cep_path); 3087 } else { 3088 retval = ibcm_update_cep_info(pr_resp, NULL, 3089 &n_hp, &api_p->ap_alt_cep_path); 3090 } 3091 if (retval != IBT_SUCCESS) 3092 continue; 3093 3094 /* Update some leftovers */ 3095 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*api_p)) 3096 3097 api_p->ap_alt_pkt_lt = pr_resp->PacketLifeTime; 3098 3099 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*api_p)) 3100 3101 rec_found = 1; 3102 break; 3103 } 3104 kmem_free(results_p, length); 3105 } 3106 3107 if (rec_found == 0) { 3108 IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path: Alternate Path cannot" 3109 " be established"); 3110 retval = IBT_PATH_RECORDS_NOT_FOUND; 3111 } else 3112 retval = IBT_SUCCESS; 3113 3114 get_alt_path_done: 3115 if ((snum) && (sgids_p)) 3116 kmem_free(sgids_p, snum * sizeof (ib_gid_t)); 3117 3118 if ((dnum) && (dgids_p)) 3119 kmem_free(dgids_p, dnum * sizeof (ib_gid_t)); 3120 3121 ibcm_dec_hca_acc_cnt(hcap); 3122 3123 IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path: Done (status %d).", retval); 3124 3125 return (retval); 3126 } 3127 3128 3129 /* Routines for warlock */ 3130 3131 /* ARGSUSED */ 3132 static void 3133 ibcm_dummy_path_handler(void *arg, ibt_status_t retval, ibt_path_info_t *paths, 3134 uint8_t num_path) 3135 { 3136 ibcm_path_tqargs_t dummy_path; 3137 3138 dummy_path.func = ibcm_dummy_path_handler; 3139 3140 IBTF_DPRINTF_L5(cmlog, "ibcm_dummy_path_handler: " 3141 "dummy_path.func %p", dummy_path.func); 3142 } 3143