Print this page
XXXX introduce drv_sectohz
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/ib/mgt/ibcm/ibcm_path.c
+++ new/usr/src/uts/common/io/ib/mgt/ibcm/ibcm_path.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 */
24 24
25 25 #include <sys/ib/mgt/ibcm/ibcm_impl.h>
26 26 #include <sys/ib/mgt/ibcm/ibcm_arp.h>
27 27
28 28 /*
29 29 * ibcm_path.c
30 30 *
31 31 * ibt_get_paths() implement the Path Informations related functionality.
32 32 */
33 33
34 34 /* ibcm_saa_service_rec() fills in ServiceID and DGID. */
35 35 typedef struct ibcm_dest_s {
36 36 ib_gid_t d_gid;
37 37 ib_svc_id_t d_sid;
38 38 ibt_srv_data_t d_sdata;
39 39 ib_pkey_t d_pkey;
40 40 uint_t d_tag; /* 0 = Unicast, 1 = Multicast */
41 41 } ibcm_dest_t;
42 42
43 43 /* Holds Destination information needed to fill in ibt_path_info_t. */
44 44 typedef struct ibcm_dinfo_s {
45 45 uint8_t num_dest;
46 46 ib_pkey_t p_key;
47 47 ibcm_dest_t dest[1];
48 48 } ibcm_dinfo_t;
49 49
50 50 _NOTE(SCHEME_PROTECTS_DATA("Temporary path storage", ibcm_dinfo_s))
51 51 _NOTE(READ_ONLY_DATA(ibt_path_attr_s))
52 52
53 53 typedef struct ibcm_path_tqargs_s {
54 54 ibt_path_attr_t attr;
55 55 ibt_path_info_t *paths;
56 56 uint8_t *num_paths_p;
57 57 ibt_path_handler_t func;
58 58 void *arg;
59 59 ibt_path_flags_t flags;
60 60 uint8_t max_paths;
61 61 } ibcm_path_tqargs_t;
62 62
63 63
64 64 /* Prototype Declarations. */
65 65 static ibt_status_t ibcm_saa_path_rec(ibcm_path_tqargs_t *,
66 66 ibtl_cm_port_list_t *, ibcm_dinfo_t *, uint8_t *);
67 67
68 68 static ibt_status_t ibcm_update_cep_info(sa_path_record_t *,
69 69 ibtl_cm_port_list_t *, ibtl_cm_hca_port_t *, ibt_cep_path_t *);
70 70
71 71 static ibt_status_t ibcm_saa_service_rec(ibcm_path_tqargs_t *,
72 72 ibtl_cm_port_list_t *, ibcm_dinfo_t *);
73 73
74 74 static ibt_status_t ibcm_get_single_pathrec(ibcm_path_tqargs_t *,
75 75 ibtl_cm_port_list_t *, ibcm_dinfo_t *, uint8_t,
76 76 uint8_t *, ibt_path_info_t *);
77 77
78 78 static ibt_status_t ibcm_get_multi_pathrec(ibcm_path_tqargs_t *,
79 79 ibtl_cm_port_list_t *, ibcm_dinfo_t *dinfo,
80 80 uint8_t *, ibt_path_info_t *);
81 81
82 82 static ibt_status_t ibcm_validate_path_attributes(ibt_path_attr_t *attrp,
83 83 ibt_path_flags_t flags, uint8_t max_paths);
84 84
85 85 static ibt_status_t ibcm_handle_get_path(ibt_path_attr_t *attrp,
86 86 ibt_path_flags_t flags, uint8_t max_paths, ibt_path_info_t *paths,
87 87 uint8_t *num_path_p, ibt_path_handler_t func, void *arg);
88 88
89 89 static void ibcm_process_async_get_paths(void *tq_arg);
90 90
91 91 static ibt_status_t ibcm_process_get_paths(void *tq_arg);
92 92
93 93 static ibt_status_t ibcm_get_comp_pgids(ib_gid_t, ib_gid_t, ib_guid_t,
94 94 ib_gid_t **, uint_t *);
95 95
96 96 /*
97 97 * Function:
98 98 * ibt_aget_paths
99 99 * Input:
100 100 * ibt_hdl The handle returned to the client by the IBTF from an
101 101 * ibt_attach() call. Can be used by the IBTF Policy module
102 102 * and CM in the determination of the "best" path to the
103 103 * specified destination for this class of driver.
104 104 * flags Path flags.
105 105 * attrp Points to an ibt_path_attr_t struct that contains
106 106 * required and optional attributes.
107 107 * func A pointer to an ibt_path_handler_t function to call
108 108 * when ibt_aget_paths() completes.
109 109 * arg The argument to 'func'.
110 110 * Returns:
111 111 * IBT_SUCCESS on early validation of attributes else appropriate error.
112 112 * Description:
113 113 * Finds the best path to a specified destination or service
114 114 * asynchronously (as determined by the IBTL) that satisfies the
115 115 * requirements specified in an ibt_path_attr_t struct.
116 116 * ibt_aget_paths() is a Non-Blocking version of ibt_get_paths().
117 117 */
118 118 ibt_status_t
119 119 ibt_aget_paths(ibt_clnt_hdl_t ibt_hdl, ibt_path_flags_t flags,
120 120 ibt_path_attr_t *attrp, uint8_t max_paths, ibt_path_handler_t func,
121 121 void *arg)
122 122 {
123 123 IBTF_DPRINTF_L3(cmlog, "ibt_aget_paths(%p(%s), 0x%X, %p, %d, %p)",
124 124 ibt_hdl, ibtl_cm_get_clnt_name(ibt_hdl), flags, attrp, max_paths,
125 125 func);
126 126
127 127 if (func == NULL) {
128 128 IBTF_DPRINTF_L2(cmlog, "ibt_aget_paths: Function Pointer is "
129 129 "NULL - ERROR ");
130 130 return (IBT_INVALID_PARAM);
131 131 }
132 132
133 133 /* Memory for path info will be allocated in ibcm_process_get_paths() */
134 134 return (ibcm_handle_get_path(attrp, flags, max_paths, NULL, NULL,
135 135 func, arg));
136 136 }
137 137
138 138
139 139 /*
140 140 * ibt_get_paths() cache consists of one or more of:
141 141 *
142 142 * ib_gid_t dgid (attrp->pa_dgids[0])
143 143 * ibt_path_attr_t attr
144 144 * ibt_path_flags_t flags
145 145 * ibt_path_info_t path
146 146 *
147 147 * If the first 3 match, max_paths is 1, sname is NULL, and sid is 0,
148 148 * then the path is returned immediately.
149 149 *
150 150 * Note that a compare of "attr" is non-trivial. Only accept ones
151 151 * that memcmp() succeeds, i.e., basically assume a bzero was done.
152 152 *
153 153 * Cache must be invalidated if PORT_DOWN event or GID_UNAVAIL occurs.
154 154 * Cache must be freed as part of _fini.
155 155 */
156 156
157 157 #define IBCM_PATH_CACHE_SIZE 16 /* keep small for linear search */
158 158 #define IBCM_PATH_CACHE_TIMEOUT 60 /* purge cache after 60 seconds */
159 159
160 160 typedef struct ibcm_path_cache_s {
161 161 ib_gid_t dgid;
162 162 ibt_path_attr_t attr;
163 163 ibt_path_flags_t flags;
164 164 ibt_path_info_t path;
165 165 } ibcm_path_cache_t;
166 166
167 167 kmutex_t ibcm_path_cache_mutex;
168 168 int ibcm_path_cache_invalidate; /* invalidate cache on next ibt_get_paths */
169 169 clock_t ibcm_path_cache_timeout = IBCM_PATH_CACHE_TIMEOUT; /* tunable */
170 170 timeout_id_t ibcm_path_cache_timeout_id;
171 171 int ibcm_path_cache_size_init = IBCM_PATH_CACHE_SIZE; /* tunable */
172 172 int ibcm_path_cache_size;
173 173 ibcm_path_cache_t *ibcm_path_cachep;
174 174
175 175 /* tunable, set to 1 to not allow link-local address */
176 176 int ibcm_ip6_linklocal_addr_ok = 0;
177 177
178 178 struct ibcm_path_cache_stat_s {
179 179 int hits;
180 180 int misses;
181 181 int adds;
182 182 int already_in_cache;
183 183 int bad_path_for_cache;
↓ open down ↓ |
183 lines elided |
↑ open up ↑ |
184 184 int purges;
185 185 int timeouts;
186 186 } ibcm_path_cache_stats;
187 187
188 188 /*ARGSUSED*/
189 189 static void
190 190 ibcm_path_cache_timeout_cb(void *arg)
191 191 {
192 192 clock_t timeout_in_hz;
193 193
194 - timeout_in_hz = drv_usectohz(ibcm_path_cache_timeout * 1000000);
194 + timeout_in_hz = drv_sectohz(ibcm_path_cache_timeout);
195 195 mutex_enter(&ibcm_path_cache_mutex);
196 196 ibcm_path_cache_invalidate = 1; /* invalidate cache on next check */
197 197 if (ibcm_path_cache_timeout_id)
198 198 ibcm_path_cache_timeout_id = timeout(ibcm_path_cache_timeout_cb,
199 199 NULL, timeout_in_hz);
200 200 /* else we're in _fini */
201 201 mutex_exit(&ibcm_path_cache_mutex);
202 202 }
203 203
204 204 void
205 205 ibcm_path_cache_init(void)
206 206 {
207 207 clock_t timeout_in_hz;
208 208 int cache_size = ibcm_path_cache_size_init;
209 209 ibcm_path_cache_t *path_cachep;
210 210
211 - timeout_in_hz = drv_usectohz(ibcm_path_cache_timeout * 1000000);
211 + timeout_in_hz = drv_sectohz(ibcm_path_cache_timeout);
212 212 path_cachep = kmem_zalloc(cache_size * sizeof (*path_cachep), KM_SLEEP);
213 213 mutex_init(&ibcm_path_cache_mutex, NULL, MUTEX_DEFAULT, NULL);
214 214 mutex_enter(&ibcm_path_cache_mutex);
215 215 ibcm_path_cache_size = cache_size;
216 216 ibcm_path_cachep = path_cachep;
217 217 ibcm_path_cache_timeout_id = timeout(ibcm_path_cache_timeout_cb,
218 218 NULL, timeout_in_hz);
219 219 mutex_exit(&ibcm_path_cache_mutex);
220 220 }
221 221
222 222 void
223 223 ibcm_path_cache_fini(void)
224 224 {
225 225 timeout_id_t tmp_timeout_id;
226 226 int cache_size;
227 227 ibcm_path_cache_t *path_cachep;
228 228
229 229 mutex_enter(&ibcm_path_cache_mutex);
230 230 if (ibcm_path_cache_timeout_id) {
231 231 tmp_timeout_id = ibcm_path_cache_timeout_id;
232 232 ibcm_path_cache_timeout_id = 0; /* no more timeouts */
233 233 }
234 234 cache_size = ibcm_path_cache_size;
235 235 path_cachep = ibcm_path_cachep;
236 236 mutex_exit(&ibcm_path_cache_mutex);
237 237 if (tmp_timeout_id)
238 238 (void) untimeout(tmp_timeout_id);
239 239 mutex_destroy(&ibcm_path_cache_mutex);
240 240 kmem_free(path_cachep, cache_size * sizeof (*path_cachep));
241 241 }
242 242
243 243 static ibcm_status_t
244 244 ibcm_path_cache_check(ibt_path_flags_t flags, ibt_path_attr_t *attrp,
245 245 uint8_t max_paths, ibt_path_info_t *path, uint8_t *num_paths_p)
246 246 {
247 247 int i;
248 248 ib_gid_t dgid;
249 249 ibcm_path_cache_t *path_cachep;
250 250
251 251 if (max_paths != 1 || attrp->pa_num_dgids != 1 ||
252 252 attrp->pa_sname != NULL || attrp->pa_sid != 0) {
253 253 mutex_enter(&ibcm_path_cache_mutex);
254 254 ibcm_path_cache_stats.bad_path_for_cache++;
255 255 mutex_exit(&ibcm_path_cache_mutex);
256 256 return (IBCM_FAILURE);
257 257 }
258 258
259 259 dgid = attrp->pa_dgids[0];
260 260 if ((dgid.gid_guid | dgid.gid_prefix) == 0ULL)
261 261 return (IBCM_FAILURE);
262 262
263 263 mutex_enter(&ibcm_path_cache_mutex);
264 264 if (ibcm_path_cache_invalidate) { /* invalidate all entries */
265 265 ibcm_path_cache_stats.timeouts++;
266 266 ibcm_path_cache_invalidate = 0;
267 267 path_cachep = ibcm_path_cachep;
268 268 for (i = 0; i < ibcm_path_cache_size; i++, path_cachep++) {
269 269 path_cachep->dgid.gid_guid = 0ULL;
270 270 path_cachep->dgid.gid_prefix = 0ULL;
271 271 }
272 272 mutex_exit(&ibcm_path_cache_mutex);
273 273 return (IBCM_FAILURE);
274 274 }
275 275
276 276 path_cachep = ibcm_path_cachep;
277 277 for (i = 0; i < ibcm_path_cache_size; i++, path_cachep++) {
278 278 if (path_cachep->dgid.gid_guid == 0ULL)
279 279 break; /* end of search, no more valid cache entries */
280 280
281 281 /* make pa_dgids pointers match, so we can use memcmp */
282 282 path_cachep->attr.pa_dgids = attrp->pa_dgids;
283 283 if (path_cachep->flags != flags ||
284 284 path_cachep->dgid.gid_guid != dgid.gid_guid ||
285 285 path_cachep->dgid.gid_prefix != dgid.gid_prefix ||
286 286 memcmp(&(path_cachep->attr), attrp, sizeof (*attrp)) != 0) {
287 287 /* make pa_dgids NULL again */
288 288 path_cachep->attr.pa_dgids = NULL;
289 289 continue;
290 290 }
291 291 /* else we have a match */
292 292 /* make pa_dgids NULL again */
293 293 path_cachep->attr.pa_dgids = NULL;
294 294 *path = path_cachep->path; /* retval */
295 295 if (num_paths_p)
296 296 *num_paths_p = 1; /* retval */
297 297 ibcm_path_cache_stats.hits++;
298 298 mutex_exit(&ibcm_path_cache_mutex);
299 299 return (IBCM_SUCCESS);
300 300 }
301 301 ibcm_path_cache_stats.misses++;
302 302 mutex_exit(&ibcm_path_cache_mutex);
303 303 return (IBCM_FAILURE);
304 304 }
305 305
306 306 static void
307 307 ibcm_path_cache_add(ibt_path_flags_t flags,
308 308 ibt_path_attr_t *attrp, uint8_t max_paths, ibt_path_info_t *path)
309 309 {
310 310 int i;
311 311 ib_gid_t dgid;
312 312 ibcm_path_cache_t *path_cachep;
313 313
314 314 if (max_paths != 1 || attrp->pa_num_dgids != 1 ||
315 315 attrp->pa_sname != NULL || attrp->pa_sid != 0)
316 316 return;
317 317
318 318 dgid = attrp->pa_dgids[0];
319 319 if ((dgid.gid_guid | dgid.gid_prefix) == 0ULL)
320 320 return;
321 321
322 322 mutex_enter(&ibcm_path_cache_mutex);
323 323 path_cachep = ibcm_path_cachep;
324 324 for (i = 0; i < ibcm_path_cache_size; i++, path_cachep++) {
325 325 path_cachep->attr.pa_dgids = attrp->pa_dgids;
326 326 if (path_cachep->flags == flags &&
327 327 path_cachep->dgid.gid_guid == dgid.gid_guid &&
328 328 path_cachep->dgid.gid_prefix == dgid.gid_prefix &&
329 329 memcmp(&(path_cachep->attr), attrp, sizeof (*attrp)) == 0) {
330 330 /* already in cache */
331 331 ibcm_path_cache_stats.already_in_cache++;
332 332 path_cachep->attr.pa_dgids = NULL;
333 333 mutex_exit(&ibcm_path_cache_mutex);
334 334 return;
335 335 }
336 336 if (path_cachep->dgid.gid_guid != 0ULL) {
337 337 path_cachep->attr.pa_dgids = NULL;
338 338 continue;
339 339 }
340 340 /* else the rest of the entries are free, so use this one */
341 341 ibcm_path_cache_stats.adds++;
342 342 path_cachep->flags = flags;
343 343 path_cachep->attr = *attrp;
344 344 path_cachep->attr.pa_dgids = NULL;
345 345 path_cachep->dgid = attrp->pa_dgids[0];
346 346 path_cachep->path = *path;
347 347 mutex_exit(&ibcm_path_cache_mutex);
348 348 return;
349 349 }
350 350 mutex_exit(&ibcm_path_cache_mutex);
351 351 }
352 352
353 353 void
354 354 ibcm_path_cache_purge(void)
355 355 {
356 356 mutex_enter(&ibcm_path_cache_mutex);
357 357 ibcm_path_cache_invalidate = 1; /* invalidate cache on next check */
358 358 ibcm_path_cache_stats.purges++;
359 359 mutex_exit(&ibcm_path_cache_mutex);
360 360 }
361 361
362 362 /*
363 363 * Function:
364 364 * ibt_get_paths
365 365 * Input:
366 366 * ibt_hdl The handle returned to the client by the IBTF from an
367 367 * ibt_attach() call. Can be used by the IBTF Policy module
368 368 * and CM in the determination of the "best" path to the
369 369 * specified destination for this class of driver.
370 370 * flags Path flags.
371 371 * attrp Points to an ibt_path_attr_t struct that contains
372 372 * required and optional attributes.
373 373 * max_paths The size of the "paths" array argument. Also, this
374 374 * is the limit on the number of paths returned.
375 375 * max_paths indicates the number of requested paths to
376 376 * the specified destination(s).
377 377 * Output:
378 378 * paths An array of ibt_path_info_t structs filled in by
379 379 * ibt_get_paths() as output parameters. Upon return,
380 380 * array elements with non-NULL HCA GUIDs are valid.
381 381 * num_paths_p If non-NULL, return the actual number of paths found.
382 382 * Returns:
383 383 * IBT_SUCCESS on Success else appropriate error.
384 384 * Description:
385 385 * Finds the best path to a specified destination (as determined by the
386 386 * IBTL) that satisfies the requirements specified in an ibt_path_attr_t
387 387 * struct.
388 388 *
389 389 * This routine can not be called from interrupt context.
390 390 */
391 391 ibt_status_t
392 392 ibt_get_paths(ibt_clnt_hdl_t ibt_hdl, ibt_path_flags_t flags,
393 393 ibt_path_attr_t *attrp, uint8_t max_paths, ibt_path_info_t *paths,
394 394 uint8_t *num_paths_p)
395 395 {
396 396 ibt_status_t retval;
397 397
398 398 ASSERT(paths != NULL);
399 399
400 400 IBTF_DPRINTF_L3(cmlog, "ibt_get_paths(%p(%s), 0x%X, %p, %d)",
401 401 ibt_hdl, ibtl_cm_get_clnt_name(ibt_hdl), flags, attrp, max_paths);
402 402
403 403 if (paths == NULL) {
404 404 IBTF_DPRINTF_L2(cmlog, "ibt_get_paths: Path Info Pointer is "
405 405 "NULL - ERROR ");
406 406 return (IBT_INVALID_PARAM);
407 407 }
408 408
409 409 if (num_paths_p != NULL)
410 410 *num_paths_p = 0;
411 411
412 412 if (ibcm_path_cache_check(flags, attrp, max_paths, paths,
413 413 num_paths_p) == IBCM_SUCCESS)
414 414 return (IBT_SUCCESS);
415 415
416 416 retval = ibcm_handle_get_path(attrp, flags, max_paths, paths,
417 417 num_paths_p, NULL, NULL);
418 418
419 419 if (retval == IBT_SUCCESS)
420 420 ibcm_path_cache_add(flags, attrp, max_paths, paths);
421 421 return (retval);
422 422 }
423 423
424 424
425 425 static ibt_status_t
426 426 ibcm_handle_get_path(ibt_path_attr_t *attrp, ibt_path_flags_t flags,
427 427 uint8_t max_paths, ibt_path_info_t *paths, uint8_t *num_path_p,
428 428 ibt_path_handler_t func, void *arg)
429 429 {
430 430 ibcm_path_tqargs_t *path_tq;
431 431 int sleep_flag = ((func == NULL) ? KM_SLEEP : KM_NOSLEEP);
432 432 int len;
433 433 ibt_status_t retval;
434 434
435 435 retval = ibcm_validate_path_attributes(attrp, flags, max_paths);
436 436 if (retval != IBT_SUCCESS)
437 437 return (retval);
438 438
439 439 len = (attrp->pa_num_dgids * sizeof (ib_gid_t)) +
440 440 sizeof (ibcm_path_tqargs_t);
441 441
442 442 path_tq = kmem_alloc(len, sleep_flag);
443 443 if (path_tq == NULL) {
444 444 IBTF_DPRINTF_L2(cmlog, "ibcm_handle_get_path: "
445 445 "Unable to allocate memory for local usage.");
446 446 return (IBT_INSUFF_KERNEL_RESOURCE);
447 447 }
448 448
449 449 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*path_tq))
450 450
451 451 bcopy(attrp, &path_tq->attr, sizeof (ibt_path_attr_t));
452 452
453 453 if (attrp->pa_num_dgids) {
454 454 path_tq->attr.pa_dgids = (ib_gid_t *)(((uchar_t *)path_tq) +
455 455 sizeof (ibcm_path_tqargs_t));
456 456
457 457 bcopy(attrp->pa_dgids, path_tq->attr.pa_dgids,
458 458 sizeof (ib_gid_t) * attrp->pa_num_dgids);
459 459 } else {
460 460 path_tq->attr.pa_dgids = NULL;
461 461 }
462 462
463 463 /* Ignore IBT_PATH_AVAIL flag, if only one path is requested. */
464 464 if ((flags & IBT_PATH_AVAIL) && (max_paths == 1)) {
465 465 flags &= ~IBT_PATH_AVAIL;
466 466
467 467 IBTF_DPRINTF_L4(cmlog, "ibcm_handle_get_path: "
468 468 "Ignoring IBT_PATH_AVAIL flag, as only ONE path "
469 469 "information is requested.");
470 470 }
471 471
472 472 path_tq->flags = flags;
473 473 path_tq->max_paths = max_paths;
474 474 path_tq->paths = paths;
475 475 path_tq->num_paths_p = num_path_p;
476 476 path_tq->func = func;
477 477 path_tq->arg = arg;
478 478
479 479 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*path_tq))
480 480
481 481 if (func != NULL) { /* Non-Blocking */
482 482 IBTF_DPRINTF_L3(cmlog, "ibcm_handle_get_path: Non Blocking");
483 483 if (taskq_dispatch(ibcm_taskq, ibcm_process_async_get_paths,
484 484 path_tq, TQ_NOSLEEP) == 0) {
485 485 IBTF_DPRINTF_L2(cmlog, "ibcm_handle_get_path: "
486 486 "Failed to dispatch the TaskQ");
487 487 kmem_free(path_tq, len);
488 488 return (IBT_INSUFF_KERNEL_RESOURCE);
489 489 } else
490 490 return (IBT_SUCCESS);
491 491 } else { /* Blocking */
492 492 IBTF_DPRINTF_L3(cmlog, "ibcm_handle_get_path: Blocking");
493 493 return (ibcm_process_get_paths(path_tq));
494 494 }
495 495 }
496 496
497 497
498 498 static void
499 499 ibcm_process_async_get_paths(void *tq_arg)
500 500 {
501 501 (void) ibcm_process_get_paths(tq_arg);
502 502 }
503 503
504 504
505 505 static ibt_status_t
506 506 ibcm_validate_path_attributes(ibt_path_attr_t *attrp, ibt_path_flags_t flags,
507 507 uint8_t max_paths)
508 508 {
509 509 uint_t i;
510 510
511 511 IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: Inputs are: "
512 512 "HCA (%llX, %d),\n\tSGID(%llX:%llX), SName=\"%s\",\n\tSID= %llX, "
513 513 "Maxpath= %d, Flags= 0x%X, #Dgid= %d, SDFlag= 0x%llX",
514 514 attrp->pa_hca_guid, attrp->pa_hca_port_num,
515 515 attrp->pa_sgid.gid_prefix, attrp->pa_sgid.gid_guid,
516 516 ((attrp->pa_sname != NULL) ? attrp->pa_sname : ""), attrp->pa_sid,
517 517 max_paths, flags, attrp->pa_num_dgids, attrp->pa_sd_flags);
518 518
519 519 /*
520 520 * Validate Path Flags.
521 521 * IBT_PATH_AVAIL & IBT_PATH_PERF are mutually exclusive.
522 522 */
523 523 if ((flags & IBT_PATH_AVAIL) && (flags & IBT_PATH_PERF)) {
524 524 IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: "
525 525 "Invalid Flags: 0x%X,\n\t AVAIL and PERF flags cannot "
526 526 "specified together.", flags);
527 527 return (IBT_INVALID_PARAM);
528 528 }
529 529
530 530 /* Validate number of records requested. */
531 531 if ((flags & (IBT_PATH_AVAIL | IBT_PATH_PERF)) &&
532 532 (max_paths > IBT_MAX_SPECIAL_PATHS)) {
533 533 IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: "
534 534 "Max records that can be requested is <%d> \n"
535 535 "when IBT_PATH_AVAIL or IBT_PATH_PERF flag is specified.",
536 536 IBT_MAX_SPECIAL_PATHS);
537 537 return (IBT_INVALID_PARAM);
538 538 }
539 539
540 540 /* Only 2 destinations can be specified w/ APM flag. */
541 541 if ((flags & IBT_PATH_APM) && (attrp->pa_num_dgids > 2)) {
542 542 IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes:\n\t Max "
543 543 "number of DGIDs that can be specified w/APM flag is 2");
544 544 return (IBT_INVALID_PARAM);
545 545 }
546 546
547 547 /*
548 548 * Max_paths of "0" is invalid.
549 549 * w/ IBT_PATH_MULTI_SVC_DEST flag, max_paths must be greater than "1".
550 550 */
551 551 if ((max_paths == 0) ||
552 552 ((flags & IBT_PATH_MULTI_SVC_DEST) && (max_paths < 2))) {
553 553 IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: "
554 554 "Invalid number of records requested:\n flags 0x%X, "
555 555 "max_paths %d", flags, max_paths);
556 556 return (IBT_INVALID_PARAM);
557 557 }
558 558
559 559 /*
560 560 * If IBT_PATH_MULTI_SVC_DEST is set, then ServiceName and/or Service ID
561 561 * must be specified and DGIDs SHOULD NOT be specified.
562 562 */
563 563 if ((flags & IBT_PATH_MULTI_SVC_DEST) && ((attrp->pa_num_dgids > 0) ||
564 564 ((attrp->pa_sid == 0) && ((attrp->pa_sname == NULL) ||
565 565 ((attrp->pa_sname != NULL) && (strlen(attrp->pa_sname) == 0)))))) {
566 566 IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: "
567 567 "Invalid Flags: 0x%X, IBT_PATH_MULTI_SVC_DEST flag set "
568 568 "but Service Name \n or Service ID NOT specified or DGIDs "
569 569 "are specified.", flags);
570 570 return (IBT_INVALID_PARAM);
571 571 }
572 572
573 573 /*
574 574 * User need to specify the destination information, which can be
575 575 * provided as one or more of the following.
576 576 * o ServiceName
577 577 * o ServiceID
578 578 * o Array of DGIDs w/Num of DGIDs, (max of 2)
579 579 */
580 580 if ((attrp->pa_sid == 0) && (attrp->pa_num_dgids == 0) &&
581 581 ((attrp->pa_sname == NULL) || ((attrp->pa_sname != NULL) &&
582 582 (strlen(attrp->pa_sname) == 0)))) {
583 583 /* Destination information not provided, bail out. */
584 584 IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: "
585 585 "Client's MUST supply DestInfo.");
586 586 return (IBT_INVALID_PARAM);
587 587 }
588 588
589 589 /* If DGIDs are provided, validate them. */
590 590 if (attrp->pa_num_dgids > 0) {
591 591 if (attrp->pa_dgids == NULL) {
592 592 IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: "
593 593 "pa_dgids NULL, but pa_num_dgids : %d",
594 594 attrp->pa_num_dgids);
595 595 return (IBT_INVALID_PARAM);
596 596 }
597 597
598 598 /* Validate DGIDs */
599 599 for (i = 0; i < attrp->pa_num_dgids; i++) {
600 600 ib_gid_t gid = attrp->pa_dgids[i];
601 601
602 602 IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: "
603 603 "DGID[%d] = %llX:%llX", i, gid.gid_prefix,
604 604 gid.gid_guid);
605 605
606 606 /* APM request for MultiCast destination is invalid. */
607 607 if ((gid.gid_prefix >> 56ULL & 0xFF) == 0xFF) {
608 608 if (flags & IBT_PATH_APM) {
609 609 IBTF_DPRINTF_L2(cmlog,
610 610 "ibcm_validate_path_attributes: "
611 611 "APM for MGIDs not supported.");
612 612 return (IBT_INVALID_PARAM);
613 613 }
614 614 } else if ((gid.gid_prefix == 0) ||
615 615 (gid.gid_guid == 0)) {
616 616 IBTF_DPRINTF_L2(cmlog,
617 617 "ibcm_validate_path_attributes: ERROR: "
618 618 "Invalid DGIDs specified");
619 619 return (IBT_INVALID_PARAM);
620 620 }
621 621 }
622 622 }
623 623
624 624 /* Check for valid Service Name length. */
625 625 if ((attrp->pa_sname != NULL) &&
626 626 (strlen(attrp->pa_sname) >= IB_SVC_NAME_LEN)) {
627 627 IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: "
628 628 "ServiceName too long");
629 629 return (IBT_INVALID_PARAM);
630 630 }
631 631
632 632 /* If P_Key is specified, check for invalid p_key's */
633 633 if (flags & IBT_PATH_PKEY) {
634 634 /* Limited P_Key is NOT supported as of now!. */
635 635 if ((attrp->pa_pkey == IB_PKEY_INVALID_FULL) ||
636 636 (attrp->pa_pkey & 0x8000) == 0) {
637 637 IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: "
638 638 "Specified P_Key is invalid: 0x%X", attrp->pa_pkey);
639 639 return (IBT_INVALID_PARAM);
640 640 }
641 641 IBTF_DPRINTF_L3(cmlog, "ibcm_validate_path_attributes: "
642 642 "P_Key= 0x%X", attrp->pa_pkey);
643 643 }
644 644
645 645 return (IBT_SUCCESS);
646 646 }
647 647
648 648
649 649 static ibt_status_t
650 650 ibcm_process_get_paths(void *tq_arg)
651 651 {
652 652 ibcm_path_tqargs_t *p_arg = (ibcm_path_tqargs_t *)tq_arg;
653 653 ibcm_dinfo_t *dinfo;
654 654 int len;
655 655 uint8_t max_paths, num_path;
656 656 ibt_status_t retval;
657 657 ib_gid_t *d_gids_p = NULL;
658 658 ibtl_cm_port_list_t *slistp = NULL;
659 659 uint_t dnum = 0;
660 660 uint8_t num_dest, i, j;
661 661 ibcm_hca_info_t *hcap;
662 662 ibmf_saa_handle_t saa_handle;
663 663
664 664 IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_paths(%p, 0x%X, %d) ",
665 665 p_arg, p_arg->flags, p_arg->max_paths);
666 666
667 667 max_paths = num_path = p_arg->max_paths;
668 668
669 669 /*
670 670 * Prepare the Destination list based on the input DGIDs and
671 671 * other attributes.
672 672 *
673 673 * APM is requested and pa_dgids are specified. If multiple DGIDs are
674 674 * specified, check out whether they are companion to each other or if
675 675 * only one DGID is specified, then get the companion port GID for that.
676 676 */
677 677 if (p_arg->attr.pa_num_dgids) {
678 678 if (p_arg->flags & IBT_PATH_APM) {
679 679 ib_gid_t c_gid, n_gid;
680 680
681 681 IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_paths: "
682 682 "DGIDs specified w/ APM Flag");
683 683
684 684 c_gid = p_arg->attr.pa_dgids[0];
685 685 if (p_arg->attr.pa_num_dgids > 1)
686 686 n_gid = p_arg->attr.pa_dgids[1];
687 687 else
688 688 n_gid.gid_prefix = n_gid.gid_guid = 0;
689 689
690 690 retval = ibcm_get_comp_pgids(c_gid, n_gid, 0, &d_gids_p,
691 691 &dnum);
692 692 if ((retval != IBT_SUCCESS) &&
693 693 (retval != IBT_GIDS_NOT_FOUND)) {
694 694 IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths:"
695 695 " Invalid DGIDs specified w/ APM Flag");
696 696 goto path_error2;
697 697 }
698 698 IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_paths: "
699 699 "Found %d Comp DGID", dnum);
700 700 }
701 701
702 702 if (dnum) {
703 703 len = 1;
704 704 } else {
705 705 len = p_arg->attr.pa_num_dgids - 1;
706 706 }
707 707 num_dest = len + 1;
708 708
709 709 IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_paths: #dgid %d, dnum "
710 710 "%d, #dest %d", p_arg->attr.pa_num_dgids, dnum, num_dest);
711 711 } else {
712 712 if (p_arg->flags & IBT_PATH_MULTI_SVC_DEST) {
713 713 IBTF_DPRINTF_L4(cmlog, "ibcm_process_get_paths: "
714 714 "IBT_PATH_MULTI_SVC_DEST flags set");
715 715 len = max_paths - 1;
716 716 } else if (p_arg->flags & IBT_PATH_APM) {
717 717 len = 1;
718 718 } else {
719 719 len = 0;
720 720 }
721 721 num_dest = 0;
722 722 }
723 723
724 724 /* Allocate memory and accumulate all destination information */
725 725 len = (len * sizeof (ibcm_dest_t)) + sizeof (ibcm_dinfo_t);
726 726
727 727 dinfo = kmem_zalloc(len, KM_SLEEP);
728 728 dinfo->num_dest = num_dest;
729 729 if (p_arg->flags & IBT_PATH_PKEY)
730 730 dinfo->p_key = p_arg->attr.pa_pkey;
731 731
732 732 for (i = 0, j = 0; i < num_dest; i++) {
733 733 if (i < p_arg->attr.pa_num_dgids)
734 734 dinfo->dest[i].d_gid = p_arg->attr.pa_dgids[i];
735 735 else
736 736 dinfo->dest[i].d_gid = d_gids_p[j++];
737 737 }
738 738
739 739 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*p_arg))
740 740
741 741 /* IBTF allocates memory for path_info in case of Async Get Paths */
742 742 if (p_arg->paths == NULL)
743 743 p_arg->paths = kmem_zalloc(sizeof (ibt_path_info_t) * max_paths,
744 744 KM_SLEEP);
745 745
746 746 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*p_arg))
747 747
748 748 /*
749 749 * Get list of active HCA<->Port list, that matches input specified attr
750 750 */
751 751 IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_paths: Get Paths from \n HCA "
752 752 "(%llX:%d), SGID %llX:%llX", p_arg->attr.pa_hca_guid,
753 753 p_arg->attr.pa_hca_port_num, p_arg->attr.pa_sgid.gid_prefix,
754 754 p_arg->attr.pa_sgid.gid_guid);
755 755
756 756 retval = ibtl_cm_get_active_plist(&p_arg->attr, p_arg->flags, &slistp);
757 757 if (retval != IBT_SUCCESS) {
758 758 IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths: HCA capable of "
759 759 "requested source attributes NOT available.");
760 760 goto path_error;
761 761 }
762 762
763 763 IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_paths: HCA (%llX, %d)",
764 764 slistp->p_hca_guid, slistp->p_port_num);
765 765
766 766 hcap = ibcm_find_hca_entry(slistp->p_hca_guid);
767 767 if (hcap == NULL) {
768 768 IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths: "
769 769 "NO HCA found");
770 770 retval = IBT_HCA_BUSY_DETACHING;
771 771 goto path_error;
772 772 }
773 773
774 774 /* Get SA Access Handle. */
775 775 for (i = 0; i < slistp->p_count; i++) {
776 776 if (i == 0) {
777 777 /* Validate whether this HCA supports APM */
778 778 if ((p_arg->flags & IBT_PATH_APM) &&
779 779 (!(hcap->hca_caps & IBT_HCA_AUTO_PATH_MIG))) {
780 780 IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths:"
781 781 " HCA (%llX): APM NOT SUPPORTED ",
782 782 slistp[i].p_hca_guid);
783 783 retval = IBT_APM_NOT_SUPPORTED;
784 784 goto path_error1;
785 785 }
786 786 }
787 787
788 788 saa_handle = ibcm_get_saa_handle(hcap, slistp[i].p_port_num);
789 789 if (saa_handle == NULL) {
790 790 IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths: "
791 791 "SAA HDL NULL, HCA (%llX:%d) NOT ACTIVE",
792 792 slistp[i].p_hca_guid, slistp[i].p_port_num);
793 793 retval = IBT_HCA_PORT_NOT_ACTIVE;
794 794 goto path_error1;
795 795 }
796 796 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*slistp))
797 797 slistp[i].p_saa_hdl = saa_handle;
798 798 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*slistp))
799 799 }
800 800
801 801 /*
802 802 * If Service Name or Service ID are specified, first retrieve
803 803 * Service Records.
804 804 */
805 805 if ((p_arg->attr.pa_sid != 0) || ((p_arg->attr.pa_sname != NULL) &&
806 806 (strlen(p_arg->attr.pa_sname) != 0))) {
807 807
808 808 IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_paths: Get Service "
809 809 "Record for \n\t(%llX, \"%s\")", p_arg->attr.pa_sid,
810 810 ((p_arg->attr.pa_sname != NULL) ?
811 811 p_arg->attr.pa_sname : ""));
812 812
813 813 /* Get Service Records. */
814 814 retval = ibcm_saa_service_rec(p_arg, slistp, dinfo);
815 815 if ((retval != IBT_SUCCESS) && (retval != IBT_INSUFF_DATA)) {
816 816 IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths: Status="
817 817 "%d, Failed to get Service Record for \n\t"
818 818 "(%llX, \"%s\")", retval, p_arg->attr.pa_sid,
819 819 ((p_arg->attr.pa_sname != NULL) ?
820 820 p_arg->attr.pa_sname : ""));
821 821 goto path_error1;
822 822 }
823 823 }
824 824
825 825 /* Get Path Records. */
826 826 retval = ibcm_saa_path_rec(p_arg, slistp, dinfo, &num_path);
827 827
828 828 path_error1:
829 829 ibcm_dec_hca_acc_cnt(hcap);
830 830
831 831 path_error:
832 832 if (slistp)
833 833 ibtl_cm_free_active_plist(slistp);
834 834
835 835 if (dinfo)
836 836 kmem_free(dinfo, len);
837 837
838 838 path_error2:
839 839 if ((retval != IBT_SUCCESS) && (retval != IBT_INSUFF_DATA))
840 840 num_path = 0;
841 841
842 842 if (p_arg->num_paths_p != NULL)
843 843 *p_arg->num_paths_p = num_path;
844 844
845 845 if ((dnum) && (d_gids_p))
846 846 kmem_free(d_gids_p, dnum * sizeof (ib_gid_t));
847 847
848 848 if (p_arg->func) { /* Do these only for Async Get Paths */
849 849 ibt_path_info_t *tmp_path_p;
850 850
851 851 if (retval == IBT_INSUFF_DATA) {
852 852 /*
853 853 * We allocated earlier memory based on "max_paths",
854 854 * but we got lesser path-records, so re-adjust that
855 855 * buffer so that caller can free the correct memory.
856 856 */
857 857 tmp_path_p = kmem_alloc(
858 858 sizeof (ibt_path_info_t) * num_path, KM_SLEEP);
859 859
860 860 bcopy(p_arg->paths, tmp_path_p,
861 861 num_path * sizeof (ibt_path_info_t));
862 862
863 863 kmem_free(p_arg->paths,
864 864 sizeof (ibt_path_info_t) * max_paths);
865 865 } else if (retval != IBT_SUCCESS) {
866 866 if (p_arg->paths)
867 867 kmem_free(p_arg->paths,
868 868 sizeof (ibt_path_info_t) * max_paths);
869 869 tmp_path_p = NULL;
870 870 } else {
871 871 tmp_path_p = p_arg->paths;
872 872 }
873 873 (*(p_arg->func))(p_arg->arg, retval, tmp_path_p, num_path);
874 874 }
875 875
876 876 len = (sizeof (ib_gid_t) * p_arg->attr.pa_num_dgids) +
877 877 sizeof (ibcm_path_tqargs_t);
878 878
879 879 if (p_arg && len)
880 880 kmem_free(p_arg, len);
881 881
882 882 IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths: done: status %d, "
883 883 "Found %d/%d Path Records", retval, num_path, max_paths);
884 884
885 885 return (retval);
886 886 }
887 887
888 888
889 889 /*
890 890 * Perform SA Access to retrieve Path Records.
891 891 */
892 892 static ibt_status_t
893 893 ibcm_saa_path_rec(ibcm_path_tqargs_t *p_arg, ibtl_cm_port_list_t *sl,
894 894 ibcm_dinfo_t *dinfo, uint8_t *max_count)
895 895 {
896 896 uint8_t num_path = *max_count;
897 897 uint8_t num_path_plus;
898 898 uint8_t extra, idx, rec_found = 0;
899 899 ibt_status_t retval = IBT_SUCCESS;
900 900 int unicast_dgid_present = 0;
901 901 uint8_t i;
902 902
903 903 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec(%p, %p, %p, 0x%X, %d)",
904 904 p_arg, sl, dinfo, p_arg->flags, *max_count);
905 905
906 906 if ((dinfo->num_dest == 0) || (num_path == 0) || (sl == NULL)) {
907 907 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec: Invalid Counters");
908 908 return (IBT_INVALID_PARAM);
909 909 }
910 910
911 911 /*
912 912 * Of the total needed "X" number of paths to "Y" number of destination
913 913 * we need to get X/Y plus X%Y extra paths to each destination,
914 914 * We do this so that we can choose the required number of path records
915 915 * for the specific destination.
916 916 */
917 917 num_path /= dinfo->num_dest;
918 918 extra = (*max_count % dinfo->num_dest);
919 919
920 920 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec: numpath %d extra %d dest %d",
921 921 num_path, extra, dinfo->num_dest);
922 922
923 923 /* Find out whether we need to get PathRecord for a MGID as DGID. */
924 924 for (idx = 0; idx < dinfo->num_dest; idx++) {
925 925 ib_gid_t dgid = dinfo->dest[idx].d_gid;
926 926
927 927 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec: DGID[%d]: %llX:%llX",
928 928 idx, dgid.gid_prefix, dgid.gid_guid);
929 929
930 930 if ((dgid.gid_prefix >> 56ULL & 0xFF) == 0xFF) {
931 931 if (extra)
932 932 num_path_plus = num_path + 1;
933 933 else
934 934 num_path_plus = num_path;
935 935
936 936 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec: Get %d Paths"
937 937 "- MGID(%016llX%016llX)", num_path_plus,
938 938 dgid.gid_prefix, dgid.gid_guid);
939 939
940 940 dinfo->dest[idx].d_tag = 1; /* MultiCast */
941 941
942 942 /* Yes, it's Single PathRec query for MGID as DGID. */
943 943 retval = ibcm_get_single_pathrec(p_arg, sl, dinfo, idx,
944 944 &num_path_plus, &p_arg->paths[rec_found]);
945 945 if ((retval != IBT_SUCCESS) &&
946 946 (retval != IBT_INSUFF_DATA)) {
947 947 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec: "
948 948 "Failed to get PathRec for MGID %d",
949 949 retval);
950 950 continue;
951 951 }
952 952 if (extra)
953 953 extra--;
954 954
955 955 rec_found += num_path_plus;
956 956 }
957 957 if (rec_found == *max_count)
958 958 break;
959 959 }
960 960
961 961 for (i = 0; i < dinfo->num_dest; i++) {
962 962 if (dinfo->dest[i].d_tag == 0) {
963 963 unicast_dgid_present++;
964 964 }
965 965 }
966 966
967 967 num_path_plus = *max_count - rec_found;
968 968
969 969 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec: Recfound: %d, need to find "
970 970 "%d, UniCastGID present %d", rec_found, num_path_plus,
971 971 unicast_dgid_present);
972 972
973 973 if ((unicast_dgid_present != 0) && (num_path_plus > 0)) {
974 974 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec: MultiSM=%X, #SRC=%d,"
975 975 "Dest%d", sl->p_multi, sl->p_count, unicast_dgid_present);
976 976
977 977 if ((sl->p_multi != IBTL_CM_SIMPLE_SETUP) ||
978 978 ((unicast_dgid_present == 1) && (sl->p_count == 1))) {
979 979 /*
980 980 * Use SinglePathRec if we are dealing w/ MultiSM or
981 981 * request is for one SGID to one DGID.
982 982 */
983 983 retval = ibcm_get_single_pathrec(p_arg, sl, dinfo, 0xFF,
984 984 &num_path_plus, &p_arg->paths[rec_found]);
985 985 } else {
986 986 uint8_t old_num_path_plus = num_path_plus;
987 987
988 988 /* MultiPathRec will be used for other queries. */
989 989 retval = ibcm_get_multi_pathrec(p_arg, sl, dinfo,
990 990 &num_path_plus, &p_arg->paths[rec_found]);
991 991 if ((retval != IBT_SUCCESS) &&
992 992 (retval != IBT_INSUFF_DATA) &&
993 993 (sl->p_count > 0) &&
994 994 (dinfo->num_dest > 0)) {
995 995 ibtl_cm_port_list_t sl_tmp = *sl;
996 996 ibcm_dinfo_t dinfo_tmp = *dinfo;
997 997
998 998 sl_tmp.p_count = 1;
999 999 dinfo_tmp.num_dest = 1;
1000 1000 num_path_plus = old_num_path_plus;
1001 1001 retval = ibcm_get_single_pathrec(p_arg, &sl_tmp,
1002 1002 &dinfo_tmp, 0xFF, &num_path_plus,
1003 1003 &p_arg->paths[rec_found]);
1004 1004 }
1005 1005 }
1006 1006 if ((retval != IBT_SUCCESS) && (retval != IBT_INSUFF_DATA)) {
1007 1007 IBTF_DPRINTF_L2(cmlog, "ibcm_saa_path_rec: "
1008 1008 "Failed to get PathRec: Status %d", retval);
1009 1009 } else {
1010 1010 rec_found += num_path_plus;
1011 1011 }
1012 1012 }
1013 1013
1014 1014 if (rec_found == 0) {
1015 1015 if (retval == IBT_SUCCESS)
1016 1016 retval = IBT_PATH_RECORDS_NOT_FOUND;
1017 1017 } else if (rec_found != *max_count)
1018 1018 retval = IBT_INSUFF_DATA;
1019 1019 else if (rec_found != 0)
1020 1020 retval = IBT_SUCCESS;
1021 1021
1022 1022 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec: done. Status = %d, "
1023 1023 "Found %d/%d Paths", retval, rec_found, *max_count);
1024 1024
1025 1025 *max_count = rec_found; /* Update the return count. */
1026 1026
1027 1027 return (retval);
1028 1028 }
1029 1029
1030 1030 ibt_status_t
1031 1031 ibcm_contact_sa_access(ibmf_saa_handle_t saa_handle,
1032 1032 ibmf_saa_access_args_t *access_args, size_t *length, void **results_p)
1033 1033 {
1034 1034 int retry;
1035 1035 int sa_retval;
1036 1036
1037 1037 IBTF_DPRINTF_L3(cmlog, "ibcm_contact_sa_access(%p, %p)",
1038 1038 saa_handle, access_args);
1039 1039
1040 1040 ibcm_sa_access_enter();
1041 1041
1042 1042 for (retry = 0; retry < ibcm_max_sa_retries; retry++) {
1043 1043 sa_retval = ibmf_sa_access(saa_handle, access_args, 0,
1044 1044 length, results_p);
1045 1045 if (sa_retval != IBMF_TRANS_TIMEOUT)
1046 1046 break;
1047 1047
1048 1048 IBTF_DPRINTF_L2(cmlog, "ibcm_contact_sa_access: "
1049 1049 "ibmf_sa_access() - Timed Out (%d)", sa_retval);
1050 1050 delay(ibcm_sa_timeout_delay);
1051 1051 }
1052 1052
1053 1053 ibcm_sa_access_exit();
1054 1054
1055 1055 if ((sa_retval == IBMF_SUCCESS) || (sa_retval == IBMF_NO_RECORDS) ||
1056 1056 (sa_retval == IBMF_REQ_INVALID)) {
1057 1057 IBTF_DPRINTF_L3(cmlog, "ibcm_contact_sa_access: "
1058 1058 "ibmf_sa_access() returned (%d)", sa_retval);
1059 1059 return (IBT_SUCCESS);
1060 1060 } else {
1061 1061 IBTF_DPRINTF_L2(cmlog, "ibcm_contact_sa_access: "
1062 1062 "ibmf_sa_access(): Failed (%d)", sa_retval);
1063 1063 return (ibcm_ibmf_analyze_error(sa_retval));
1064 1064 }
1065 1065 }
1066 1066
1067 1067
1068 1068 static ibt_status_t
1069 1069 ibcm_update_pri(sa_path_record_t *pr_resp, ibtl_cm_port_list_t *sl,
1070 1070 ibcm_dinfo_t *dinfo, ibt_path_info_t *paths)
1071 1071 {
1072 1072 ibt_status_t retval = IBT_SUCCESS;
1073 1073 int d, s;
1074 1074
1075 1075 retval = ibcm_update_cep_info(pr_resp, sl, NULL,
1076 1076 &paths->pi_prim_cep_path);
1077 1077 if (retval != IBT_SUCCESS)
1078 1078 return (retval);
1079 1079
1080 1080 /* Update some leftovers */
1081 1081 paths->pi_prim_pkt_lt = pr_resp->PacketLifeTime;
1082 1082 paths->pi_path_mtu = pr_resp->Mtu;
1083 1083
1084 1084 for (d = 0; d < dinfo->num_dest; d++) {
1085 1085 if (pr_resp->DGID.gid_guid == dinfo->dest[d].d_gid.gid_guid) {
1086 1086 paths->pi_sid = dinfo->dest[d].d_sid;
1087 1087 if (paths->pi_sid != 0) {
1088 1088 bcopy(&dinfo->dest[d].d_sdata,
1089 1089 &paths->pi_sdata, sizeof (ibt_srv_data_t));
1090 1090 }
1091 1091 break;
1092 1092 }
1093 1093 }
1094 1094
1095 1095 for (s = 0; s < sl->p_count; s++) {
1096 1096 if (pr_resp->SGID.gid_guid == sl[s].p_sgid.gid_guid) {
1097 1097 paths->pi_hca_guid = sl[s].p_hca_guid;
1098 1098 }
1099 1099 }
1100 1100
1101 1101 /* Set Alternate Path to invalid state. */
1102 1102 paths->pi_alt_cep_path.cep_hca_port_num = 0;
1103 1103 paths->pi_alt_cep_path.cep_adds_vect.av_dlid = 0;
1104 1104
1105 1105 IBTF_DPRINTF_L5(cmlog, "Path: HCA GUID = 0x%llX", paths->pi_hca_guid);
1106 1106 IBTF_DPRINTF_L5(cmlog, "Path: ServiceID = 0x%llX", paths->pi_sid);
1107 1107
1108 1108 return (retval);
1109 1109 }
1110 1110
1111 1111
1112 1112 static ibt_status_t
1113 1113 ibcm_get_single_pathrec(ibcm_path_tqargs_t *p_arg, ibtl_cm_port_list_t *sl,
1114 1114 ibcm_dinfo_t *dinfo, uint8_t idx, uint8_t *num_path, ibt_path_info_t *paths)
1115 1115 {
1116 1116 sa_path_record_t pathrec_req;
1117 1117 sa_path_record_t *pr_resp;
1118 1118 ibmf_saa_access_args_t access_args;
1119 1119 uint64_t c_mask = 0;
1120 1120 void *results_p;
1121 1121 uint8_t num_rec;
1122 1122 size_t length;
1123 1123 ibt_status_t retval;
1124 1124 int i, j, k;
1125 1125 uint8_t found, p_fnd;
1126 1126 ibt_path_attr_t *attrp = &p_arg->attr;
1127 1127 ibmf_saa_handle_t saa_handle;
1128 1128
1129 1129 IBTF_DPRINTF_L3(cmlog, "ibcm_get_single_pathrec(%p, %p, %p, %d)",
1130 1130 p_arg, sl, dinfo, *num_path);
1131 1131
1132 1132 bzero(&pathrec_req, sizeof (sa_path_record_t));
1133 1133
1134 1134 /* Is Flow Label Specified. */
1135 1135 if (attrp->pa_flow) {
1136 1136 pathrec_req.FlowLabel = attrp->pa_flow;
1137 1137 c_mask |= SA_PR_COMPMASK_FLOWLABEL;
1138 1138 }
1139 1139
1140 1140 /* Is HopLimit Specified. */
1141 1141 if (p_arg->flags & IBT_PATH_HOP) {
1142 1142 pathrec_req.HopLimit = attrp->pa_hop;
1143 1143 c_mask |= SA_PR_COMPMASK_HOPLIMIT;
1144 1144 }
1145 1145
1146 1146 /* Is P_Key Specified. */
1147 1147 if (dinfo->p_key) {
1148 1148 IBTF_DPRINTF_L3(cmlog, "ibcm_get_single_pathrec: "
1149 1149 "Specified or Global PKEY 0x%X", dinfo->p_key);
1150 1150 pathrec_req.P_Key = dinfo->p_key;
1151 1151 c_mask |= SA_PR_COMPMASK_PKEY;
1152 1152 }
1153 1153
1154 1154 /* Is TClass Specified. */
1155 1155 if (attrp->pa_tclass) {
1156 1156 pathrec_req.TClass = attrp->pa_tclass;
1157 1157 c_mask |= SA_PR_COMPMASK_TCLASS;
1158 1158 }
1159 1159
1160 1160 /* Is SL specified. */
1161 1161 if (attrp->pa_sl) {
1162 1162 pathrec_req.SL = attrp->pa_sl;
1163 1163 c_mask |= SA_PR_COMPMASK_SL;
1164 1164 }
1165 1165
1166 1166 /* If IBT_PATH_PERF is set, then mark all selectors to BEST. */
1167 1167 if (p_arg->flags & IBT_PATH_PERF) {
1168 1168 pathrec_req.PacketLifeTimeSelector = IBT_BEST;
1169 1169 pathrec_req.MtuSelector = IBT_BEST;
1170 1170 pathrec_req.RateSelector = IBT_BEST;
1171 1171
1172 1172 c_mask |= SA_PR_COMPMASK_PKTLTSELECTOR |
1173 1173 SA_PR_COMPMASK_RATESELECTOR | SA_PR_COMPMASK_MTUSELECTOR;
1174 1174 } else {
1175 1175 if (attrp->pa_pkt_lt.p_selector == IBT_BEST) {
1176 1176 pathrec_req.PacketLifeTimeSelector = IBT_BEST;
1177 1177 c_mask |= SA_PR_COMPMASK_PKTLTSELECTOR;
1178 1178 }
1179 1179
1180 1180 if (attrp->pa_srate.r_selector == IBT_BEST) {
1181 1181 pathrec_req.RateSelector = IBT_BEST;
1182 1182 c_mask |= SA_PR_COMPMASK_RATESELECTOR;
1183 1183 }
1184 1184
1185 1185 if (attrp->pa_mtu.r_selector == IBT_BEST) {
1186 1186 pathrec_req.MtuSelector = IBT_BEST;
1187 1187 c_mask |= SA_PR_COMPMASK_MTUSELECTOR;
1188 1188 }
1189 1189 }
1190 1190
1191 1191 /*
1192 1192 * Honor individual selection of these attributes,
1193 1193 * even if IBT_PATH_PERF is set.
1194 1194 */
1195 1195 /* Check out whether Packet Life Time is specified. */
1196 1196 if (attrp->pa_pkt_lt.p_pkt_lt) {
1197 1197 pathrec_req.PacketLifeTime =
1198 1198 ibt_usec2ib(attrp->pa_pkt_lt.p_pkt_lt);
1199 1199 pathrec_req.PacketLifeTimeSelector =
1200 1200 attrp->pa_pkt_lt.p_selector;
1201 1201
1202 1202 c_mask |= SA_PR_COMPMASK_PKTLT | SA_PR_COMPMASK_PKTLTSELECTOR;
1203 1203 }
1204 1204
1205 1205 /* Is SRATE specified. */
1206 1206 if (attrp->pa_srate.r_srate) {
1207 1207 pathrec_req.Rate = attrp->pa_srate.r_srate;
1208 1208 pathrec_req.RateSelector = attrp->pa_srate.r_selector;
1209 1209
1210 1210 c_mask |= SA_PR_COMPMASK_RATE | SA_PR_COMPMASK_RATESELECTOR;
1211 1211 }
1212 1212
1213 1213 /* Is MTU specified. */
1214 1214 if (attrp->pa_mtu.r_mtu) {
1215 1215 pathrec_req.Mtu = attrp->pa_mtu.r_mtu;
1216 1216 pathrec_req.MtuSelector = attrp->pa_mtu.r_selector;
1217 1217
1218 1218 c_mask |= SA_PR_COMPMASK_MTU | SA_PR_COMPMASK_MTUSELECTOR;
1219 1219 }
1220 1220
1221 1221 /* We always get REVERSIBLE paths. */
1222 1222 pathrec_req.Reversible = 1;
1223 1223 c_mask |= SA_PR_COMPMASK_REVERSIBLE;
1224 1224
1225 1225 pathrec_req.NumbPath = *num_path;
1226 1226 c_mask |= SA_PR_COMPMASK_NUMBPATH;
1227 1227
1228 1228 if (idx != 0xFF) {
1229 1229 /* MGID */
1230 1230 pathrec_req.DGID = dinfo->dest[idx].d_gid;
1231 1231 c_mask |= SA_PR_COMPMASK_DGID;
1232 1232 }
1233 1233
1234 1234 p_fnd = found = 0;
1235 1235
1236 1236 for (i = 0; i < sl->p_count; i++) {
1237 1237 /* SGID */
1238 1238 pathrec_req.SGID = sl[i].p_sgid;
1239 1239 c_mask |= SA_PR_COMPMASK_SGID;
1240 1240 saa_handle = sl[i].p_saa_hdl;
1241 1241
1242 1242 for (k = 0; k < dinfo->num_dest; k++) {
1243 1243 if (idx == 0xFF) { /* DGID */
1244 1244 if (dinfo->dest[k].d_tag != 0)
1245 1245 continue;
1246 1246
1247 1247 if (pathrec_req.SGID.gid_prefix !=
1248 1248 dinfo->dest[k].d_gid.gid_prefix) {
1249 1249 IBTF_DPRINTF_L3(cmlog,
1250 1250 "ibcm_get_single_pathrec: SGID_pfx="
1251 1251 "%llX, DGID_pfx=%llX doesn't match",
1252 1252 pathrec_req.SGID.gid_prefix,
1253 1253 dinfo->dest[k].d_gid.gid_prefix);
1254 1254 continue;
1255 1255 }
1256 1256
1257 1257 pathrec_req.DGID = dinfo->dest[k].d_gid;
1258 1258 c_mask |= SA_PR_COMPMASK_DGID;
1259 1259
1260 1260 /*
1261 1261 * If we had performed Service Look-up, then we
1262 1262 * got P_Key from ServiceRecord, so get path
1263 1263 * records that satisfy this particular P_Key.
1264 1264 */
1265 1265 if ((dinfo->p_key == 0) &&
1266 1266 (dinfo->dest[k].d_pkey != 0)) {
1267 1267 pathrec_req.P_Key =
1268 1268 dinfo->dest[k].d_pkey;
1269 1269 c_mask |= SA_PR_COMPMASK_PKEY;
1270 1270 }
1271 1271 }
1272 1272
1273 1273 IBTF_DPRINTF_L3(cmlog, "ibcm_get_single_pathrec: "
1274 1274 "Get %d Path(s) between\nSGID %llX:%llX "
1275 1275 "DGID %llX:%llX", pathrec_req.NumbPath,
1276 1276 pathrec_req.SGID.gid_prefix,
1277 1277 pathrec_req.SGID.gid_guid,
1278 1278 pathrec_req.DGID.gid_prefix,
1279 1279 pathrec_req.DGID.gid_guid);
1280 1280
1281 1281 IBTF_DPRINTF_L3(cmlog, "ibcm_get_single_pathrec: CMask"
1282 1282 "=0x%llX, PKey=0x%X", c_mask, pathrec_req.P_Key);
1283 1283
1284 1284 /* Contact SA Access to retrieve Path Records. */
1285 1285 access_args.sq_attr_id = SA_PATHRECORD_ATTRID;
1286 1286 access_args.sq_template = &pathrec_req;
1287 1287 access_args.sq_access_type = IBMF_SAA_RETRIEVE;
1288 1288 access_args.sq_template_length =
1289 1289 sizeof (sa_path_record_t);
1290 1290 access_args.sq_component_mask = c_mask;
1291 1291 access_args.sq_callback = NULL;
1292 1292 access_args.sq_callback_arg = NULL;
1293 1293
1294 1294 retval = ibcm_contact_sa_access(saa_handle,
1295 1295 &access_args, &length, &results_p);
1296 1296 if (retval != IBT_SUCCESS) {
1297 1297 *num_path = 0;
1298 1298 return (retval);
1299 1299 }
1300 1300
1301 1301 num_rec = length / sizeof (sa_path_record_t);
1302 1302
1303 1303 IBTF_DPRINTF_L3(cmlog, "ibcm_get_single_pathrec: "
1304 1304 "FOUND %d/%d path requested", num_rec, *num_path);
1305 1305
1306 1306 if ((results_p == NULL) || (num_rec == 0)) {
1307 1307 if (idx != 0xFF)
1308 1308 break;
1309 1309 else
1310 1310 continue;
1311 1311 }
1312 1312
1313 1313 /* Update the PathInfo from the response. */
1314 1314 pr_resp = (sa_path_record_t *)results_p;
1315 1315 for (j = 0; j < num_rec; j++, pr_resp++) {
1316 1316 if ((p_fnd != 0) &&
1317 1317 (p_arg->flags & IBT_PATH_APM)) {
1318 1318 IBTF_DPRINTF_L3(cmlog,
1319 1319 "ibcm_get_single_pathrec: "
1320 1320 "Fill Alternate Path");
1321 1321 retval = ibcm_update_cep_info(pr_resp,
1322 1322 sl, NULL,
1323 1323 &paths[found - 1].pi_alt_cep_path);
1324 1324 if (retval != IBT_SUCCESS)
1325 1325 continue;
1326 1326
1327 1327 /* Update some leftovers */
1328 1328 paths[found - 1].pi_alt_pkt_lt =
1329 1329 pr_resp->PacketLifeTime;
1330 1330 p_fnd = 0;
1331 1331 } else {
1332 1332 IBTF_DPRINTF_L3(cmlog,
1333 1333 "ibcm_get_single_pathrec: "
1334 1334 "Fill Primary Path");
1335 1335
1336 1336 if (found == *num_path)
1337 1337 break;
1338 1338
1339 1339 retval = ibcm_update_pri(pr_resp, sl,
1340 1340 dinfo, &paths[found]);
1341 1341 if (retval != IBT_SUCCESS)
1342 1342 continue;
1343 1343 p_fnd = 1;
1344 1344 found++;
1345 1345 }
1346 1346
1347 1347 }
1348 1348 /* Deallocate the memory for results_p. */
1349 1349 kmem_free(results_p, length);
1350 1350
1351 1351 if (idx != 0xFF)
1352 1352 break; /* We r here for MGID */
1353 1353 }
1354 1354 if ((idx != 0xFF) && (found == *num_path))
1355 1355 break; /* We r here for MGID */
1356 1356 }
1357 1357
1358 1358 if (found == 0)
1359 1359 retval = IBT_PATH_RECORDS_NOT_FOUND;
1360 1360 else if (found != *num_path)
1361 1361 retval = IBT_INSUFF_DATA;
1362 1362 else
1363 1363 retval = IBT_SUCCESS;
1364 1364
1365 1365 IBTF_DPRINTF_L3(cmlog, "ibcm_get_single_pathrec: done. Status %d, "
1366 1366 "Found %d/%d Paths", retval, found, *num_path);
1367 1367
1368 1368 *num_path = found;
1369 1369
1370 1370 return (retval);
1371 1371 }
1372 1372
1373 1373
1374 1374 static ibt_status_t
1375 1375 ibcm_get_multi_pathrec(ibcm_path_tqargs_t *p_arg, ibtl_cm_port_list_t *sl,
1376 1376 ibcm_dinfo_t *dinfo, uint8_t *num_path, ibt_path_info_t *paths)
1377 1377 {
1378 1378 sa_multipath_record_t *mpr_req;
1379 1379 sa_path_record_t *pr_resp;
1380 1380 ibmf_saa_access_args_t access_args;
1381 1381 void *results_p;
1382 1382 uint64_t c_mask = 0;
1383 1383 ib_gid_t *gid_ptr, *gid_s_ptr;
1384 1384 size_t length;
1385 1385 int template_len;
1386 1386 uint8_t found, num_rec;
1387 1387 int i, k;
1388 1388 ibt_status_t retval;
1389 1389 uint8_t sgid_cnt, dgid_cnt;
1390 1390 ibt_path_attr_t *attrp = &p_arg->attr;
1391 1391
1392 1392 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec(%p, %p, %p, %d)",
1393 1393 attrp, sl, dinfo, *num_path);
1394 1394
1395 1395 for (i = 0, dgid_cnt = 0; i < dinfo->num_dest; i++) {
1396 1396 if (dinfo->dest[i].d_tag == 0)
1397 1397 dgid_cnt++;
1398 1398 }
1399 1399
1400 1400 sgid_cnt = sl->p_count;
1401 1401
1402 1402 if ((sgid_cnt == 0) || (dgid_cnt == 0)) {
1403 1403 IBTF_DPRINTF_L2(cmlog, "ibcm_get_multi_pathrec: sgid_cnt(%d) or"
1404 1404 " dgid_cnt(%d) is zero", sgid_cnt, dgid_cnt);
1405 1405 return (IBT_INVALID_PARAM);
1406 1406 }
1407 1407
1408 1408 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: Get %d records between "
1409 1409 "%d Src(s) <=> %d Dest(s)", *num_path, sgid_cnt, dgid_cnt);
1410 1410
1411 1411 /*
1412 1412 * Calculate the size for multi-path records template, which includes
1413 1413 * constant portion of the multipath record, plus variable size for
1414 1414 * SGID (sgid_cnt) and DGID (dgid_cnt).
1415 1415 */
1416 1416 template_len = ((dgid_cnt + sgid_cnt) * sizeof (ib_gid_t)) +
1417 1417 sizeof (sa_multipath_record_t);
1418 1418
1419 1419 mpr_req = kmem_zalloc(template_len, KM_SLEEP);
1420 1420
1421 1421 ASSERT(mpr_req != NULL);
1422 1422
1423 1423 gid_ptr = (ib_gid_t *)(((uchar_t *)mpr_req) +
1424 1424 sizeof (sa_multipath_record_t));
1425 1425
1426 1426 /* Get the starting pointer where GIDs are stored. */
1427 1427 gid_s_ptr = gid_ptr;
1428 1428
1429 1429 /* SGID */
1430 1430 for (i = 0; i < sgid_cnt; i++) {
1431 1431 *gid_ptr = sl[i].p_sgid;
1432 1432
1433 1433 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: SGID[%d] = "
1434 1434 "(%llX:%llX)", i, gid_ptr->gid_prefix, gid_ptr->gid_guid);
1435 1435
1436 1436 gid_ptr++;
1437 1437 }
1438 1438
1439 1439 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mpr_req))
1440 1440
1441 1441 mpr_req->SGIDCount = sgid_cnt;
1442 1442 c_mask = SA_MPR_COMPMASK_SGIDCOUNT;
1443 1443
1444 1444 /* DGIDs */
1445 1445 for (i = 0; i < dinfo->num_dest; i++) {
1446 1446 if (dinfo->dest[i].d_tag == 0) {
1447 1447 *gid_ptr = dinfo->dest[i].d_gid;
1448 1448
1449 1449 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: "
1450 1450 "DGID[%d] = (%llX:%llX)", i, gid_ptr->gid_prefix,
1451 1451 gid_ptr->gid_guid);
1452 1452 gid_ptr++;
1453 1453 }
1454 1454 }
1455 1455
1456 1456 mpr_req->DGIDCount = dgid_cnt;
1457 1457 c_mask |= SA_MPR_COMPMASK_DGIDCOUNT;
1458 1458
1459 1459 /* Is Flow Label Specified. */
1460 1460 if (attrp->pa_flow) {
1461 1461 mpr_req->FlowLabel = attrp->pa_flow;
1462 1462 c_mask |= SA_MPR_COMPMASK_FLOWLABEL;
1463 1463 }
1464 1464
1465 1465 /* Is HopLimit Specified. */
1466 1466 if (p_arg->flags & IBT_PATH_HOP) {
1467 1467 mpr_req->HopLimit = attrp->pa_hop;
1468 1468 c_mask |= SA_MPR_COMPMASK_HOPLIMIT;
1469 1469 }
1470 1470
1471 1471 /* Is TClass Specified. */
1472 1472 if (attrp->pa_tclass) {
1473 1473 mpr_req->TClass = attrp->pa_tclass;
1474 1474 c_mask |= SA_MPR_COMPMASK_TCLASS;
1475 1475 }
1476 1476
1477 1477 /* Is SL specified. */
1478 1478 if (attrp->pa_sl) {
1479 1479 mpr_req->SL = attrp->pa_sl;
1480 1480 c_mask |= SA_MPR_COMPMASK_SL;
1481 1481 }
1482 1482
1483 1483 if (p_arg->flags & IBT_PATH_PERF) {
1484 1484 mpr_req->PacketLifeTimeSelector = IBT_BEST;
1485 1485 mpr_req->RateSelector = IBT_BEST;
1486 1486 mpr_req->MtuSelector = IBT_BEST;
1487 1487
1488 1488 c_mask |= SA_MPR_COMPMASK_PKTLTSELECTOR |
1489 1489 SA_MPR_COMPMASK_RATESELECTOR | SA_MPR_COMPMASK_MTUSELECTOR;
1490 1490 } else {
1491 1491 if (attrp->pa_pkt_lt.p_selector == IBT_BEST) {
1492 1492 mpr_req->PacketLifeTimeSelector = IBT_BEST;
1493 1493 c_mask |= SA_MPR_COMPMASK_PKTLTSELECTOR;
1494 1494 }
1495 1495
1496 1496 if (attrp->pa_srate.r_selector == IBT_BEST) {
1497 1497 mpr_req->RateSelector = IBT_BEST;
1498 1498 c_mask |= SA_MPR_COMPMASK_RATESELECTOR;
1499 1499 }
1500 1500
1501 1501 if (attrp->pa_mtu.r_selector == IBT_BEST) {
1502 1502 mpr_req->MtuSelector = IBT_BEST;
1503 1503 c_mask |= SA_MPR_COMPMASK_MTUSELECTOR;
1504 1504 }
1505 1505 }
1506 1506
1507 1507 /*
1508 1508 * Honor individual selection of these attributes,
1509 1509 * even if IBT_PATH_PERF is set.
1510 1510 */
1511 1511 /* Check out whether Packet Life Time is specified. */
1512 1512 if (attrp->pa_pkt_lt.p_pkt_lt) {
1513 1513 mpr_req->PacketLifeTime =
1514 1514 ibt_usec2ib(attrp->pa_pkt_lt.p_pkt_lt);
1515 1515 mpr_req->PacketLifeTimeSelector =
1516 1516 attrp->pa_pkt_lt.p_selector;
1517 1517
1518 1518 c_mask |= SA_MPR_COMPMASK_PKTLT |
1519 1519 SA_MPR_COMPMASK_PKTLTSELECTOR;
1520 1520 }
1521 1521
1522 1522 /* Is SRATE specified. */
1523 1523 if (attrp->pa_srate.r_srate) {
1524 1524 mpr_req->Rate = attrp->pa_srate.r_srate;
1525 1525 mpr_req->RateSelector = attrp->pa_srate.r_selector;
1526 1526
1527 1527 c_mask |= SA_MPR_COMPMASK_RATE |
1528 1528 SA_MPR_COMPMASK_RATESELECTOR;
1529 1529 }
1530 1530
1531 1531 /* Is MTU specified. */
1532 1532 if (attrp->pa_mtu.r_mtu) {
1533 1533 mpr_req->Mtu = attrp->pa_mtu.r_mtu;
1534 1534 mpr_req->MtuSelector = attrp->pa_mtu.r_selector;
1535 1535
1536 1536 c_mask |= SA_MPR_COMPMASK_MTU |
1537 1537 SA_MPR_COMPMASK_MTUSELECTOR;
1538 1538 }
1539 1539
1540 1540 /* Is P_Key Specified or obtained during Service Look-up. */
1541 1541 if (dinfo->p_key) {
1542 1542 mpr_req->P_Key = dinfo->p_key;
1543 1543 c_mask |= SA_MPR_COMPMASK_PKEY;
1544 1544 }
1545 1545
1546 1546 /* We always get REVERSIBLE paths. */
1547 1547 mpr_req->Reversible = 1;
1548 1548 c_mask |= SA_MPR_COMPMASK_REVERSIBLE;
1549 1549
1550 1550 if (p_arg->flags & IBT_PATH_AVAIL) {
1551 1551 mpr_req->IndependenceSelector = 1;
1552 1552 c_mask |= SA_MPR_COMPMASK_INDEPSEL;
1553 1553 }
1554 1554
1555 1555 /* we will not specify how many records we want. */
1556 1556
1557 1557 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*mpr_req))
1558 1558
1559 1559 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: CMask: %llX Pkey: %X",
1560 1560 c_mask, mpr_req->P_Key);
1561 1561
1562 1562 /* Contact SA Access to retrieve Path Records. */
1563 1563 access_args.sq_attr_id = SA_MULTIPATHRECORD_ATTRID;
1564 1564 access_args.sq_access_type = IBMF_SAA_RETRIEVE;
1565 1565 access_args.sq_component_mask = c_mask;
1566 1566 access_args.sq_template = mpr_req;
1567 1567 access_args.sq_template_length = sizeof (sa_multipath_record_t);
1568 1568 access_args.sq_callback = NULL;
1569 1569 access_args.sq_callback_arg = NULL;
1570 1570
1571 1571 retval = ibcm_contact_sa_access(sl->p_saa_hdl, &access_args, &length,
1572 1572 &results_p);
1573 1573 if (retval != IBT_SUCCESS) {
1574 1574 *num_path = 0; /* Update the return count. */
1575 1575 kmem_free(mpr_req, template_len);
1576 1576 return (retval);
1577 1577 }
1578 1578
1579 1579 num_rec = length / sizeof (sa_path_record_t);
1580 1580
1581 1581 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: Found %d Paths",
1582 1582 num_rec);
1583 1583
1584 1584 found = 0;
1585 1585 if ((results_p != NULL) && (num_rec > 0)) {
1586 1586 /* Update the PathInfo with the response Path Records */
1587 1587 pr_resp = (sa_path_record_t *)results_p;
1588 1588
1589 1589 for (i = 0; i < num_rec; i++) {
1590 1590 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: "
1591 1591 "P[%d]: SG %llX, DG %llX", i,
1592 1592 pr_resp[i].SGID.gid_guid, pr_resp[i].DGID.gid_guid);
1593 1593 }
1594 1594
1595 1595 if (p_arg->flags & (IBT_PATH_APM | IBT_PATH_AVAIL)) {
1596 1596 sa_path_record_t *p_resp = NULL, *a_resp = NULL;
1597 1597 sa_path_record_t *p_tmp = NULL, *a_tmp = NULL;
1598 1598 int p_found = 0, a_found = 0;
1599 1599 ib_gid_t p_sg, a_sg, p_dg, a_dg;
1600 1600 int p_tmp_found = 0, a_tmp_found = 0;
1601 1601
1602 1602 p_sg = gid_s_ptr[0];
1603 1603 if (sgid_cnt > 1)
1604 1604 a_sg = gid_s_ptr[1];
1605 1605 else
1606 1606 a_sg = p_sg;
1607 1607
1608 1608 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: "
1609 1609 "REQ: P_SG: %llX, A_SG: %llX",
1610 1610 p_sg.gid_guid, a_sg.gid_guid);
1611 1611
1612 1612 p_dg = gid_s_ptr[sgid_cnt];
1613 1613 if (dgid_cnt > 1)
1614 1614 a_dg = gid_s_ptr[sgid_cnt + 1];
1615 1615 else
1616 1616 a_dg = p_dg;
1617 1617
1618 1618 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: "
1619 1619 "REQ: P_DG: %llX, A_DG: %llX",
1620 1620 p_dg.gid_guid, a_dg.gid_guid);
1621 1621
1622 1622 /*
1623 1623 * If SGID and/or DGID is specified by user, make sure
1624 1624 * he gets his primary-path on those node points.
1625 1625 */
1626 1626 for (i = 0; i < num_rec; i++, pr_resp++) {
1627 1627 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec:"
1628 1628 " PF %d, AF %d,\n\t\t P[%d] = SG: %llX, "
1629 1629 "DG: %llX", p_found, a_found, i,
1630 1630 pr_resp->SGID.gid_guid,
1631 1631 pr_resp->DGID.gid_guid);
1632 1632
1633 1633 if ((!p_found) &&
1634 1634 (p_dg.gid_guid == pr_resp->DGID.gid_guid)) {
1635 1635 IBTF_DPRINTF_L3(cmlog,
1636 1636 "ibcm_get_multi_pathrec: "
1637 1637 "Pri DGID Match.. ");
1638 1638 if (p_sg.gid_guid ==
1639 1639 pr_resp->SGID.gid_guid) {
1640 1640 p_found = 1;
1641 1641 p_resp = pr_resp;
1642 1642 IBTF_DPRINTF_L3(cmlog,
1643 1643 "ibcm_get_multi_pathrec: "
1644 1644 "Primary Path Found");
1645 1645
1646 1646 if (a_found)
1647 1647 break;
1648 1648 else
1649 1649 continue;
1650 1650 } else if ((!p_tmp_found) &&
1651 1651 (a_sg.gid_guid ==
1652 1652 pr_resp->SGID.gid_guid)) {
1653 1653 p_tmp_found = 1;
1654 1654 p_tmp = pr_resp;
1655 1655 IBTF_DPRINTF_L3(cmlog,
1656 1656 "ibcm_get_multi_pathrec: "
1657 1657 "Tmp Pri Path Found");
1658 1658 }
1659 1659 IBTF_DPRINTF_L3(cmlog,
1660 1660 "ibcm_get_multi_pathrec:"
1661 1661 "Pri SGID Don't Match.. ");
1662 1662 }
1663 1663
1664 1664 if ((!a_found) &&
1665 1665 (a_dg.gid_guid == pr_resp->DGID.gid_guid)) {
1666 1666 IBTF_DPRINTF_L3(cmlog,
1667 1667 "ibcm_get_multi_pathrec:"
1668 1668 "Alt DGID Match.. ");
1669 1669 if (a_sg.gid_guid ==
1670 1670 pr_resp->SGID.gid_guid) {
1671 1671 a_found = 1;
1672 1672 a_resp = pr_resp;
1673 1673
1674 1674 IBTF_DPRINTF_L3(cmlog,
1675 1675 "ibcm_get_multi_pathrec:"
1676 1676 "Alternate Path Found ");
1677 1677
1678 1678 if (p_found)
1679 1679 break;
1680 1680 else
1681 1681 continue;
1682 1682 } else if ((!a_tmp_found) &&
1683 1683 (p_sg.gid_guid ==
1684 1684 pr_resp->SGID.gid_guid)) {
1685 1685 a_tmp_found = 1;
1686 1686 a_tmp = pr_resp;
1687 1687
1688 1688 IBTF_DPRINTF_L3(cmlog,
1689 1689 "ibcm_get_multi_pathrec:"
1690 1690 "Tmp Alt Path Found ");
1691 1691 }
1692 1692 IBTF_DPRINTF_L3(cmlog,
1693 1693 "ibcm_get_multi_pathrec:"
1694 1694 "Alt SGID Don't Match.. ");
1695 1695 }
1696 1696 }
1697 1697
1698 1698 if ((p_found == 0) && (a_found == 0) &&
1699 1699 (p_tmp_found == 0) && (a_tmp_found == 0)) {
1700 1700 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec:"
1701 1701 " Path to desired node points NOT "
1702 1702 "Available.");
1703 1703 retval = IBT_PATH_RECORDS_NOT_FOUND;
1704 1704 goto get_mpr_end;
1705 1705 }
1706 1706
1707 1707 if (p_resp == NULL) {
1708 1708 if (a_resp != NULL) {
1709 1709 p_resp = a_resp;
1710 1710 a_resp = NULL;
1711 1711 } else if (p_tmp != NULL) {
1712 1712 p_resp = p_tmp;
1713 1713 p_tmp = NULL;
1714 1714 } else if (a_tmp != NULL) {
1715 1715 p_resp = a_tmp;
1716 1716 a_tmp = NULL;
1717 1717 }
1718 1718 }
1719 1719 if (a_resp == NULL) {
1720 1720 if (a_tmp != NULL) {
1721 1721 a_resp = a_tmp;
1722 1722 a_tmp = NULL;
1723 1723 } else if (p_tmp != NULL) {
1724 1724 a_resp = p_tmp;
1725 1725 p_tmp = NULL;
1726 1726 }
1727 1727 }
1728 1728
1729 1729 /* Fill in Primary Path */
1730 1730 retval = ibcm_update_pri(p_resp, sl, dinfo,
1731 1731 &paths[found]);
1732 1732 if (retval != IBT_SUCCESS)
1733 1733 goto get_mpr_end;
1734 1734
1735 1735 if (p_arg->flags & IBT_PATH_APM) {
1736 1736 /* Fill in Alternate Path */
1737 1737 if (a_resp != NULL) {
1738 1738 /*
1739 1739 * a_resp will point to AltPathInfo
1740 1740 * buffer.
1741 1741 */
1742 1742 retval = ibcm_update_cep_info(a_resp,
1743 1743 sl, NULL,
1744 1744 &paths[found].pi_alt_cep_path);
1745 1745 if (retval != IBT_SUCCESS)
1746 1746 goto get_mpr_end;
1747 1747
1748 1748 /* Update some leftovers */
1749 1749 paths[found].pi_alt_pkt_lt =
1750 1750 a_resp->PacketLifeTime;
1751 1751 } else {
1752 1752 IBTF_DPRINTF_L3(cmlog,
1753 1753 "ibcm_get_multi_pathrec:"
1754 1754 " Alternate Path NOT Available.");
1755 1755 retval = IBT_INSUFF_DATA;
1756 1756 }
1757 1757 found++;
1758 1758 } else if (p_arg->flags & IBT_PATH_AVAIL) {
1759 1759 found++;
1760 1760
1761 1761 if (found < *num_path) {
1762 1762
1763 1763 /* Fill in second Path */
1764 1764 if (a_resp != NULL) {
1765 1765 retval = ibcm_update_pri(a_resp,
1766 1766 sl, dinfo, &paths[found]);
1767 1767 if (retval != IBT_SUCCESS)
1768 1768 goto get_mpr_end;
1769 1769 else
1770 1770 found++;
1771 1771 } else {
1772 1772 IBTF_DPRINTF_L3(cmlog,
1773 1773 "ibcm_get_multi_pathrec: "
1774 1774 "SecondPath NOT Available");
1775 1775 retval = IBT_INSUFF_DATA;
1776 1776 }
1777 1777 }
1778 1778 }
1779 1779 } else { /* If NOT APM */
1780 1780 boolean_t check_pkey = B_FALSE;
1781 1781
1782 1782 /* mark flag whether to validate PKey or not. */
1783 1783 if ((dinfo->p_key == 0) && (dinfo->dest[0].d_pkey != 0))
1784 1784 check_pkey = B_TRUE;
1785 1785
1786 1786 for (i = 0; i < num_rec; i++, pr_resp++) {
1787 1787 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec:"
1788 1788 " PKeyCheck - %s, PKey=0x%X, DGID(%llX)",
1789 1789 ((check_pkey == B_TRUE)?"REQD":"NOT_REQD"),
1790 1790 pr_resp->P_Key, pr_resp->DGID.gid_guid);
1791 1791
1792 1792 if (check_pkey) {
1793 1793 boolean_t match_found = B_FALSE;
1794 1794
1795 1795 /* For all DGIDs */
1796 1796 for (k = 0; k < dinfo->num_dest; k++) {
1797 1797 if (dinfo->dest[k].d_tag != 0)
1798 1798 continue;
1799 1799
1800 1800 if ((dinfo->dest[k].d_gid.
1801 1801 gid_guid ==
1802 1802 pr_resp->DGID.gid_guid) &&
1803 1803 (dinfo->dest[k].d_pkey ==
1804 1804 pr_resp->P_Key)) {
1805 1805 match_found = B_TRUE;
1806 1806 break;
1807 1807 }
1808 1808 }
1809 1809 if (!match_found)
1810 1810 continue;
1811 1811 }
1812 1812 /* Fill in Primary Path */
1813 1813 retval = ibcm_update_pri(pr_resp, sl, dinfo,
1814 1814 &paths[found]);
1815 1815 if (retval != IBT_SUCCESS)
1816 1816 continue;
1817 1817
1818 1818 if (++found == *num_path)
1819 1819 break;
1820 1820 }
1821 1821 }
1822 1822 get_mpr_end:
1823 1823 kmem_free(results_p, length);
1824 1824 }
1825 1825 kmem_free(mpr_req, template_len);
1826 1826
1827 1827 if (found == 0)
1828 1828 retval = IBT_PATH_RECORDS_NOT_FOUND;
1829 1829 else if (found != *num_path)
1830 1830 retval = IBT_INSUFF_DATA;
1831 1831 else
1832 1832 retval = IBT_SUCCESS;
1833 1833
1834 1834 IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: Done (status %d). "
1835 1835 "Found %d/%d Paths", retval, found, *num_path);
1836 1836
1837 1837 *num_path = found; /* Update the return count. */
1838 1838
1839 1839 return (retval);
1840 1840 }
1841 1841
1842 1842
1843 1843 /*
1844 1844 * Update the output path records buffer with the values as obtained from
1845 1845 * SA Access retrieve call results for Path Records.
1846 1846 */
1847 1847 static ibt_status_t
1848 1848 ibcm_update_cep_info(sa_path_record_t *prec_resp, ibtl_cm_port_list_t *sl,
1849 1849 ibtl_cm_hca_port_t *hport, ibt_cep_path_t *cep_p)
1850 1850 {
1851 1851 ibt_status_t retval;
1852 1852 int i;
1853 1853
1854 1854 IBCM_DUMP_PATH_REC(prec_resp);
1855 1855
1856 1856 /*
1857 1857 * If path's packet life time is more than 4 seconds, IBCM cannot
1858 1858 * handle this path connection, so discard this path record.
1859 1859 */
1860 1860 if (prec_resp->PacketLifeTime > ibcm_max_ib_pkt_lt) {
1861 1861 IBTF_DPRINTF_L2(cmlog, "ibcm_update_cep_info: Path's Packet "
1862 1862 "LifeTime too high %d, Maximum allowed %d IB Time (4 sec)",
1863 1863 prec_resp->PacketLifeTime, ibcm_max_ib_pkt_lt);
1864 1864 return (ibt_get_module_failure(IBT_FAILURE_IBSM, 0));
1865 1865 }
1866 1866
1867 1867 if ((prec_resp->Mtu > IB_MTU_4K) || (prec_resp->Mtu < IB_MTU_256)) {
1868 1868 IBTF_DPRINTF_L2(cmlog, "ibcm_update_cep_info: MTU (%d) from "
1869 1869 "pathrecord is invalid, reject it.", prec_resp->Mtu);
1870 1870 return (ibt_get_module_failure(IBT_FAILURE_IBSM, 0));
1871 1871 }
1872 1872
1873 1873 /* Source Node Information. */
1874 1874 cep_p->cep_adds_vect.av_sgid = prec_resp->SGID;
1875 1875 if (hport != NULL) {
1876 1876 /* Convert P_Key to P_Key_Index */
1877 1877 retval = ibt_pkey2index_byguid(hport->hp_hca_guid,
1878 1878 hport->hp_port, prec_resp->P_Key, &cep_p->cep_pkey_ix);
1879 1879 if (retval != IBT_SUCCESS) {
1880 1880 /* Failed to get pkey_index from pkey */
1881 1881 IBTF_DPRINTF_L2(cmlog, "ibcm_update_cep_info: "
1882 1882 "Pkey2Index (PKey = %X) conversion failed: %d",
1883 1883 prec_resp->P_Key, retval);
1884 1884 return (ibt_get_module_failure(IBT_FAILURE_IBSM, 0));
1885 1885 }
1886 1886 cep_p->cep_adds_vect.av_sgid_ix = hport->hp_sgid_ix;
1887 1887 cep_p->cep_adds_vect.av_src_path =
1888 1888 prec_resp->SLID - hport->hp_base_lid;
1889 1889 cep_p->cep_adds_vect.av_port_num = cep_p->cep_hca_port_num =
1890 1890 hport->hp_port;
1891 1891 } else if (sl != NULL) {
1892 1892 for (i = 0; i < sl->p_count; i++) {
1893 1893 if (prec_resp->SGID.gid_guid == sl[i].p_sgid.gid_guid) {
1894 1894 /* Convert P_Key to P_Key_Index */
1895 1895 retval = ibt_pkey2index_byguid(sl[i].p_hca_guid,
1896 1896 sl[i].p_port_num, prec_resp->P_Key,
1897 1897 &cep_p->cep_pkey_ix);
1898 1898 if (retval != IBT_SUCCESS) {
1899 1899 /* Failed to get pkey_index from pkey */
1900 1900 IBTF_DPRINTF_L2(cmlog,
1901 1901 "ibcm_update_cep_info: Pkey2Index "
1902 1902 "(PKey = %X) conversion failed: %d",
1903 1903 prec_resp->P_Key, retval);
1904 1904 return (ibt_get_module_failure(
1905 1905 IBT_FAILURE_IBSM, 0));
1906 1906 }
1907 1907
1908 1908 cep_p->cep_adds_vect.av_sgid_ix =
1909 1909 sl[i].p_sgid_ix;
1910 1910 cep_p->cep_adds_vect.av_src_path =
1911 1911 prec_resp->SLID - sl[i].p_base_lid;
1912 1912 cep_p->cep_adds_vect.av_port_num =
1913 1913 sl[i].p_port_num;
1914 1914 cep_p->cep_hca_port_num = sl[i].p_port_num;
1915 1915
1916 1916 break;
1917 1917 }
1918 1918 }
1919 1919 } else {
1920 1920 IBTF_DPRINTF_L2(cmlog, "ibcm_update_cep_info: Sl or Hport "
1921 1921 "must be non-null");
1922 1922 return (IBT_INVALID_PARAM);
1923 1923 }
1924 1924
1925 1925 if (prec_resp->Rate) {
1926 1926 cep_p->cep_adds_vect.av_srate = prec_resp->Rate;
1927 1927 } else {
1928 1928 IBTF_DPRINTF_L2(cmlog, "ibcm_update_cep_info: SRate (%d) from "
1929 1929 "pathrecord is invalid, reject it.", prec_resp->Rate);
1930 1930 return (ibt_get_module_failure(IBT_FAILURE_IBSM, 0));
1931 1931 }
1932 1932 /*
1933 1933 * If both Source and Destination GID prefix are same, then GRH is not
1934 1934 * valid, so make it as false, else set this field as true.
1935 1935 */
1936 1936 if (prec_resp->SGID.gid_prefix == prec_resp->DGID.gid_prefix)
1937 1937 cep_p->cep_adds_vect.av_send_grh = B_FALSE;
1938 1938 else
1939 1939 cep_p->cep_adds_vect.av_send_grh = B_TRUE;
1940 1940
1941 1941 /* SGID and SGID Index. */
1942 1942 cep_p->cep_adds_vect.av_sgid = prec_resp->SGID;
1943 1943 cep_p->cep_adds_vect.av_flow = prec_resp->FlowLabel;
1944 1944 cep_p->cep_adds_vect.av_tclass = prec_resp->TClass;
1945 1945 cep_p->cep_adds_vect.av_hop = prec_resp->HopLimit;
1946 1946
1947 1947 /* Address Vector Definition. */
1948 1948 cep_p->cep_adds_vect.av_dlid = prec_resp->DLID;
1949 1949 cep_p->cep_adds_vect.av_srvl = prec_resp->SL;
1950 1950
1951 1951 /* DGID */
1952 1952 cep_p->cep_adds_vect.av_dgid = prec_resp->DGID;
1953 1953
1954 1954 /* CEP Timeout is NOT filled in by PATH routines. */
1955 1955 cep_p->cep_timeout = 0;
1956 1956
1957 1957 IBTF_DPRINTF_L2(cmlog, "ibcm_update_cep_info: Done. Port=%d, PKey=%X\n"
1958 1958 "SGID=%llX:%llX DGID=%llX:%llX", cep_p->cep_adds_vect.av_port_num,
1959 1959 prec_resp->P_Key,
1960 1960 prec_resp->SGID.gid_prefix, prec_resp->SGID.gid_guid,
1961 1961 prec_resp->DGID.gid_prefix, prec_resp->DGID.gid_guid);
1962 1962
1963 1963 return (IBT_SUCCESS);
1964 1964 }
1965 1965
1966 1966
1967 1967 static void
1968 1968 ibcm_fill_svcinfo(sa_service_record_t *sr_resp, ibcm_dest_t *dest)
1969 1969 {
1970 1970 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*dest))
1971 1971
1972 1972 dest->d_gid = sr_resp->ServiceGID;
1973 1973 dest->d_sid = sr_resp->ServiceID;
1974 1974 ibcm_swizzle_to_srv(sr_resp->ServiceData, &dest->d_sdata);
1975 1975 dest->d_pkey = sr_resp->ServiceP_Key;
1976 1976
1977 1977 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*dest))
1978 1978
1979 1979 IBTF_DPRINTF_L3(cmlog, "ibcm_fill_svcinfo: SID(%llX), GID(%llX:%llX)"
1980 1980 "\n\tSvcPKey 0x%X", dest->d_sid, dest->d_gid.gid_prefix,
1981 1981 dest->d_gid.gid_guid, dest->d_pkey);
1982 1982 }
1983 1983
1984 1984
1985 1985 static ib_gid_t
1986 1986 ibcm_saa_get_agid(ibtl_cm_port_list_t *sl, ib_gid_t *gidp, uint_t ngid)
1987 1987 {
1988 1988 int k, l;
1989 1989 ib_gid_t a_gid;
1990 1990
1991 1991 a_gid.gid_prefix = a_gid.gid_guid = 0;
1992 1992
1993 1993 for (k = 0; k < sl->p_count; k++) {
1994 1994 for (l = 0; l < ngid; l++) {
1995 1995
1996 1996 if (gidp->gid_prefix == sl->p_sgid.gid_prefix) {
1997 1997 a_gid = *gidp;
1998 1998 break;
1999 1999 }
2000 2000 if (a_gid.gid_guid && a_gid.gid_prefix)
2001 2001 break;
2002 2002 gidp++;
2003 2003 }
2004 2004 if (a_gid.gid_guid && a_gid.gid_prefix)
2005 2005 break;
2006 2006 sl++;
2007 2007 }
2008 2008 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_get_agid: AltGID = %llX:%llX",
2009 2009 a_gid.gid_prefix, a_gid.gid_guid);
2010 2010
2011 2011 return (a_gid);
2012 2012 }
2013 2013
2014 2014 /*
2015 2015 * Perform SA Access to retrieve Service Records.
2016 2016 * On Success, returns ServiceID and ServiceGID info in '*dinfo'.
2017 2017 */
2018 2018 static ibt_status_t
2019 2019 ibcm_saa_service_rec(ibcm_path_tqargs_t *p_arg, ibtl_cm_port_list_t *sl,
2020 2020 ibcm_dinfo_t *dinfo)
2021 2021 {
2022 2022 sa_service_record_t svcrec_req;
2023 2023 sa_service_record_t *svcrec_resp;
2024 2024 void *results_p;
2025 2025 uint64_t component_mask = 0;
2026 2026 size_t length;
2027 2027 uint8_t i, j, k, rec_found, s;
2028 2028 ibmf_saa_access_args_t access_args;
2029 2029 ibt_status_t retval;
2030 2030 ibt_path_attr_t *attrp = &p_arg->attr;
2031 2031 uint64_t tmp_sd_flag = attrp->pa_sd_flags;
2032 2032 uint8_t num_req;
2033 2033
2034 2034 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec(%p, %p)", p_arg, sl);
2035 2035
2036 2036 bzero(&svcrec_req, sizeof (svcrec_req));
2037 2037
2038 2038 /* Service Name */
2039 2039 if ((attrp->pa_sname != NULL) && (strlen(attrp->pa_sname) != 0)) {
2040 2040 (void) strncpy((char *)(svcrec_req.ServiceName),
2041 2041 attrp->pa_sname, IB_SVC_NAME_LEN);
2042 2042
2043 2043 component_mask |= SA_SR_COMPMASK_NAME;
2044 2044 }
2045 2045
2046 2046 /* Service ID */
2047 2047 if (attrp->pa_sid) {
2048 2048 svcrec_req.ServiceID = attrp->pa_sid;
2049 2049 component_mask |= SA_SR_COMPMASK_ID;
2050 2050 }
2051 2051
2052 2052 /* Is P_Key Specified. */
2053 2053 if (p_arg->flags & IBT_PATH_PKEY) {
2054 2054 svcrec_req.ServiceP_Key = attrp->pa_pkey;
2055 2055 component_mask |= SA_SR_COMPMASK_PKEY;
2056 2056 }
2057 2057
2058 2058 /* Is ServiceData Specified. */
2059 2059 if (attrp->pa_sd_flags != IBT_NO_SDATA) {
2060 2060 /* Handle endianess for service data. */
2061 2061 ibcm_swizzle_from_srv(&attrp->pa_sdata, svcrec_req.ServiceData);
2062 2062
2063 2063 /*
2064 2064 * Lets not interpret each and every ServiceData flags,
2065 2065 * just pass it on to SAA. Shift the flag, to suit
2066 2066 * SA_SR_COMPMASK_ALL_DATA definition.
2067 2067 */
2068 2068 component_mask |= (tmp_sd_flag << 7);
2069 2069 }
2070 2070
2071 2071 if (dinfo->num_dest == 1) {
2072 2072
2073 2073 /* If a single DGID is specified, provide it */
2074 2074 svcrec_req.ServiceGID = dinfo->dest->d_gid;
2075 2075 component_mask |= SA_SR_COMPMASK_GID;
2076 2076
2077 2077 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec:%llX:%llX",
2078 2078 svcrec_req.ServiceGID.gid_prefix,
2079 2079 svcrec_req.ServiceGID.gid_guid);
2080 2080 }
2081 2081
2082 2082 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: "
2083 2083 "Perform SA Access: Mask: 0x%X", component_mask);
2084 2084
2085 2085 /*
2086 2086 * Call in SA Access retrieve routine to get Service Records.
2087 2087 *
2088 2088 * SA Access framework allocated memory for the "results_p".
2089 2089 * Make sure to deallocate once we are done with the results_p.
2090 2090 * The size of the buffer allocated will be as returned in
2091 2091 * "length" field.
2092 2092 */
2093 2093 access_args.sq_attr_id = SA_SERVICERECORD_ATTRID;
2094 2094 access_args.sq_access_type = IBMF_SAA_RETRIEVE;
2095 2095 access_args.sq_component_mask = component_mask;
2096 2096 access_args.sq_template = &svcrec_req;
2097 2097 access_args.sq_template_length = sizeof (sa_service_record_t);
2098 2098 access_args.sq_callback = NULL;
2099 2099 access_args.sq_callback_arg = NULL;
2100 2100
2101 2101 for (s = 0; s < sl->p_count; s++) {
2102 2102 retval = ibcm_contact_sa_access(sl[s].p_saa_hdl, &access_args,
2103 2103 &length, &results_p);
2104 2104 if (retval != IBT_SUCCESS)
2105 2105 if (sl[s].p_multi & IBTL_CM_MULTI_SM)
2106 2106 continue;
2107 2107 else
2108 2108 return (retval);
2109 2109
2110 2110 if ((results_p == NULL) || (length == 0)) {
2111 2111 IBTF_DPRINTF_L2(cmlog, "ibcm_saa_service_rec: SvcRec "
2112 2112 "Not Found: res_p %p, len %d", results_p, length);
2113 2113 if (sl[s].p_multi & IBTL_CM_MULTI_SM) {
2114 2114 retval = IBT_SERVICE_RECORDS_NOT_FOUND;
2115 2115 continue;
2116 2116 } else
2117 2117 return (IBT_SERVICE_RECORDS_NOT_FOUND);
2118 2118 }
2119 2119
2120 2120 /* if we are here, we got some records. so break. */
2121 2121 break;
2122 2122 }
2123 2123
2124 2124 if (retval != IBT_SUCCESS)
2125 2125 return (retval);
2126 2126
2127 2127 num_req = length / sizeof (sa_service_record_t);
2128 2128
2129 2129 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: Got %d Service Records.",
2130 2130 num_req);
2131 2131
2132 2132 svcrec_resp = (sa_service_record_t *)results_p;
2133 2133 rec_found = 0;
2134 2134
2135 2135 /* Update the return values. */
2136 2136 if (dinfo->num_dest) {
2137 2137 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: Get ServiceRec "
2138 2138 "for Specified DGID: %d", dinfo->num_dest);
2139 2139
2140 2140 for (i = 0; i < num_req; i++, svcrec_resp++) {
2141 2141 /* Limited P_Key is NOT supported as of now!. */
2142 2142 if ((svcrec_resp->ServiceP_Key & 0x8000) == 0) {
2143 2143 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: "
2144 2144 "SvcPkey 0x%X limited, reject the record.",
2145 2145 svcrec_resp->ServiceP_Key);
2146 2146 continue;
2147 2147 }
2148 2148
2149 2149 for (j = 0; j < dinfo->num_dest; j++) {
2150 2150 if (dinfo->dest[j].d_gid.gid_guid ==
2151 2151 svcrec_resp->ServiceGID.gid_guid) {
2152 2152 ibcm_fill_svcinfo(svcrec_resp,
2153 2153 &dinfo->dest[j]);
2154 2154 rec_found++;
2155 2155 }
2156 2156 if (rec_found == dinfo->num_dest)
2157 2157 break;
2158 2158 }
2159 2159 if (rec_found == dinfo->num_dest)
2160 2160 break;
2161 2161 }
2162 2162 if (rec_found != dinfo->num_dest) {
2163 2163 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: Did NOT "
2164 2164 "find ServiceRec for all DGIDs: (%d/%d)", rec_found,
2165 2165 dinfo->num_dest);
2166 2166 retval = IBT_INSUFF_DATA;
2167 2167 }
2168 2168 } else if (p_arg->flags & IBT_PATH_APM) {
2169 2169 ib_gid_t p_gid, a_gid, last_p_gid;
2170 2170 ib_gid_t *gidp = NULL;
2171 2171 uint_t n_gids;
2172 2172 sa_service_record_t *stmp;
2173 2173 boolean_t pri_fill_done = B_FALSE;
2174 2174 boolean_t alt_fill_done = B_FALSE;
2175 2175 ib_pkey_t p_pkey = 0, a_pkey = 0;
2176 2176
2177 2177 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: Need to "
2178 2178 "find ServiceRec that can satisfy APM");
2179 2179
2180 2180 p_gid.gid_prefix = p_gid.gid_guid = 0;
2181 2181 a_gid.gid_prefix = a_gid.gid_guid = 0;
2182 2182 last_p_gid.gid_prefix = last_p_gid.gid_guid = 0;
2183 2183
2184 2184 for (i = 0; i < num_req; i++, svcrec_resp++) {
2185 2185 ibt_status_t ret;
2186 2186 boolean_t is_this_on_local_node = B_FALSE;
2187 2187
2188 2188 /* Limited P_Key is NOT supported as of now!. */
2189 2189 if ((svcrec_resp->ServiceP_Key & 0x8000) == 0) {
2190 2190 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: "
2191 2191 "SvcPkey 0x%X limited, reject the record.",
2192 2192 svcrec_resp->ServiceP_Key);
2193 2193 continue;
2194 2194 }
2195 2195
2196 2196 p_gid = svcrec_resp->ServiceGID;
2197 2197
2198 2198 /* Let's avoid LoopBack Nodes. */
2199 2199 for (j = 0; j < sl->p_count; j++) {
2200 2200 if (p_gid.gid_guid == sl[j].p_sgid.gid_guid) {
2201 2201 is_this_on_local_node = B_TRUE;
2202 2202
2203 2203 IBTF_DPRINTF_L3(cmlog,
2204 2204 "ibcm_saa_service_rec: ServiceGID "
2205 2205 "%llX:%llX is on Local Node, "
2206 2206 "search for remote.",
2207 2207 p_gid.gid_prefix, p_gid.gid_guid);
2208 2208 }
2209 2209 }
2210 2210
2211 2211 if (is_this_on_local_node) {
2212 2212 if ((i + 1) < num_req) {
2213 2213 p_gid.gid_prefix = 0;
2214 2214 p_gid.gid_guid = 0;
2215 2215 continue;
2216 2216 } else if (last_p_gid.gid_prefix != 0) {
2217 2217 p_gid = last_p_gid;
2218 2218 break;
2219 2219 }
2220 2220 }
2221 2221
2222 2222 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: "
2223 2223 "Finally let Primary DGID = %llX:%llX",
2224 2224 p_gid.gid_prefix, p_gid.gid_guid);
2225 2225
2226 2226 ret = ibt_get_companion_port_gids(p_gid, 0, 0,
2227 2227 &gidp, &n_gids);
2228 2228 if (ret == IBT_SUCCESS) {
2229 2229 IBTF_DPRINTF_L3(cmlog,
2230 2230 "ibcm_saa_service_rec: Found %d "
2231 2231 "CompGID for %llX:%llX", n_gids,
2232 2232 p_gid.gid_prefix, p_gid.gid_guid);
2233 2233
2234 2234 stmp = (sa_service_record_t *)results_p;
2235 2235 a_gid.gid_prefix = a_gid.gid_guid = 0;
2236 2236
2237 2237 if (sl->p_multi & IBTL_CM_MULTI_SM) {
2238 2238 /* validate sn_pfx */
2239 2239 a_gid = ibcm_saa_get_agid(sl,
2240 2240 gidp, n_gids);
2241 2241 } else {
2242 2242 for (k = 0; k < num_req; k++) {
2243 2243 ib_gid_t sg = stmp->ServiceGID;
2244 2244
2245 2245 IBTF_DPRINTF_L3(cmlog,
2246 2246 "ibcm_saa_service_rec: "
2247 2247 "SvcGID[%d] = %llX:%llX", k,
2248 2248 sg.gid_prefix, sg.gid_guid);
2249 2249
2250 2250 for (j = 0; j < n_gids; j++) {
2251 2251 if (gidp[j].gid_guid ==
2252 2252 sg.gid_guid) {
2253 2253 a_gid = gidp[j];
2254 2254 break;
2255 2255 }
2256 2256 }
2257 2257 if (a_gid.gid_guid)
2258 2258 break;
2259 2259 stmp++;
2260 2260 }
2261 2261 if (a_gid.gid_guid == 0) {
2262 2262 /* Rec not found for Alt. */
2263 2263 for (j = 0; j < n_gids; j++) {
2264 2264 if (gidp[j].gid_prefix
2265 2265 == p_gid.
2266 2266 gid_prefix) {
2267 2267 a_gid = gidp[j];
2268 2268 break;
2269 2269 }
2270 2270 }
2271 2271 }
2272 2272 }
2273 2273 kmem_free(gidp,
2274 2274 n_gids * sizeof (ib_gid_t));
2275 2275
2276 2276 if (a_gid.gid_guid)
2277 2277 break;
2278 2278 } else if (ret == IBT_GIDS_NOT_FOUND) {
2279 2279 last_p_gid = p_gid;
2280 2280 IBTF_DPRINTF_L3(cmlog,
2281 2281 "ibcm_saa_service_rec: Didn't find "
2282 2282 "CompGID for %llX:%llX, ret=%d",
2283 2283 p_gid.gid_prefix, p_gid.gid_guid,
2284 2284 ret);
2285 2285 } else {
2286 2286 IBTF_DPRINTF_L3(cmlog,
2287 2287 "ibcm_saa_service_rec: Call to "
2288 2288 "ibt_get_companion_port_gids(%llX:"
2289 2289 "%llX) Failed = %d",
2290 2290 p_gid.gid_prefix, p_gid.gid_guid,
2291 2291 ret);
2292 2292 }
2293 2293 }
2294 2294
2295 2295 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: \n\t"
2296 2296 "Pri DGID(%llX:%llX), Alt DGID(%llX:%llX)",
2297 2297 p_gid.gid_prefix, p_gid.gid_guid, a_gid.gid_prefix,
2298 2298 a_gid.gid_guid);
2299 2299
2300 2300 svcrec_resp = (sa_service_record_t *)results_p;
2301 2301
2302 2302 for (i = 0, j = 0; i < num_req; i++, svcrec_resp++) {
2303 2303 /* Limited P_Key is NOT supported as of now!. */
2304 2304 if ((svcrec_resp->ServiceP_Key & 0x8000) == 0) {
2305 2305 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: "
2306 2306 "SvcPkey 0x%X limited, reject the record.",
2307 2307 svcrec_resp->ServiceP_Key);
2308 2308 continue;
2309 2309 }
2310 2310
2311 2311 if ((!pri_fill_done) && (p_gid.gid_guid ==
2312 2312 svcrec_resp->ServiceGID.gid_guid)) {
2313 2313 p_pkey = svcrec_resp->ServiceP_Key;
2314 2314 if ((a_pkey != 0) &&
2315 2315 (a_pkey != p_pkey)) {
2316 2316 IBTF_DPRINTF_L3(cmlog,
2317 2317 "ibcm_saa_service_rec: "
2318 2318 "Pri(0x%X) & Alt (0x%X) "
2319 2319 "PKey must match.",
2320 2320 p_pkey, a_pkey);
2321 2321 p_pkey = 0;
2322 2322 continue;
2323 2323 }
2324 2324 ibcm_fill_svcinfo(svcrec_resp,
2325 2325 &dinfo->dest[j++]);
2326 2326 rec_found++;
2327 2327 pri_fill_done = B_TRUE;
2328 2328 } else if ((!alt_fill_done) && (a_gid.gid_guid ==
2329 2329 svcrec_resp->ServiceGID.gid_guid)) {
2330 2330 a_pkey = svcrec_resp->ServiceP_Key;
2331 2331 if ((p_pkey != 0) &&
2332 2332 (a_pkey != p_pkey)) {
2333 2333 IBTF_DPRINTF_L3(cmlog,
2334 2334 "ibcm_saa_service_rec: "
2335 2335 "Pri(0x%X) & Alt (0x%X) "
2336 2336 "PKey must match.",
2337 2337 p_pkey, a_pkey);
2338 2338 a_pkey = 0;
2339 2339 continue;
2340 2340 }
2341 2341 ibcm_fill_svcinfo(svcrec_resp,
2342 2342 &dinfo->dest[j++]);
2343 2343 rec_found++;
2344 2344 alt_fill_done = B_TRUE;
2345 2345 }
2346 2346
2347 2347 if (rec_found == 2)
2348 2348 break;
2349 2349 }
2350 2350 if ((!alt_fill_done) && (a_gid.gid_guid)) {
2351 2351 dinfo->dest[j].d_gid = a_gid;
2352 2352 dinfo->dest[j].d_pkey = p_pkey;
2353 2353 rec_found++;
2354 2354 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: "
2355 2355 "Let Alt Pkey=%X, DGID=%llX:%llX", p_pkey,
2356 2356 a_gid.gid_prefix, a_gid.gid_guid);
2357 2357 }
2358 2358
2359 2359 if (rec_found == 1)
2360 2360 retval = IBT_INSUFF_DATA;
2361 2361 } else if (p_arg->flags & IBT_PATH_MULTI_SVC_DEST) {
2362 2362 for (i = 0; i < num_req; i++, svcrec_resp++) {
2363 2363 ib_gid_t p_gid;
2364 2364 boolean_t is_this_on_local_node = B_FALSE;
2365 2365
2366 2366 /* Limited P_Key is NOT supported as of now!. */
2367 2367 if ((svcrec_resp->ServiceP_Key & 0x8000) == 0) {
2368 2368 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: "
2369 2369 "SvcPkey 0x%X limited, reject the record.",
2370 2370 svcrec_resp->ServiceP_Key);
2371 2371 continue;
2372 2372 }
2373 2373
2374 2374 p_gid = svcrec_resp->ServiceGID;
2375 2375
2376 2376 /* Let's avoid LoopBack Nodes. */
2377 2377 for (j = 0; j < sl->p_count; j++) {
2378 2378 if (p_gid.gid_guid == sl[j].p_sgid.gid_guid) {
2379 2379 is_this_on_local_node = B_TRUE;
2380 2380 IBTF_DPRINTF_L3(cmlog,
2381 2381 "ibcm_saa_service_rec: ServiceGID "
2382 2382 "%llX:%llX is on Local Node, "
2383 2383 "search for remote.",
2384 2384 p_gid.gid_prefix, p_gid.gid_guid);
2385 2385 }
2386 2386 }
2387 2387
2388 2388 if (is_this_on_local_node)
2389 2389 if ((i + 1) < num_req)
2390 2390 continue;
2391 2391
2392 2392 IBTF_DPRINTF_L4(cmlog, "ibcm_saa_service_rec: "
2393 2393 "Found ServiceGID = %llX:%llX",
2394 2394 p_gid.gid_prefix, p_gid.gid_guid);
2395 2395
2396 2396 ibcm_fill_svcinfo(svcrec_resp,
2397 2397 &dinfo->dest[rec_found]);
2398 2398 rec_found++;
2399 2399 if (rec_found == p_arg->max_paths)
2400 2400 break;
2401 2401 }
2402 2402
2403 2403 if (rec_found < p_arg->max_paths)
2404 2404 retval = IBT_INSUFF_DATA;
2405 2405 } else {
2406 2406 for (i = 0; i < num_req; i++) {
2407 2407 /* Limited P_Key is NOT supported as of now!. */
2408 2408 if ((svcrec_resp->ServiceP_Key & 0x8000) == 0) {
2409 2409 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: "
2410 2410 "SvcPkey 0x%X limited, reject the record.",
2411 2411 svcrec_resp->ServiceP_Key);
2412 2412 svcrec_resp++;
2413 2413 continue;
2414 2414 }
2415 2415
2416 2416 ibcm_fill_svcinfo(svcrec_resp, &dinfo->dest[0]);
2417 2417 rec_found = 1;
2418 2418
2419 2419 /* Avoid having loopback node */
2420 2420 if (svcrec_resp->ServiceGID.gid_guid !=
2421 2421 sl->p_sgid.gid_guid) {
2422 2422 break;
2423 2423 } else {
2424 2424 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: "
2425 2425 "avoid LoopBack node.");
2426 2426 svcrec_resp++;
2427 2427 }
2428 2428 }
2429 2429 }
2430 2430
2431 2431 /* Deallocate the memory for results_p. */
2432 2432 kmem_free(results_p, length);
2433 2433 if (dinfo->num_dest == 0)
2434 2434 dinfo->num_dest = rec_found;
2435 2435
2436 2436 /*
2437 2437 * Check out whether all Service Path we looking for are on the same
2438 2438 * P_key. If yes, then set the global p_key field with that value,
2439 2439 * to make it easy during SA Path Query.
2440 2440 */
2441 2441 if ((dinfo->num_dest) && (dinfo->p_key == 0)) {
2442 2442 ib_pkey_t pk = dinfo->dest[0].d_pkey;
2443 2443
2444 2444 if (dinfo->num_dest == 1) {
2445 2445 dinfo->p_key = pk;
2446 2446 } else {
2447 2447 for (i = 1; i < (dinfo->num_dest - 1); i++) {
2448 2448 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: "
2449 2449 "pk= 0x%X, pk[%d]= 0x%X", pk, i,
2450 2450 dinfo->dest[i].d_pkey);
2451 2451 if (pk != dinfo->dest[i].d_pkey) {
2452 2452 dinfo->p_key = 0;
2453 2453 break;
2454 2454 } else {
2455 2455 dinfo->p_key = pk;
2456 2456 }
2457 2457 }
2458 2458 }
2459 2459 }
2460 2460
2461 2461 if (rec_found == 0) {
2462 2462 IBTF_DPRINTF_L2(cmlog, "ibcm_saa_service_rec: "
2463 2463 "ServiceRec NOT Found");
2464 2464 retval = IBT_SERVICE_RECORDS_NOT_FOUND;
2465 2465 }
2466 2466
2467 2467 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: done. Status %d, "
2468 2468 "PKey 0x%X, Found %d SvcRec", retval, dinfo->p_key, rec_found);
2469 2469
2470 2470 return (retval);
2471 2471 }
2472 2472
2473 2473
2474 2474 static boolean_t
2475 2475 ibcm_compare_paths(sa_path_record_t *pr_resp, ibt_cep_path_t *rc_path,
2476 2476 ibtl_cm_hca_port_t *c_hp)
2477 2477 {
2478 2478 if ((rc_path->cep_hca_port_num == c_hp->hp_port) &&
2479 2479 (rc_path->cep_adds_vect.av_src_path ==
2480 2480 (pr_resp->SLID - c_hp->hp_base_lid)) &&
2481 2481 (rc_path->cep_adds_vect.av_dlid == pr_resp->DLID) &&
2482 2482 (rc_path->cep_adds_vect.av_srate == pr_resp->Rate)) {
2483 2483 return (B_TRUE);
2484 2484 } else {
2485 2485 return (B_FALSE);
2486 2486 }
2487 2487 }
2488 2488
2489 2489 /*
2490 2490 * ibcm_get_comp_pgids() routine gets the companion port for 'gid'.
2491 2491 *
2492 2492 * On success:
2493 2493 * If 'n_gid' is specified, then verify whether 'n_gid' is indeed a
2494 2494 * companion portgid of 'gid'. If matches return success or else error.
2495 2495 *
2496 2496 * If 'n_gid' is NOT specified, then return back SUCCESS along with
2497 2497 * obtained Companion PortGids 'gid_p', where 'num' indicated number
2498 2498 * of companion portgids returned in 'gid_p'.
2499 2499 */
2500 2500
2501 2501 static ibt_status_t
2502 2502 ibcm_get_comp_pgids(ib_gid_t gid, ib_gid_t n_gid, ib_guid_t hca_guid,
2503 2503 ib_gid_t **gid_p, uint_t *num)
2504 2504 {
2505 2505 ibt_status_t ret;
2506 2506 int i;
2507 2507
2508 2508 ret = ibt_get_companion_port_gids(gid, hca_guid, 0, gid_p, num);
2509 2509 if ((ret != IBT_SUCCESS) && (ret != IBT_GIDS_NOT_FOUND)) {
2510 2510 IBTF_DPRINTF_L2(cmlog, "ibcm_get_comp_pgids: "
2511 2511 "ibt_get_companion_port_gids(%llX:%llX) Failed: %d",
2512 2512 gid.gid_prefix, gid.gid_guid, ret);
2513 2513 } else if ((ret == IBT_GIDS_NOT_FOUND) && (n_gid.gid_guid != 0)) {
2514 2514 IBTF_DPRINTF_L2(cmlog, "ibcm_get_comp_pgids: Specified GID "
2515 2515 "(%llX:%llX) is NOT a Companion \n\t to current channel's "
2516 2516 "GID(%llX:%llX)", n_gid.gid_prefix, n_gid.gid_guid,
2517 2517 gid.gid_prefix, gid.gid_guid);
2518 2518 ret = IBT_INVALID_PARAM;
2519 2519 } else if (n_gid.gid_guid != 0) {
2520 2520 /*
2521 2521 * We found some Comp GIDs and n_gid is specified. Validate
2522 2522 * whether the 'n_gid' specified is indeed the companion port
2523 2523 * GID of 'gid'.
2524 2524 */
2525 2525 for (i = 0; i < *num; i++) {
2526 2526 if ((n_gid.gid_prefix == gid_p[i]->gid_prefix) &&
2527 2527 (n_gid.gid_guid == gid_p[i]->gid_guid)) {
2528 2528 IBTF_DPRINTF_L3(cmlog, "ibcm_get_comp_pgids: "
2529 2529 "Matching Found!. Done.");
2530 2530 return (IBT_SUCCESS);
2531 2531 }
2532 2532 }
2533 2533 IBTF_DPRINTF_L2(cmlog, "ibcm_get_comp_pgids: GID (%llX:%llX)\n"
2534 2534 "\t and (%llX:%llX) are NOT Companion Port GIDS",
2535 2535 n_gid.gid_prefix, n_gid.gid_guid, gid.gid_prefix,
2536 2536 gid.gid_guid);
2537 2537 ret = IBT_INVALID_PARAM;
2538 2538 } else {
2539 2539 ret = IBT_SUCCESS;
2540 2540 }
2541 2541
2542 2542 IBTF_DPRINTF_L3(cmlog, "ibcm_get_comp_pgids: done. Status = %d", ret);
2543 2543 return (ret);
2544 2544 }
2545 2545
2546 2546 /*
2547 2547 * Function:
2548 2548 * ibt_get_alt_path
2549 2549 * Input:
2550 2550 * rc_chan An RC channel handle returned in a previous call
2551 2551 * ibt_alloc_rc_channel(9F), specifies the channel to open.
2552 2552 * flags Path flags.
2553 2553 * attrp A pointer to an ibt_alt_path_attr_t(9S) structure that
2554 2554 * specifies required attributes of the selected path(s).
2555 2555 * Output:
2556 2556 * api_p An ibt_alt_path_info_t(9S) struct filled in as output
2557 2557 * parameters.
2558 2558 * Returns:
2559 2559 * IBT_SUCCESS on Success else appropriate error.
2560 2560 * Description:
2561 2561 * Finds the best alternate path to a specified channel (as determined by
2562 2562 * the IBTL) that satisfies the requirements specified in an
2563 2563 * ibt_alt_path_attr_t struct. The specified channel must have been
2564 2564 * previously opened successfully using ibt_open_rc_channel.
2565 2565 * This function also ensures that the service being accessed by the
2566 2566 * channel is available at the selected alternate port.
2567 2567 *
2568 2568 * Note: The apa_dgid must be on the same destination channel adapter,
2569 2569 * if specified.
2570 2570 * This routine can not be called from interrupt context.
2571 2571 */
2572 2572 ibt_status_t
2573 2573 ibt_get_alt_path(ibt_channel_hdl_t rc_chan, ibt_path_flags_t flags,
2574 2574 ibt_alt_path_attr_t *attrp, ibt_alt_path_info_t *api_p)
2575 2575 {
2576 2576 sa_multipath_record_t *mpr_req;
2577 2577 sa_path_record_t *pr_resp;
2578 2578 ibmf_saa_access_args_t access_args;
2579 2579 ibt_qp_query_attr_t qp_attr;
2580 2580 ibtl_cm_hca_port_t c_hp, n_hp;
2581 2581 ibcm_hca_info_t *hcap;
2582 2582 void *results_p;
2583 2583 uint64_t c_mask = 0;
2584 2584 ib_gid_t *gid_ptr = NULL;
2585 2585 ib_gid_t *sgids_p = NULL, *dgids_p = NULL;
2586 2586 ib_gid_t cur_dgid, cur_sgid;
2587 2587 ib_gid_t new_dgid, new_sgid;
2588 2588 ibmf_saa_handle_t saa_handle;
2589 2589 size_t length;
2590 2590 int i, j, template_len, rec_found;
2591 2591 uint_t snum = 0, dnum = 0, num_rec;
2592 2592 ibt_status_t retval;
2593 2593 ib_mtu_t prim_mtu;
2594 2594
2595 2595 IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path(%p, %x, %p, %p)",
2596 2596 rc_chan, flags, attrp, api_p);
2597 2597
2598 2598 /* validate channel */
2599 2599 if (IBCM_INVALID_CHANNEL(rc_chan)) {
2600 2600 IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: invalid channel");
2601 2601 return (IBT_CHAN_HDL_INVALID);
2602 2602 }
2603 2603
2604 2604 if (api_p == NULL) {
2605 2605 IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: invalid attribute: "
2606 2606 " AltPathInfo can't be NULL");
2607 2607 return (IBT_INVALID_PARAM);
2608 2608 }
2609 2609
2610 2610 retval = ibt_query_qp(rc_chan, &qp_attr);
2611 2611 if (retval != IBT_SUCCESS) {
2612 2612 IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: ibt_query_qp(%p) "
2613 2613 "failed %d", rc_chan, retval);
2614 2614 return (retval);
2615 2615 }
2616 2616
2617 2617 if (qp_attr.qp_info.qp_trans != IBT_RC_SRV) {
2618 2618 IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: "
2619 2619 "Invalid Channel type: Applicable only to RC Channel");
2620 2620 return (IBT_CHAN_SRV_TYPE_INVALID);
2621 2621 }
2622 2622
2623 2623 cur_dgid =
2624 2624 qp_attr.qp_info.qp_transport.rc.rc_path.cep_adds_vect.av_dgid;
2625 2625 cur_sgid =
2626 2626 qp_attr.qp_info.qp_transport.rc.rc_path.cep_adds_vect.av_sgid;
2627 2627 prim_mtu = qp_attr.qp_info.qp_transport.rc.rc_path_mtu;
2628 2628
2629 2629 /* If optional attributes are specified, validate them. */
2630 2630 if (attrp) {
2631 2631 new_dgid = attrp->apa_dgid;
2632 2632 new_sgid = attrp->apa_sgid;
2633 2633 } else {
2634 2634 new_dgid.gid_prefix = 0;
2635 2635 new_dgid.gid_guid = 0;
2636 2636 new_sgid.gid_prefix = 0;
2637 2637 new_sgid.gid_guid = 0;
2638 2638 }
2639 2639
2640 2640 if ((new_dgid.gid_prefix != 0) && (new_sgid.gid_prefix != 0) &&
2641 2641 (new_dgid.gid_prefix != new_sgid.gid_prefix)) {
2642 2642 IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: Specified SGID's "
2643 2643 "SNprefix (%llX) doesn't match with \n specified DGID's "
2644 2644 "SNprefix: %llX", new_sgid.gid_prefix, new_dgid.gid_prefix);
2645 2645 return (IBT_INVALID_PARAM);
2646 2646 }
2647 2647
2648 2648 /* For the specified SGID, get HCA information. */
2649 2649 retval = ibtl_cm_get_hca_port(cur_sgid, 0, &c_hp);
2650 2650 if (retval != IBT_SUCCESS) {
2651 2651 IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: "
2652 2652 "Get HCA Port Failed: %d", retval);
2653 2653 return (retval);
2654 2654 }
2655 2655
2656 2656 hcap = ibcm_find_hca_entry(c_hp.hp_hca_guid);
2657 2657 if (hcap == NULL) {
2658 2658 IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: NO HCA found");
2659 2659 return (IBT_HCA_BUSY_DETACHING);
2660 2660 }
2661 2661
2662 2662 /* Validate whether this HCA support APM */
2663 2663 if (!(hcap->hca_caps & IBT_HCA_AUTO_PATH_MIG)) {
2664 2664 IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: "
2665 2665 "HCA (%llX) - APM NOT SUPPORTED ", c_hp.hp_hca_guid);
2666 2666 retval = IBT_APM_NOT_SUPPORTED;
2667 2667 goto get_alt_path_done;
2668 2668 }
2669 2669
2670 2670 /* Get Companion Port GID of the current Channel's SGID */
2671 2671 if ((new_sgid.gid_guid == 0) || ((new_sgid.gid_guid != 0) &&
2672 2672 (new_sgid.gid_guid != cur_sgid.gid_guid))) {
2673 2673 IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path: SRC: "
2674 2674 "Get Companion PortGids for - %llX:%llX",
2675 2675 cur_sgid.gid_prefix, cur_sgid.gid_guid);
2676 2676
2677 2677 retval = ibcm_get_comp_pgids(cur_sgid, new_sgid,
2678 2678 c_hp.hp_hca_guid, &sgids_p, &snum);
2679 2679 if (retval != IBT_SUCCESS)
2680 2680 goto get_alt_path_done;
2681 2681 }
2682 2682
2683 2683 /* Get Companion Port GID of the current Channel's DGID */
2684 2684 if ((new_dgid.gid_guid == 0) || ((new_dgid.gid_guid != 0) &&
2685 2685 (new_dgid.gid_guid != cur_dgid.gid_guid))) {
2686 2686
2687 2687 IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path: DEST: "
2688 2688 "Get Companion PortGids for - %llX:%llX",
2689 2689 cur_dgid.gid_prefix, cur_dgid.gid_guid);
2690 2690
2691 2691 retval = ibcm_get_comp_pgids(cur_dgid, new_dgid, 0, &dgids_p,
2692 2692 &dnum);
2693 2693 if (retval != IBT_SUCCESS)
2694 2694 goto get_alt_path_done;
2695 2695 }
2696 2696
2697 2697 if ((new_dgid.gid_guid == 0) || (new_sgid.gid_guid == 0)) {
2698 2698 if (new_sgid.gid_guid == 0) {
2699 2699 for (i = 0; i < snum; i++) {
2700 2700 if (new_dgid.gid_guid == 0) {
2701 2701 for (j = 0; j < dnum; j++) {
2702 2702 if (sgids_p[i].gid_prefix ==
2703 2703 dgids_p[j].gid_prefix) {
2704 2704 new_dgid = dgids_p[j];
2705 2705 new_sgid = sgids_p[i];
2706 2706
2707 2707 goto get_alt_proceed;
2708 2708 }
2709 2709 }
2710 2710 /* Current DGID */
2711 2711 if (sgids_p[i].gid_prefix ==
2712 2712 cur_dgid.gid_prefix) {
2713 2713 new_sgid = sgids_p[i];
2714 2714 goto get_alt_proceed;
2715 2715 }
2716 2716 } else {
2717 2717 if (sgids_p[i].gid_prefix ==
2718 2718 new_dgid.gid_prefix) {
2719 2719 new_sgid = sgids_p[i];
2720 2720 goto get_alt_proceed;
2721 2721 }
2722 2722 }
2723 2723 }
2724 2724 /* Current SGID */
2725 2725 if (new_dgid.gid_guid == 0) {
2726 2726 for (j = 0; j < dnum; j++) {
2727 2727 if (cur_sgid.gid_prefix ==
2728 2728 dgids_p[j].gid_prefix) {
2729 2729 new_dgid = dgids_p[j];
2730 2730
2731 2731 goto get_alt_proceed;
2732 2732 }
2733 2733 }
2734 2734 }
2735 2735 } else if (new_dgid.gid_guid == 0) {
2736 2736 for (i = 0; i < dnum; i++) {
2737 2737 if (dgids_p[i].gid_prefix ==
2738 2738 new_sgid.gid_prefix) {
2739 2739 new_dgid = dgids_p[i];
2740 2740 goto get_alt_proceed;
2741 2741 }
2742 2742 }
2743 2743 /* Current DGID */
2744 2744 if (cur_dgid.gid_prefix == new_sgid.gid_prefix) {
2745 2745 goto get_alt_proceed;
2746 2746 }
2747 2747 }
2748 2748 /*
2749 2749 * hmm... No Companion Ports available.
2750 2750 * so we will be using current or specified attributes only.
2751 2751 */
2752 2752 }
2753 2753
2754 2754 get_alt_proceed:
2755 2755
2756 2756 if (new_sgid.gid_guid != 0) {
2757 2757 retval = ibtl_cm_get_hca_port(new_sgid, 0, &n_hp);
2758 2758 if (retval != IBT_SUCCESS) {
2759 2759 IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: "
2760 2760 "Get HCA Port Failed: %d", retval);
2761 2761 goto get_alt_path_done;
2762 2762 }
2763 2763 }
2764 2764
2765 2765 /* Calculate the size for multi-path records template */
2766 2766 template_len = (2 * sizeof (ib_gid_t)) + sizeof (sa_multipath_record_t);
2767 2767
2768 2768 mpr_req = kmem_zalloc(template_len, KM_SLEEP);
2769 2769
2770 2770 ASSERT(mpr_req != NULL);
2771 2771
2772 2772 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mpr_req))
2773 2773
2774 2774 gid_ptr = (ib_gid_t *)(((uchar_t *)mpr_req) +
2775 2775 sizeof (sa_multipath_record_t));
2776 2776
2777 2777 /* SGID */
2778 2778 if (new_sgid.gid_guid == 0)
2779 2779 *gid_ptr = cur_sgid;
2780 2780 else
2781 2781 *gid_ptr = new_sgid;
2782 2782
2783 2783 IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path: Get Path Between "
2784 2784 " SGID : %llX:%llX", gid_ptr->gid_prefix, gid_ptr->gid_guid);
2785 2785
2786 2786 gid_ptr++;
2787 2787
2788 2788 /* DGID */
2789 2789 if (new_dgid.gid_guid == 0)
2790 2790 *gid_ptr = cur_dgid;
2791 2791 else
2792 2792 *gid_ptr = new_dgid;
2793 2793
2794 2794 IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path:\t\t DGID : %llX:%llX",
2795 2795 gid_ptr->gid_prefix, gid_ptr->gid_guid);
2796 2796
2797 2797 mpr_req->SGIDCount = 1;
2798 2798 c_mask = SA_MPR_COMPMASK_SGIDCOUNT;
2799 2799
2800 2800 mpr_req->DGIDCount = 1;
2801 2801 c_mask |= SA_MPR_COMPMASK_DGIDCOUNT;
2802 2802
2803 2803 /* Is Flow Label Specified. */
2804 2804 if (attrp) {
2805 2805 if (attrp->apa_flow) {
2806 2806 mpr_req->FlowLabel = attrp->apa_flow;
2807 2807 c_mask |= SA_MPR_COMPMASK_FLOWLABEL;
2808 2808 }
2809 2809
2810 2810 /* Is HopLimit Specified. */
2811 2811 if (flags & IBT_PATH_HOP) {
2812 2812 mpr_req->HopLimit = attrp->apa_hop;
2813 2813 c_mask |= SA_MPR_COMPMASK_HOPLIMIT;
2814 2814 }
2815 2815
2816 2816 /* Is TClass Specified. */
2817 2817 if (attrp->apa_tclass) {
2818 2818 mpr_req->TClass = attrp->apa_tclass;
2819 2819 c_mask |= SA_MPR_COMPMASK_TCLASS;
2820 2820 }
2821 2821
2822 2822 /* Is SL specified. */
2823 2823 if (attrp->apa_sl) {
2824 2824 mpr_req->SL = attrp->apa_sl;
2825 2825 c_mask |= SA_MPR_COMPMASK_SL;
2826 2826 }
2827 2827
2828 2828 if (flags & IBT_PATH_PERF) {
2829 2829 mpr_req->PacketLifeTimeSelector = IBT_BEST;
2830 2830 mpr_req->RateSelector = IBT_BEST;
2831 2831
2832 2832 c_mask |= SA_MPR_COMPMASK_PKTLTSELECTOR |
2833 2833 SA_MPR_COMPMASK_RATESELECTOR;
2834 2834 } else {
2835 2835 if (attrp->apa_pkt_lt.p_selector == IBT_BEST) {
2836 2836 mpr_req->PacketLifeTimeSelector = IBT_BEST;
2837 2837 c_mask |= SA_MPR_COMPMASK_PKTLTSELECTOR;
2838 2838 }
2839 2839
2840 2840 if (attrp->apa_srate.r_selector == IBT_BEST) {
2841 2841 mpr_req->RateSelector = IBT_BEST;
2842 2842 c_mask |= SA_MPR_COMPMASK_RATESELECTOR;
2843 2843 }
2844 2844 }
2845 2845
2846 2846 /*
2847 2847 * Honor individual selection of these attributes,
2848 2848 * even if IBT_PATH_PERF is set.
2849 2849 */
2850 2850 /* Check out whether Packet Life Time is specified. */
2851 2851 if (attrp->apa_pkt_lt.p_pkt_lt) {
2852 2852 mpr_req->PacketLifeTime =
2853 2853 ibt_usec2ib(attrp->apa_pkt_lt.p_pkt_lt);
2854 2854 mpr_req->PacketLifeTimeSelector =
2855 2855 attrp->apa_pkt_lt.p_selector;
2856 2856
2857 2857 c_mask |= SA_MPR_COMPMASK_PKTLT |
2858 2858 SA_MPR_COMPMASK_PKTLTSELECTOR;
2859 2859 }
2860 2860
2861 2861 /* Is SRATE specified. */
2862 2862 if (attrp->apa_srate.r_srate) {
2863 2863 mpr_req->Rate = attrp->apa_srate.r_srate;
2864 2864 mpr_req->RateSelector = attrp->apa_srate.r_selector;
2865 2865
2866 2866 c_mask |= SA_MPR_COMPMASK_RATE |
2867 2867 SA_MPR_COMPMASK_RATESELECTOR;
2868 2868 }
2869 2869 }
2870 2870
2871 2871 /* Alt PathMTU can be GT or EQU to current channel's Pri PathMTU */
2872 2872
2873 2873 /* P_Key must be same as that of primary path */
2874 2874 retval = ibt_index2pkey_byguid(c_hp.hp_hca_guid, c_hp.hp_port,
2875 2875 qp_attr.qp_info.qp_transport.rc.rc_path.cep_pkey_ix,
2876 2876 &mpr_req->P_Key);
2877 2877 if (retval != IBT_SUCCESS) {
2878 2878 IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: Idx2Pkey Failed: %d",
2879 2879 retval);
2880 2880 goto get_alt_path_done;
2881 2881 }
2882 2882 c_mask |= SA_MPR_COMPMASK_PKEY;
2883 2883
2884 2884 mpr_req->Reversible = 1; /* We always get REVERSIBLE paths. */
2885 2885 mpr_req->IndependenceSelector = 1;
2886 2886 c_mask |= SA_MPR_COMPMASK_REVERSIBLE | SA_MPR_COMPMASK_INDEPSEL;
2887 2887
2888 2888 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*mpr_req))
2889 2889
2890 2890 IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path: CMask: 0x%llX", c_mask);
2891 2891
2892 2892 /* NOTE: We will **NOT** specify how many records we want. */
2893 2893
2894 2894 IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path: Primary: MTU %d, PKey[%d]="
2895 2895 "0x%X\n\tSGID = %llX:%llX, DGID = %llX:%llX", prim_mtu,
2896 2896 qp_attr.qp_info.qp_transport.rc.rc_path.cep_pkey_ix, mpr_req->P_Key,
2897 2897 cur_sgid.gid_prefix, cur_sgid.gid_guid, cur_dgid.gid_prefix,
2898 2898 cur_dgid.gid_guid);
2899 2899
2900 2900 /* Get SA Access Handle. */
2901 2901 if (new_sgid.gid_guid != 0)
2902 2902 saa_handle = ibcm_get_saa_handle(hcap, n_hp.hp_port);
2903 2903 else
2904 2904 saa_handle = ibcm_get_saa_handle(hcap, c_hp.hp_port);
2905 2905 if (saa_handle == NULL) {
2906 2906 retval = IBT_HCA_PORT_NOT_ACTIVE;
2907 2907 goto get_alt_path_done;
2908 2908 }
2909 2909
2910 2910 /* Contact SA Access to retrieve Path Records. */
2911 2911 access_args.sq_attr_id = SA_MULTIPATHRECORD_ATTRID;
2912 2912 access_args.sq_access_type = IBMF_SAA_RETRIEVE;
2913 2913 access_args.sq_component_mask = c_mask;
2914 2914 access_args.sq_template = mpr_req;
2915 2915 access_args.sq_template_length = sizeof (sa_multipath_record_t);
2916 2916 access_args.sq_callback = NULL;
2917 2917 access_args.sq_callback_arg = NULL;
2918 2918
2919 2919 retval = ibcm_contact_sa_access(saa_handle, &access_args, &length,
2920 2920 &results_p);
2921 2921 if (retval != IBT_SUCCESS) {
2922 2922 goto get_alt_path_done;
2923 2923 }
2924 2924
2925 2925 num_rec = length / sizeof (sa_path_record_t);
2926 2926
2927 2927 kmem_free(mpr_req, template_len);
2928 2928
2929 2929 IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path: Found %d Paths", num_rec);
2930 2930
2931 2931 rec_found = 0;
2932 2932 if ((results_p != NULL) && (num_rec > 0)) {
2933 2933 /* Update the PathInfo with the response Path Records */
2934 2934 pr_resp = (sa_path_record_t *)results_p;
2935 2935 for (i = 0; i < num_rec; i++, pr_resp++) {
2936 2936 if (prim_mtu > pr_resp->Mtu) {
2937 2937 IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: "
2938 2938 "Alt PathMTU(%d) must be GT or EQU to Pri "
2939 2939 "PathMTU(%d). Ignore this rec",
2940 2940 pr_resp->Mtu, prim_mtu);
2941 2941 continue;
2942 2942 }
2943 2943
2944 2944 if ((new_sgid.gid_guid == 0) &&
2945 2945 (new_dgid.gid_guid == 0)) {
2946 2946 /* Reject PathRec if it same as Primary Path. */
2947 2947 if (ibcm_compare_paths(pr_resp,
2948 2948 &qp_attr.qp_info.qp_transport.rc.rc_path,
2949 2949 &c_hp)) {
2950 2950 IBTF_DPRINTF_L3(cmlog,
2951 2951 "ibt_get_alt_path: PathRec obtained"
2952 2952 " is similar to Prim Path, ignore "
2953 2953 "this record");
2954 2954 continue;
2955 2955 }
2956 2956 }
2957 2957
2958 2958 if (new_sgid.gid_guid == 0) {
2959 2959 retval = ibcm_update_cep_info(pr_resp, NULL,
2960 2960 &c_hp, &api_p->ap_alt_cep_path);
2961 2961 } else {
2962 2962 retval = ibcm_update_cep_info(pr_resp, NULL,
2963 2963 &n_hp, &api_p->ap_alt_cep_path);
2964 2964 }
2965 2965 if (retval != IBT_SUCCESS)
2966 2966 continue;
2967 2967
2968 2968 /* Update some leftovers */
2969 2969 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*api_p))
2970 2970
2971 2971 api_p->ap_alt_pkt_lt = pr_resp->PacketLifeTime;
2972 2972
2973 2973 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*api_p))
2974 2974
2975 2975 rec_found = 1;
2976 2976 break;
2977 2977 }
2978 2978 kmem_free(results_p, length);
2979 2979 }
2980 2980
2981 2981 if (rec_found == 0) {
2982 2982 IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path: Alternate Path cannot"
2983 2983 " be established");
2984 2984 retval = IBT_PATH_RECORDS_NOT_FOUND;
2985 2985 } else
2986 2986 retval = IBT_SUCCESS;
2987 2987
2988 2988 get_alt_path_done:
2989 2989 if ((snum) && (sgids_p))
2990 2990 kmem_free(sgids_p, snum * sizeof (ib_gid_t));
2991 2991
2992 2992 if ((dnum) && (dgids_p))
2993 2993 kmem_free(dgids_p, dnum * sizeof (ib_gid_t));
2994 2994
2995 2995 ibcm_dec_hca_acc_cnt(hcap);
2996 2996
2997 2997 IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path: Done (status %d).", retval);
2998 2998
2999 2999 return (retval);
3000 3000 }
3001 3001
3002 3002
3003 3003
3004 3004 /*
3005 3005 * IP Path API
3006 3006 */
3007 3007
3008 3008 typedef struct ibcm_ip_path_tqargs_s {
3009 3009 ibt_ip_path_attr_t attr;
3010 3010 ibt_path_info_t *paths;
3011 3011 ibt_path_ip_src_t *src_ip_p;
3012 3012 uint8_t *num_paths_p;
3013 3013 ibt_ip_path_handler_t func;
3014 3014 void *arg;
3015 3015 ibt_path_flags_t flags;
3016 3016 ibt_clnt_hdl_t ibt_hdl;
3017 3017 kmutex_t ip_lock;
3018 3018 kcondvar_t ip_cv;
3019 3019 boolean_t ip_done;
3020 3020 ibt_status_t retval;
3021 3021 uint_t len;
3022 3022 } ibcm_ip_path_tqargs_t;
3023 3023
3024 3024 /* Holds destination information needed to fill in ibt_path_info_t. */
3025 3025 typedef struct ibcm_ip_dinfo_s {
3026 3026 uint8_t num_dest;
3027 3027 ib_gid_t d_gid[1];
3028 3028 } ibcm_ip_dinfo_t;
3029 3029
3030 3030 _NOTE(SCHEME_PROTECTS_DATA("Temporary path storage", ibcm_ip_dinfo_s))
3031 3031
3032 3032 /* Prototype Declarations. */
3033 3033 static void ibcm_process_get_ip_paths(void *tq_arg);
3034 3034 static ibt_status_t ibcm_get_ip_spr(ibcm_ip_path_tqargs_t *,
3035 3035 ibtl_cm_port_list_t *, ibcm_ip_dinfo_t *, uint8_t *, ibt_path_info_t *);
3036 3036 static ibt_status_t ibcm_get_ip_mpr(ibcm_ip_path_tqargs_t *,
3037 3037 ibtl_cm_port_list_t *, ibcm_ip_dinfo_t *dinfo,
3038 3038 uint8_t *, ibt_path_info_t *);
3039 3039
3040 3040 /*
3041 3041 * Perform SA Access to retrieve Path Records.
3042 3042 */
3043 3043 static ibt_status_t
3044 3044 ibcm_saa_ip_pr(ibcm_ip_path_tqargs_t *p_arg, ibtl_cm_port_list_t *sl,
3045 3045 ibcm_ip_dinfo_t *dinfo, uint8_t *max_count)
3046 3046 {
3047 3047 uint8_t num_path = *max_count;
3048 3048 uint8_t rec_found = 0;
3049 3049 ibt_status_t retval = IBT_SUCCESS;
3050 3050 uint8_t i, j;
3051 3051
3052 3052 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_ip_pr(%p, %p, %p, 0x%X, %d)",
3053 3053 p_arg, sl, dinfo, p_arg->flags, *max_count);
3054 3054
3055 3055 if ((dinfo->num_dest == 0) || (num_path == 0) || (sl == NULL)) {
3056 3056 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_ip_pr: Invalid Counters");
3057 3057 return (IBT_INVALID_PARAM);
3058 3058 }
3059 3059
3060 3060 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_ip_pr: MultiSM=%X, #SRC=%d, "
3061 3061 "#Dest=%d, #Path %d", sl->p_multi, sl->p_count, dinfo->num_dest,
3062 3062 num_path);
3063 3063
3064 3064 if ((sl->p_multi != IBTL_CM_SIMPLE_SETUP) ||
3065 3065 ((dinfo->num_dest == 1) && (sl->p_count == 1))) {
3066 3066 /*
3067 3067 * Use SinglePathRec if we are dealing w/ MultiSM or
3068 3068 * request is for one SGID to one DGID.
3069 3069 */
3070 3070 retval = ibcm_get_ip_spr(p_arg, sl, dinfo,
3071 3071 &num_path, &p_arg->paths[rec_found]);
3072 3072 } else {
3073 3073 /* MultiPathRec will be used for other queries. */
3074 3074 retval = ibcm_get_ip_mpr(p_arg, sl, dinfo,
3075 3075 &num_path, &p_arg->paths[rec_found]);
3076 3076 }
3077 3077 if ((retval != IBT_SUCCESS) && (retval != IBT_INSUFF_DATA))
3078 3078 IBTF_DPRINTF_L2(cmlog, "ibcm_saa_ip_pr: "
3079 3079 "Failed to get PathRec: Status %d", retval);
3080 3080 else
3081 3081 rec_found += num_path;
3082 3082
3083 3083 if (rec_found == 0) {
3084 3084 if (retval == IBT_SUCCESS)
3085 3085 retval = IBT_PATH_RECORDS_NOT_FOUND;
3086 3086 } else if (rec_found != *max_count)
3087 3087 retval = IBT_INSUFF_DATA;
3088 3088 else if (rec_found != 0)
3089 3089 retval = IBT_SUCCESS;
3090 3090
3091 3091 if ((p_arg->src_ip_p != NULL) && (rec_found != 0)) {
3092 3092 for (i = 0; i < rec_found; i++) {
3093 3093 for (j = 0; j < sl->p_count; j++) {
3094 3094 if (sl[j].p_sgid.gid_guid == p_arg->paths[i].
3095 3095 pi_prim_cep_path.cep_adds_vect.
3096 3096 av_sgid.gid_guid) {
3097 3097 bcopy(&sl[j].p_src_ip,
3098 3098 &p_arg->src_ip_p[i].ip_primary,
3099 3099 sizeof (ibt_ip_addr_t));
3100 3100 }
3101 3101 /* Is Alt Path present */
3102 3102 if (p_arg->paths[i].pi_alt_cep_path.
3103 3103 cep_hca_port_num) {
3104 3104 if (sl[j].p_sgid.gid_guid ==
3105 3105 p_arg->paths[i].pi_alt_cep_path.
3106 3106 cep_adds_vect.av_sgid.gid_guid) {
3107 3107 bcopy(&sl[j].p_src_ip,
3108 3108 &p_arg->src_ip_p[i].
3109 3109 ip_alternate,
3110 3110 sizeof (ibt_ip_addr_t));
3111 3111 }
3112 3112 }
3113 3113 }
3114 3114 }
3115 3115 }
3116 3116 IBTF_DPRINTF_L3(cmlog, "ibcm_saa_ip_pr: done. Status = %d, "
3117 3117 "Found %d/%d Paths", retval, rec_found, *max_count);
3118 3118
3119 3119 *max_count = rec_found; /* Update the return count. */
3120 3120
3121 3121 return (retval);
3122 3122 }
3123 3123
3124 3124 static ibt_status_t
3125 3125 ibcm_ip_update_pri(sa_path_record_t *pr_resp, ibtl_cm_port_list_t *sl,
3126 3126 ibt_path_info_t *paths)
3127 3127 {
3128 3128 ibt_status_t retval = IBT_SUCCESS;
3129 3129 int s;
3130 3130
3131 3131 retval = ibcm_update_cep_info(pr_resp, sl, NULL,
3132 3132 &paths->pi_prim_cep_path);
3133 3133 if (retval != IBT_SUCCESS)
3134 3134 return (retval);
3135 3135
3136 3136 /* Update some leftovers */
3137 3137 paths->pi_prim_pkt_lt = pr_resp->PacketLifeTime;
3138 3138 paths->pi_path_mtu = pr_resp->Mtu;
3139 3139
3140 3140 for (s = 0; s < sl->p_count; s++) {
3141 3141 if (pr_resp->SGID.gid_guid == sl[s].p_sgid.gid_guid)
3142 3142 paths->pi_hca_guid = sl[s].p_hca_guid;
3143 3143 }
3144 3144
3145 3145 /* Set Alternate Path to invalid state. */
3146 3146 paths->pi_alt_cep_path.cep_hca_port_num = 0;
3147 3147 paths->pi_alt_cep_path.cep_adds_vect.av_dlid = 0;
3148 3148
3149 3149 IBTF_DPRINTF_L5(cmlog, "ibcm_ip_update_pri: Path HCA GUID 0x%llX",
3150 3150 paths->pi_hca_guid);
3151 3151
3152 3152 return (retval);
3153 3153 }
3154 3154
3155 3155
3156 3156 static ibt_status_t
3157 3157 ibcm_get_ip_spr(ibcm_ip_path_tqargs_t *p_arg, ibtl_cm_port_list_t *sl,
3158 3158 ibcm_ip_dinfo_t *dinfo, uint8_t *num_path, ibt_path_info_t *paths)
3159 3159 {
3160 3160 sa_path_record_t pathrec_req;
3161 3161 sa_path_record_t *pr_resp;
3162 3162 ibmf_saa_access_args_t access_args;
3163 3163 uint64_t c_mask = 0;
3164 3164 void *results_p;
3165 3165 uint8_t num_rec;
3166 3166 size_t length;
3167 3167 ibt_status_t retval;
3168 3168 int i, j, k;
3169 3169 uint8_t found, p_fnd;
3170 3170 ibt_ip_path_attr_t *attrp = &p_arg->attr;
3171 3171 ibmf_saa_handle_t saa_handle;
3172 3172
3173 3173 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_spr(%p, %p, %p, %d)",
3174 3174 p_arg, sl, dinfo, *num_path);
3175 3175
3176 3176 bzero(&pathrec_req, sizeof (sa_path_record_t));
3177 3177
3178 3178 /* Is Flow Label Specified. */
3179 3179 if (attrp->ipa_flow) {
3180 3180 pathrec_req.FlowLabel = attrp->ipa_flow;
3181 3181 c_mask |= SA_PR_COMPMASK_FLOWLABEL;
3182 3182 }
3183 3183
3184 3184 /* Is HopLimit Specified. */
3185 3185 if (p_arg->flags & IBT_PATH_HOP) {
3186 3186 pathrec_req.HopLimit = attrp->ipa_hop;
3187 3187 c_mask |= SA_PR_COMPMASK_HOPLIMIT;
3188 3188 }
3189 3189
3190 3190 /* Is TClass Specified. */
3191 3191 if (attrp->ipa_tclass) {
3192 3192 pathrec_req.TClass = attrp->ipa_tclass;
3193 3193 c_mask |= SA_PR_COMPMASK_TCLASS;
3194 3194 }
3195 3195
3196 3196 /* Is SL specified. */
3197 3197 if (attrp->ipa_sl) {
3198 3198 pathrec_req.SL = attrp->ipa_sl;
3199 3199 c_mask |= SA_PR_COMPMASK_SL;
3200 3200 }
3201 3201
3202 3202 /* If IBT_PATH_PERF is set, then mark all selectors to BEST. */
3203 3203 if (p_arg->flags & IBT_PATH_PERF) {
3204 3204 pathrec_req.PacketLifeTimeSelector = IBT_BEST;
3205 3205 pathrec_req.MtuSelector = IBT_BEST;
3206 3206 pathrec_req.RateSelector = IBT_BEST;
3207 3207
3208 3208 c_mask |= SA_PR_COMPMASK_PKTLTSELECTOR |
3209 3209 SA_PR_COMPMASK_RATESELECTOR | SA_PR_COMPMASK_MTUSELECTOR;
3210 3210 } else {
3211 3211 if (attrp->ipa_pkt_lt.p_selector == IBT_BEST) {
3212 3212 pathrec_req.PacketLifeTimeSelector = IBT_BEST;
3213 3213 c_mask |= SA_PR_COMPMASK_PKTLTSELECTOR;
3214 3214 }
3215 3215
3216 3216 if (attrp->ipa_srate.r_selector == IBT_BEST) {
3217 3217 pathrec_req.RateSelector = IBT_BEST;
3218 3218 c_mask |= SA_PR_COMPMASK_RATESELECTOR;
3219 3219 }
3220 3220
3221 3221 if (attrp->ipa_mtu.r_selector == IBT_BEST) {
3222 3222 pathrec_req.MtuSelector = IBT_BEST;
3223 3223 c_mask |= SA_PR_COMPMASK_MTUSELECTOR;
3224 3224 }
3225 3225 }
3226 3226
3227 3227 /*
3228 3228 * Honor individual selection of these attributes,
3229 3229 * even if IBT_PATH_PERF is set.
3230 3230 */
3231 3231 /* Check out whether Packet Life Time is specified. */
3232 3232 if (attrp->ipa_pkt_lt.p_pkt_lt) {
3233 3233 pathrec_req.PacketLifeTime =
3234 3234 ibt_usec2ib(attrp->ipa_pkt_lt.p_pkt_lt);
3235 3235 pathrec_req.PacketLifeTimeSelector =
3236 3236 attrp->ipa_pkt_lt.p_selector;
3237 3237
3238 3238 c_mask |= SA_PR_COMPMASK_PKTLT | SA_PR_COMPMASK_PKTLTSELECTOR;
3239 3239 }
3240 3240
3241 3241 /* Is SRATE specified. */
3242 3242 if (attrp->ipa_srate.r_srate) {
3243 3243 pathrec_req.Rate = attrp->ipa_srate.r_srate;
3244 3244 pathrec_req.RateSelector = attrp->ipa_srate.r_selector;
3245 3245
3246 3246 c_mask |= SA_PR_COMPMASK_RATE | SA_PR_COMPMASK_RATESELECTOR;
3247 3247 }
3248 3248
3249 3249 /* Is MTU specified. */
3250 3250 if (attrp->ipa_mtu.r_mtu) {
3251 3251 pathrec_req.Mtu = attrp->ipa_mtu.r_mtu;
3252 3252 pathrec_req.MtuSelector = attrp->ipa_mtu.r_selector;
3253 3253
3254 3254 c_mask |= SA_PR_COMPMASK_MTU | SA_PR_COMPMASK_MTUSELECTOR;
3255 3255 }
3256 3256
3257 3257 /* We always get REVERSIBLE paths. */
3258 3258 pathrec_req.Reversible = 1;
3259 3259 c_mask |= SA_PR_COMPMASK_REVERSIBLE;
3260 3260
3261 3261 pathrec_req.NumbPath = *num_path;
3262 3262 c_mask |= SA_PR_COMPMASK_NUMBPATH;
3263 3263
3264 3264 p_fnd = found = 0;
3265 3265
3266 3266 for (i = 0; i < sl->p_count; i++) {
3267 3267 /* SGID */
3268 3268 pathrec_req.SGID = sl[i].p_sgid;
3269 3269 c_mask |= SA_PR_COMPMASK_SGID;
3270 3270 saa_handle = sl[i].p_saa_hdl;
3271 3271
3272 3272 for (k = 0; k < dinfo->num_dest; k++) {
3273 3273 if (pathrec_req.SGID.gid_prefix !=
3274 3274 dinfo->d_gid[k].gid_prefix) {
3275 3275 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_spr: "
3276 3276 "SGID_pfx=%llX DGID_pfx=%llX doesn't match",
3277 3277 pathrec_req.SGID.gid_prefix,
3278 3278 dinfo->d_gid[k].gid_prefix);
3279 3279 continue;
3280 3280 }
3281 3281
3282 3282 pathrec_req.DGID = dinfo->d_gid[k];
3283 3283 c_mask |= SA_PR_COMPMASK_DGID;
3284 3284
3285 3285 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_spr: "
3286 3286 "Get %d Path(s) between\n SGID %llX:%llX "
3287 3287 "DGID %llX:%llX", pathrec_req.NumbPath,
3288 3288 pathrec_req.SGID.gid_prefix,
3289 3289 pathrec_req.SGID.gid_guid,
3290 3290 pathrec_req.DGID.gid_prefix,
3291 3291 pathrec_req.DGID.gid_guid);
3292 3292
3293 3293 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_spr: CMask=0x%llX, "
3294 3294 "PKey=0x%X", c_mask, pathrec_req.P_Key);
3295 3295
3296 3296 /* Contact SA Access to retrieve Path Records. */
3297 3297 access_args.sq_attr_id = SA_PATHRECORD_ATTRID;
3298 3298 access_args.sq_template = &pathrec_req;
3299 3299 access_args.sq_access_type = IBMF_SAA_RETRIEVE;
3300 3300 access_args.sq_template_length =
3301 3301 sizeof (sa_path_record_t);
3302 3302 access_args.sq_component_mask = c_mask;
3303 3303 access_args.sq_callback = NULL;
3304 3304 access_args.sq_callback_arg = NULL;
3305 3305
3306 3306 retval = ibcm_contact_sa_access(saa_handle,
3307 3307 &access_args, &length, &results_p);
3308 3308 if (retval != IBT_SUCCESS) {
3309 3309 *num_path = 0;
3310 3310 return (retval);
3311 3311 }
3312 3312
3313 3313 num_rec = length / sizeof (sa_path_record_t);
3314 3314
3315 3315 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_spr: "
3316 3316 "FOUND %d/%d path requested", num_rec, *num_path);
3317 3317
3318 3318 if ((results_p == NULL) || (num_rec == 0))
3319 3319 continue;
3320 3320
3321 3321 /* Update the PathInfo from the response. */
3322 3322 pr_resp = (sa_path_record_t *)results_p;
3323 3323 for (j = 0; j < num_rec; j++, pr_resp++) {
3324 3324 if ((p_fnd != 0) &&
3325 3325 (p_arg->flags & IBT_PATH_APM)) {
3326 3326 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_spr"
3327 3327 ": Fill Alternate Path");
3328 3328 retval = ibcm_update_cep_info(pr_resp,
3329 3329 sl, NULL,
3330 3330 &paths[found - 1].pi_alt_cep_path);
3331 3331 if (retval != IBT_SUCCESS)
3332 3332 continue;
3333 3333
3334 3334 /* Update some leftovers */
3335 3335 paths[found - 1].pi_alt_pkt_lt =
3336 3336 pr_resp->PacketLifeTime;
3337 3337 p_fnd = 0;
3338 3338 } else {
3339 3339 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_spr"
3340 3340 ": Fill Primary Path");
3341 3341
3342 3342 if (found == *num_path)
3343 3343 break;
3344 3344
3345 3345 retval = ibcm_ip_update_pri(pr_resp, sl,
3346 3346 &paths[found]);
3347 3347 if (retval != IBT_SUCCESS)
3348 3348 continue;
3349 3349 p_fnd = 1;
3350 3350 found++;
3351 3351 }
3352 3352
3353 3353 }
3354 3354 /* Deallocate the memory for results_p. */
3355 3355 kmem_free(results_p, length);
3356 3356 }
3357 3357 }
3358 3358
3359 3359 if (found == 0)
3360 3360 retval = IBT_PATH_RECORDS_NOT_FOUND;
3361 3361 else if (found != *num_path)
3362 3362 retval = IBT_INSUFF_DATA;
3363 3363 else
3364 3364 retval = IBT_SUCCESS;
3365 3365
3366 3366 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_spr: done. Status %d, "
3367 3367 "Found %d/%d Paths", retval, found, *num_path);
3368 3368
3369 3369 *num_path = found;
3370 3370
3371 3371 return (retval);
3372 3372 }
3373 3373
3374 3374
3375 3375 static ibt_status_t
3376 3376 ibcm_get_ip_mpr(ibcm_ip_path_tqargs_t *p_arg, ibtl_cm_port_list_t *sl,
3377 3377 ibcm_ip_dinfo_t *dinfo, uint8_t *num_path, ibt_path_info_t *paths)
3378 3378 {
3379 3379 sa_multipath_record_t *mpr_req;
3380 3380 sa_path_record_t *pr_resp;
3381 3381 ibmf_saa_access_args_t access_args;
3382 3382 void *results_p;
3383 3383 uint64_t c_mask = 0;
3384 3384 ib_gid_t *gid_ptr, *gid_s_ptr;
3385 3385 size_t length;
3386 3386 int template_len;
3387 3387 uint8_t found, num_rec;
3388 3388 int i;
3389 3389 ibt_status_t retval;
3390 3390 uint8_t sgid_cnt, dgid_cnt;
3391 3391 ibt_ip_path_attr_t *attrp = &p_arg->attr;
3392 3392
3393 3393 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr(%p, %p, %p, %d)",
3394 3394 attrp, sl, dinfo, *num_path);
3395 3395
3396 3396 dgid_cnt = dinfo->num_dest;
3397 3397 sgid_cnt = sl->p_count;
3398 3398
3399 3399 if ((sgid_cnt == 0) || (dgid_cnt == 0)) {
3400 3400 IBTF_DPRINTF_L2(cmlog, "ibcm_get_ip_mpr: sgid_cnt(%d) or"
3401 3401 " dgid_cnt(%d) is zero", sgid_cnt, dgid_cnt);
3402 3402 return (IBT_INVALID_PARAM);
3403 3403 }
3404 3404
3405 3405 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr: Get %d records between "
3406 3406 "%d Src(s) <=> %d Dest(s)", *num_path, sgid_cnt, dgid_cnt);
3407 3407
3408 3408 /*
3409 3409 * Calculate the size for multi-path records template, which includes
3410 3410 * constant portion of the multipath record, plus variable size for
3411 3411 * SGID (sgid_cnt) and DGID (dgid_cnt).
3412 3412 */
3413 3413 template_len = ((dgid_cnt + sgid_cnt) * sizeof (ib_gid_t)) +
3414 3414 sizeof (sa_multipath_record_t);
3415 3415
3416 3416 mpr_req = kmem_zalloc(template_len, KM_SLEEP);
3417 3417
3418 3418 ASSERT(mpr_req != NULL);
3419 3419
3420 3420 gid_ptr = (ib_gid_t *)(((uchar_t *)mpr_req) +
3421 3421 sizeof (sa_multipath_record_t));
3422 3422
3423 3423 /* Get the starting pointer where GIDs are stored. */
3424 3424 gid_s_ptr = gid_ptr;
3425 3425
3426 3426 /* SGID */
3427 3427 for (i = 0; i < sgid_cnt; i++) {
3428 3428 *gid_ptr = sl[i].p_sgid;
3429 3429
3430 3430 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr: SGID[%d] = %llX:%llX",
3431 3431 i, gid_ptr->gid_prefix, gid_ptr->gid_guid);
3432 3432
3433 3433 gid_ptr++;
3434 3434 }
3435 3435
3436 3436 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mpr_req))
3437 3437
3438 3438 mpr_req->SGIDCount = sgid_cnt;
3439 3439 c_mask = SA_MPR_COMPMASK_SGIDCOUNT;
3440 3440
3441 3441 /* DGIDs */
3442 3442 for (i = 0; i < dgid_cnt; i++) {
3443 3443 *gid_ptr = dinfo->d_gid[i];
3444 3444
3445 3445 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr: DGID[%d] = "
3446 3446 "%llX:%llX", i, gid_ptr->gid_prefix, gid_ptr->gid_guid);
3447 3447 gid_ptr++;
3448 3448 }
3449 3449
3450 3450 mpr_req->DGIDCount = dgid_cnt;
3451 3451 c_mask |= SA_MPR_COMPMASK_DGIDCOUNT;
3452 3452
3453 3453 /* Is Flow Label Specified. */
3454 3454 if (attrp->ipa_flow) {
3455 3455 mpr_req->FlowLabel = attrp->ipa_flow;
3456 3456 c_mask |= SA_MPR_COMPMASK_FLOWLABEL;
3457 3457 }
3458 3458
3459 3459 /* Is HopLimit Specified. */
3460 3460 if (p_arg->flags & IBT_PATH_HOP) {
3461 3461 mpr_req->HopLimit = attrp->ipa_hop;
3462 3462 c_mask |= SA_MPR_COMPMASK_HOPLIMIT;
3463 3463 }
3464 3464
3465 3465 /* Is TClass Specified. */
3466 3466 if (attrp->ipa_tclass) {
3467 3467 mpr_req->TClass = attrp->ipa_tclass;
3468 3468 c_mask |= SA_MPR_COMPMASK_TCLASS;
3469 3469 }
3470 3470
3471 3471 /* Is SL specified. */
3472 3472 if (attrp->ipa_sl) {
3473 3473 mpr_req->SL = attrp->ipa_sl;
3474 3474 c_mask |= SA_MPR_COMPMASK_SL;
3475 3475 }
3476 3476
3477 3477 if (p_arg->flags & IBT_PATH_PERF) {
3478 3478 mpr_req->PacketLifeTimeSelector = IBT_BEST;
3479 3479 mpr_req->RateSelector = IBT_BEST;
3480 3480 mpr_req->MtuSelector = IBT_BEST;
3481 3481
3482 3482 c_mask |= SA_MPR_COMPMASK_PKTLTSELECTOR |
3483 3483 SA_MPR_COMPMASK_RATESELECTOR | SA_MPR_COMPMASK_MTUSELECTOR;
3484 3484 } else {
3485 3485 if (attrp->ipa_pkt_lt.p_selector == IBT_BEST) {
3486 3486 mpr_req->PacketLifeTimeSelector = IBT_BEST;
3487 3487 c_mask |= SA_MPR_COMPMASK_PKTLTSELECTOR;
3488 3488 }
3489 3489
3490 3490 if (attrp->ipa_srate.r_selector == IBT_BEST) {
3491 3491 mpr_req->RateSelector = IBT_BEST;
3492 3492 c_mask |= SA_MPR_COMPMASK_RATESELECTOR;
3493 3493 }
3494 3494
3495 3495 if (attrp->ipa_mtu.r_selector == IBT_BEST) {
3496 3496 mpr_req->MtuSelector = IBT_BEST;
3497 3497 c_mask |= SA_MPR_COMPMASK_MTUSELECTOR;
3498 3498 }
3499 3499 }
3500 3500
3501 3501 /*
3502 3502 * Honor individual selection of these attributes,
3503 3503 * even if IBT_PATH_PERF is set.
3504 3504 */
3505 3505 /* Check out whether Packet Life Time is specified. */
3506 3506 if (attrp->ipa_pkt_lt.p_pkt_lt) {
3507 3507 mpr_req->PacketLifeTime =
3508 3508 ibt_usec2ib(attrp->ipa_pkt_lt.p_pkt_lt);
3509 3509 mpr_req->PacketLifeTimeSelector =
3510 3510 attrp->ipa_pkt_lt.p_selector;
3511 3511
3512 3512 c_mask |= SA_MPR_COMPMASK_PKTLT |
3513 3513 SA_MPR_COMPMASK_PKTLTSELECTOR;
3514 3514 }
3515 3515
3516 3516 /* Is SRATE specified. */
3517 3517 if (attrp->ipa_srate.r_srate) {
3518 3518 mpr_req->Rate = attrp->ipa_srate.r_srate;
3519 3519 mpr_req->RateSelector = attrp->ipa_srate.r_selector;
3520 3520
3521 3521 c_mask |= SA_MPR_COMPMASK_RATE |
3522 3522 SA_MPR_COMPMASK_RATESELECTOR;
3523 3523 }
3524 3524
3525 3525 /* Is MTU specified. */
3526 3526 if (attrp->ipa_mtu.r_mtu) {
3527 3527 mpr_req->Mtu = attrp->ipa_mtu.r_mtu;
3528 3528 mpr_req->MtuSelector = attrp->ipa_mtu.r_selector;
3529 3529
3530 3530 c_mask |= SA_MPR_COMPMASK_MTU |
3531 3531 SA_MPR_COMPMASK_MTUSELECTOR;
3532 3532 }
3533 3533
3534 3534 /* We always get REVERSIBLE paths. */
3535 3535 mpr_req->Reversible = 1;
3536 3536 c_mask |= SA_MPR_COMPMASK_REVERSIBLE;
3537 3537
3538 3538 if (p_arg->flags & IBT_PATH_AVAIL) {
3539 3539 mpr_req->IndependenceSelector = 1;
3540 3540 c_mask |= SA_MPR_COMPMASK_INDEPSEL;
3541 3541 }
3542 3542
3543 3543 /* we will not specify how many records we want. */
3544 3544
3545 3545 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*mpr_req))
3546 3546
3547 3547 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr: CMask: %llX Pkey: %X",
3548 3548 c_mask, mpr_req->P_Key);
3549 3549
3550 3550 /* Contact SA Access to retrieve Path Records. */
3551 3551 access_args.sq_attr_id = SA_MULTIPATHRECORD_ATTRID;
3552 3552 access_args.sq_access_type = IBMF_SAA_RETRIEVE;
3553 3553 access_args.sq_component_mask = c_mask;
3554 3554 access_args.sq_template = mpr_req;
3555 3555 access_args.sq_template_length = sizeof (sa_multipath_record_t);
3556 3556 access_args.sq_callback = NULL;
3557 3557 access_args.sq_callback_arg = NULL;
3558 3558
3559 3559 retval = ibcm_contact_sa_access(sl->p_saa_hdl, &access_args, &length,
3560 3560 &results_p);
3561 3561 if (retval != IBT_SUCCESS) {
3562 3562 *num_path = 0; /* Update the return count. */
3563 3563 kmem_free(mpr_req, template_len);
3564 3564 return (retval);
3565 3565 }
3566 3566
3567 3567 num_rec = length / sizeof (sa_path_record_t);
3568 3568
3569 3569 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr: Found %d Paths", num_rec);
3570 3570
3571 3571 found = 0;
3572 3572 if ((results_p != NULL) && (num_rec > 0)) {
3573 3573 /* Update the PathInfo with the response Path Records */
3574 3574 pr_resp = (sa_path_record_t *)results_p;
3575 3575
3576 3576 for (i = 0; i < num_rec; i++) {
3577 3577 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr: "
3578 3578 "P[%d]: SG %llX, DG %llX", i,
3579 3579 pr_resp[i].SGID.gid_guid, pr_resp[i].DGID.gid_guid);
3580 3580 }
3581 3581
3582 3582 if (p_arg->flags & IBT_PATH_APM) {
3583 3583 sa_path_record_t *p_resp = NULL, *a_resp = NULL;
3584 3584 int p_found = 0, a_found = 0;
3585 3585 ib_gid_t p_sg, a_sg, p_dg, a_dg;
3586 3586 int s_spec;
3587 3587
3588 3588 s_spec =
3589 3589 p_arg->attr.ipa_src_ip.family != AF_UNSPEC ? 1 : 0;
3590 3590
3591 3591 p_sg = gid_s_ptr[0];
3592 3592 if (sgid_cnt > 1)
3593 3593 a_sg = gid_s_ptr[1];
3594 3594 else
3595 3595 a_sg = p_sg;
3596 3596
3597 3597 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr: P_SG: %llX, "
3598 3598 "A_SG: %llX", p_sg.gid_guid, a_sg.gid_guid);
3599 3599
3600 3600 p_dg = gid_s_ptr[sgid_cnt];
3601 3601 if (dgid_cnt > 1)
3602 3602 a_dg = gid_s_ptr[sgid_cnt + 1];
3603 3603 else
3604 3604 a_dg = p_dg;
3605 3605
3606 3606 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr: P_DG: %llX, "
3607 3607 "A_DG: %llX", p_dg.gid_guid, a_dg.gid_guid);
3608 3608
3609 3609 /*
3610 3610 * If SGID and/or DGID is specified by user, make sure
3611 3611 * he gets his primary-path on those node points.
3612 3612 */
3613 3613 for (i = 0; i < num_rec; i++, pr_resp++) {
3614 3614 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr: "
3615 3615 "PF %d, AF %d,\n\t\t P[%d] = SG: %llX, "
3616 3616 "DG: %llX", p_found, a_found, i,
3617 3617 pr_resp->SGID.gid_guid,
3618 3618 pr_resp->DGID.gid_guid);
3619 3619
3620 3620 if ((!p_found) &&
3621 3621 (p_dg.gid_guid == pr_resp->DGID.gid_guid)) {
3622 3622 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr"
3623 3623 ": Pri DGID Match.. ");
3624 3624 if ((s_spec == 0) || (p_sg.gid_guid ==
3625 3625 pr_resp->SGID.gid_guid)) {
3626 3626 p_found = 1;
3627 3627 p_resp = pr_resp;
3628 3628 IBTF_DPRINTF_L3(cmlog,
3629 3629 "ibcm_get_ip_mpr: "
3630 3630 "Primary Path Found");
3631 3631
3632 3632 if (a_found)
3633 3633 break;
3634 3634 else
3635 3635 continue;
3636 3636 }
3637 3637 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr"
3638 3638 ": Pri SGID Don't Match.. ");
3639 3639 }
3640 3640
3641 3641 if ((!a_found) &&
3642 3642 (a_dg.gid_guid == pr_resp->DGID.gid_guid)) {
3643 3643 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr"
3644 3644 ": Alt DGID Match.. ");
3645 3645 if ((s_spec == 0) || (a_sg.gid_guid ==
3646 3646 pr_resp->SGID.gid_guid)) {
3647 3647 a_found = 1;
3648 3648 a_resp = pr_resp;
3649 3649
3650 3650 IBTF_DPRINTF_L3(cmlog,
3651 3651 "ibcm_get_ip_mpr:"
3652 3652 "Alternate Path Found ");
3653 3653
3654 3654 if (p_found)
3655 3655 break;
3656 3656 else
3657 3657 continue;
3658 3658 }
3659 3659 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr"
3660 3660 ": Alt SGID Don't Match.. ");
3661 3661 }
3662 3662 }
3663 3663
3664 3664 if ((p_found == 0) && (a_found == 0)) {
3665 3665 IBTF_DPRINTF_L2(cmlog, "ibcm_get_ip_mpr: Path "
3666 3666 "to desired node points NOT Available.");
3667 3667 retval = IBT_PATH_RECORDS_NOT_FOUND;
3668 3668 goto get_ip_mpr_end;
3669 3669 }
3670 3670
3671 3671 if ((p_resp == NULL) && (a_resp != NULL)) {
3672 3672 p_resp = a_resp;
3673 3673 a_resp = NULL;
3674 3674 }
3675 3675
3676 3676 /* Fill in Primary Path */
3677 3677 retval = ibcm_ip_update_pri(p_resp, sl, &paths[found]);
3678 3678 if (retval != IBT_SUCCESS)
3679 3679 goto get_ip_mpr_end;
3680 3680
3681 3681 /* Fill in Alternate Path */
3682 3682 if (a_resp != NULL) {
3683 3683 /* a_resp will point to AltPathInfo buffer. */
3684 3684 retval = ibcm_update_cep_info(a_resp, sl,
3685 3685 NULL, &paths[found].pi_alt_cep_path);
3686 3686 if (retval != IBT_SUCCESS)
3687 3687 goto get_ip_mpr_end;
3688 3688
3689 3689 /* Update some leftovers */
3690 3690 paths[found].pi_alt_pkt_lt =
3691 3691 a_resp->PacketLifeTime;
3692 3692 } else {
3693 3693 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr: "
3694 3694 "Alternate Path NOT Available.");
3695 3695 retval = IBT_INSUFF_DATA;
3696 3696 }
3697 3697 found++;
3698 3698 } else { /* If NOT APM */
3699 3699 for (i = 0; i < num_rec; i++, pr_resp++) {
3700 3700 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr: "
3701 3701 "DGID(%llX)", pr_resp->DGID.gid_guid);
3702 3702
3703 3703 /* Fill in Primary Path */
3704 3704 retval = ibcm_ip_update_pri(pr_resp, sl,
3705 3705 &paths[found]);
3706 3706 if (retval != IBT_SUCCESS)
3707 3707 continue;
3708 3708
3709 3709 if (++found == *num_path)
3710 3710 break;
3711 3711 }
3712 3712 }
3713 3713 get_ip_mpr_end:
3714 3714 kmem_free(results_p, length);
3715 3715 }
3716 3716 kmem_free(mpr_req, template_len);
3717 3717
3718 3718 if (found == 0)
3719 3719 retval = IBT_PATH_RECORDS_NOT_FOUND;
3720 3720 else if (found != *num_path)
3721 3721 retval = IBT_INSUFF_DATA;
3722 3722 else
3723 3723 retval = IBT_SUCCESS;
3724 3724
3725 3725 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr: Done (status %d). "
3726 3726 "Found %d/%d Paths", retval, found, *num_path);
3727 3727
3728 3728 *num_path = found; /* Update the return count. */
3729 3729
3730 3730 return (retval);
3731 3731 }
3732 3732
3733 3733
3734 3734 static void
3735 3735 ibcm_process_get_ip_paths(void *tq_arg)
3736 3736 {
3737 3737 ibcm_ip_path_tqargs_t *p_arg = (ibcm_ip_path_tqargs_t *)tq_arg;
3738 3738 ibcm_ip_dinfo_t *dinfo = NULL;
3739 3739 int len = 0;
3740 3740 uint8_t max_paths, num_path;
3741 3741 ib_gid_t *d_gids_p = NULL;
3742 3742 ib_gid_t sgid, dgid1, dgid2;
3743 3743 ibt_status_t retval = IBT_SUCCESS;
3744 3744 ibtl_cm_port_list_t *sl = NULL;
3745 3745 uint_t dnum = 0;
3746 3746 uint8_t i;
3747 3747 ibcm_hca_info_t *hcap;
3748 3748 ibmf_saa_handle_t saa_handle;
3749 3749 ibt_path_attr_t attr;
3750 3750 ibt_ip_addr_t src_ip_p;
3751 3751
3752 3752 IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_ip_paths(%p, 0x%X) ",
3753 3753 p_arg, p_arg->flags);
3754 3754
3755 3755 max_paths = num_path = p_arg->attr.ipa_max_paths;
3756 3756
3757 3757 /*
3758 3758 * Prepare the Source and Destination GID list based on the input
3759 3759 * attributes. We contact ARP module to perform IP to MAC
3760 3760 * i.e. GID conversion. We use this GID for path look-up.
3761 3761 *
3762 3762 * If APM is requested and if multiple Dest IPs are specified, check
3763 3763 * out whether they are companion to each other. But, if only one
3764 3764 * Dest IP is specified, then it is beyond our scope to verify that
3765 3765 * the companion port GID obtained has IP-Service enabled.
3766 3766 */
3767 3767 dgid1.gid_prefix = dgid1.gid_guid = 0;
3768 3768 sgid.gid_prefix = sgid.gid_guid = 0;
3769 3769
3770 3770 retval = ibcm_arp_get_ibaddr(p_arg->attr.ipa_zoneid,
3771 3771 p_arg->attr.ipa_src_ip, p_arg->attr.ipa_dst_ip[0], &sgid,
3772 3772 &dgid1, &src_ip_p);
3773 3773 if (retval) {
3774 3774 IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_ip_paths: "
3775 3775 "ibcm_arp_get_ibaddr() failed: %d", retval);
3776 3776 goto ippath_error;
3777 3777 }
3778 3778
3779 3779 bzero(&attr, sizeof (ibt_path_attr_t));
3780 3780 attr.pa_hca_guid = p_arg->attr.ipa_hca_guid;
3781 3781 attr.pa_hca_port_num = p_arg->attr.ipa_hca_port_num;
3782 3782 attr.pa_sgid = sgid;
3783 3783 bcopy(&p_arg->attr.ipa_mtu, &attr.pa_mtu, sizeof (ibt_mtu_req_t));
3784 3784 bcopy(&p_arg->attr.ipa_srate, &attr.pa_srate, sizeof (ibt_srate_req_t));
3785 3785 bcopy(&p_arg->attr.ipa_pkt_lt, &attr.pa_pkt_lt,
3786 3786 sizeof (ibt_pkt_lt_req_t));
3787 3787 retval = ibtl_cm_get_active_plist(&attr, p_arg->flags, &sl);
3788 3788 if (retval == IBT_SUCCESS) {
3789 3789 bcopy(&src_ip_p, &sl->p_src_ip, sizeof (ibt_ip_addr_t));
3790 3790 } else {
3791 3791 IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_ip_paths: "
3792 3792 "ibtl_cm_get_active_plist: Failed %d", retval);
3793 3793 goto ippath_error;
3794 3794 }
3795 3795
3796 3796 IBTF_DPRINTF_L4(cmlog, "ibcm_process_get_ip_paths: SGID %llX:%llX, "
3797 3797 "DGID0: %llX:%llX", sl->p_sgid.gid_prefix, sl->p_sgid.gid_guid,
3798 3798 dgid1.gid_prefix, dgid1.gid_guid);
3799 3799
3800 3800 len = p_arg->attr.ipa_ndst - 1;
3801 3801 len = (len * sizeof (ib_gid_t)) + sizeof (ibcm_ip_dinfo_t);
3802 3802 dinfo = kmem_zalloc(len, KM_SLEEP);
3803 3803
3804 3804 dinfo->d_gid[0] = dgid1;
3805 3805
3806 3806 i = 1;
3807 3807 if (p_arg->attr.ipa_ndst > 1) {
3808 3808 /* Get DGID for all specified Dest IP Addr */
3809 3809 for (; i < p_arg->attr.ipa_ndst; i++) {
3810 3810 retval = ibcm_arp_get_ibaddr(p_arg->attr.ipa_zoneid,
3811 3811 p_arg->attr.ipa_src_ip, p_arg->attr.ipa_dst_ip[i],
3812 3812 NULL, &dgid2, NULL);
3813 3813 if (retval) {
3814 3814 IBTF_DPRINTF_L2(cmlog,
3815 3815 "ibcm_process_get_ip_paths: "
3816 3816 "ibcm_arp_get_ibaddr failed: %d", retval);
3817 3817 goto ippath_error2;
3818 3818 }
3819 3819 dinfo->d_gid[i] = dgid2;
3820 3820
3821 3821 IBTF_DPRINTF_L4(cmlog, "ibcm_process_get_ip_paths: "
3822 3822 "DGID%d: %llX:%llX", i, dgid2.gid_prefix,
3823 3823 dgid2.gid_guid);
3824 3824 }
3825 3825
3826 3826 if (p_arg->flags & IBT_PATH_APM) {
3827 3827 dgid2 = dinfo->d_gid[1];
3828 3828
3829 3829 retval = ibcm_get_comp_pgids(dgid1, dgid2, 0,
3830 3830 &d_gids_p, &dnum);
3831 3831 if ((retval != IBT_SUCCESS) &&
3832 3832 (retval != IBT_GIDS_NOT_FOUND)) {
3833 3833 IBTF_DPRINTF_L2(cmlog,
3834 3834 "ibcm_process_get_ip_paths: "
3835 3835 "Invalid DGIDs specified w/ APM Flag");
3836 3836 goto ippath_error2;
3837 3837 }
3838 3838 IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_ip_paths: "
3839 3839 "Found %d Comp DGID", dnum);
3840 3840
3841 3841 if (dnum) {
3842 3842 dinfo->d_gid[i] = d_gids_p[0];
3843 3843 i++;
3844 3844 }
3845 3845 }
3846 3846 }
3847 3847
3848 3848 /* "i" will get us num_dest count. */
3849 3849 dinfo->num_dest = i;
3850 3850
3851 3851 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*p_arg))
3852 3852
3853 3853 /*
3854 3854 * IBTF allocates memory for path_info & src_ip in case of
3855 3855 * Async Get IP Paths
3856 3856 */
3857 3857 if (p_arg->func) { /* Do these only for Async Get Paths */
3858 3858 p_arg->paths = kmem_zalloc(sizeof (ibt_path_info_t) * max_paths,
3859 3859 KM_SLEEP);
3860 3860 if (p_arg->src_ip_p == NULL)
3861 3861 p_arg->src_ip_p = kmem_zalloc(
3862 3862 sizeof (ibt_path_ip_src_t) * max_paths, KM_SLEEP);
3863 3863 }
3864 3864
3865 3865 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*p_arg))
3866 3866
3867 3867 IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_ip_paths: HCA (%llX, %d)",
3868 3868 sl->p_hca_guid, sl->p_port_num);
3869 3869
3870 3870 hcap = ibcm_find_hca_entry(sl->p_hca_guid);
3871 3871 if (hcap == NULL) {
3872 3872 IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_ip_paths: "
3873 3873 "NO HCA found");
3874 3874 retval = IBT_HCA_BUSY_DETACHING;
3875 3875 goto ippath_error2;
3876 3876 }
3877 3877
3878 3878 /* Get SA Access Handle. */
3879 3879 for (i = 0; i < sl->p_count; i++) {
3880 3880 if (i == 0) {
3881 3881 /* Validate whether this HCA supports APM */
3882 3882 if ((p_arg->flags & IBT_PATH_APM) &&
3883 3883 (!(hcap->hca_caps & IBT_HCA_AUTO_PATH_MIG))) {
3884 3884 IBTF_DPRINTF_L2(cmlog,
3885 3885 "ibcm_process_get_ip_paths: HCA (%llX): "
3886 3886 "APM NOT SUPPORTED", sl[i].p_hca_guid);
3887 3887 retval = IBT_APM_NOT_SUPPORTED;
3888 3888 goto ippath_error3;
3889 3889 }
3890 3890 }
3891 3891
3892 3892 saa_handle = ibcm_get_saa_handle(hcap, sl[i].p_port_num);
3893 3893 if (saa_handle == NULL) {
3894 3894 IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_ip_paths: "
3895 3895 "SAA HDL NULL, HCA (%llX:%d) NOT ACTIVE",
3896 3896 sl[i].p_hca_guid, sl[i].p_port_num);
3897 3897 retval = IBT_HCA_PORT_NOT_ACTIVE;
3898 3898 goto ippath_error3;
3899 3899 }
3900 3900 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*sl))
3901 3901 sl[i].p_saa_hdl = saa_handle;
3902 3902 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*sl))
3903 3903 }
3904 3904
3905 3905 /* Get Path Records. */
3906 3906 retval = ibcm_saa_ip_pr(p_arg, sl, dinfo, &num_path);
3907 3907
3908 3908 ippath_error3:
3909 3909 ibcm_dec_hca_acc_cnt(hcap);
3910 3910
3911 3911 ippath_error2:
3912 3912 if (dinfo && len)
3913 3913 kmem_free(dinfo, len);
3914 3914
3915 3915 ippath_error1:
3916 3916 if (sl)
3917 3917 ibtl_cm_free_active_plist(sl);
3918 3918
3919 3919 ippath_error:
3920 3920 if ((retval != IBT_SUCCESS) && (retval != IBT_INSUFF_DATA))
3921 3921 num_path = 0;
3922 3922
3923 3923 if (p_arg->num_paths_p != NULL)
3924 3924 *p_arg->num_paths_p = num_path;
3925 3925
3926 3926 if (p_arg->func) { /* Do these only for Async Get Paths */
3927 3927 ibt_path_info_t *tmp_path_p;
3928 3928 ibt_path_ip_src_t *tmp_src_ip_p;
3929 3929
3930 3930 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*p_arg))
3931 3931 p_arg->retval = retval;
3932 3932 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*p_arg))
3933 3933
3934 3934 if (retval == IBT_INSUFF_DATA) {
3935 3935 /*
3936 3936 * We allocated earlier memory based on "max_paths",
3937 3937 * but we got lesser path-records, so re-adjust that
3938 3938 * buffer so that caller can free the correct memory.
3939 3939 */
3940 3940 tmp_path_p = kmem_alloc(
3941 3941 sizeof (ibt_path_info_t) * num_path, KM_SLEEP);
3942 3942
3943 3943 bcopy(p_arg->paths, tmp_path_p,
3944 3944 num_path * sizeof (ibt_path_info_t));
3945 3945
3946 3946 kmem_free(p_arg->paths,
3947 3947 sizeof (ibt_path_info_t) * max_paths);
3948 3948
3949 3949 tmp_src_ip_p = kmem_alloc(
3950 3950 sizeof (ibt_path_ip_src_t) * num_path, KM_SLEEP);
3951 3951
3952 3952 bcopy(p_arg->src_ip_p, tmp_src_ip_p,
3953 3953 num_path * sizeof (ibt_path_ip_src_t));
3954 3954
3955 3955 kmem_free(p_arg->src_ip_p,
3956 3956 sizeof (ibt_path_ip_src_t) * max_paths);
3957 3957 } else if (retval != IBT_SUCCESS) {
3958 3958 if (p_arg->paths)
3959 3959 kmem_free(p_arg->paths,
3960 3960 sizeof (ibt_path_info_t) * max_paths);
3961 3961 if (p_arg->src_ip_p)
3962 3962 kmem_free(p_arg->src_ip_p,
3963 3963 sizeof (ibt_path_ip_src_t) * max_paths);
3964 3964 tmp_path_p = NULL;
3965 3965 tmp_src_ip_p = NULL;
3966 3966 } else {
3967 3967 tmp_path_p = p_arg->paths;
3968 3968 tmp_src_ip_p = p_arg->src_ip_p;
3969 3969 }
3970 3970 (*(p_arg->func))(p_arg->arg, retval, tmp_path_p, num_path,
3971 3971 tmp_src_ip_p);
3972 3972
3973 3973 len = p_arg->len;
3974 3974 if (p_arg && len)
3975 3975 kmem_free(p_arg, len);
3976 3976 } else {
3977 3977 mutex_enter(&p_arg->ip_lock);
3978 3978 p_arg->ip_done = B_TRUE;
3979 3979 p_arg->retval = retval;
3980 3980 cv_signal(&p_arg->ip_cv);
3981 3981 mutex_exit(&p_arg->ip_lock);
3982 3982 }
3983 3983
3984 3984 IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_ip_paths: done: status %d, "
3985 3985 "Found %d/%d Path Records", retval, num_path, max_paths);
3986 3986 }
3987 3987
3988 3988
3989 3989 static ibt_status_t
3990 3990 ibcm_val_ipattr(ibt_ip_path_attr_t *attrp, ibt_path_flags_t flags)
3991 3991 {
3992 3992 uint_t i;
3993 3993
3994 3994 if (attrp == NULL) {
3995 3995 IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: IP Path Attr is NULL");
3996 3996 return (IBT_INVALID_PARAM);
3997 3997 }
3998 3998
3999 3999 IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: Inputs are: HCA %llX:%d, "
4000 4000 "Maxpath= %d, \n Flags= 0x%X, #Dest %d", attrp->ipa_hca_guid,
4001 4001 attrp->ipa_hca_port_num, attrp->ipa_max_paths, flags,
4002 4002 attrp->ipa_ndst);
4003 4003
4004 4004 /*
4005 4005 * Validate Path Flags.
4006 4006 * IBT_PATH_AVAIL & IBT_PATH_PERF are mutually exclusive.
4007 4007 */
4008 4008 if ((flags & IBT_PATH_AVAIL) && (flags & IBT_PATH_PERF)) {
4009 4009 IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: Invalid Flags: 0x%X,"
4010 4010 "\n\t AVAIL and PERF flags specified together", flags);
4011 4011 return (IBT_INVALID_PARAM);
4012 4012 }
4013 4013
4014 4014 /*
4015 4015 * Validate number of records requested.
4016 4016 *
4017 4017 * Max_paths of "0" is invalid.
4018 4018 * Max_paths <= IBT_MAX_SPECIAL_PATHS, if AVAIL or PERF is set.
4019 4019 */
4020 4020 if (attrp->ipa_max_paths == 0) {
4021 4021 IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: Invalid max_paths %d",
4022 4022 attrp->ipa_max_paths);
4023 4023 return (IBT_INVALID_PARAM);
4024 4024 }
4025 4025
4026 4026 if ((flags & (IBT_PATH_AVAIL | IBT_PATH_PERF)) &&
4027 4027 (attrp->ipa_max_paths > IBT_MAX_SPECIAL_PATHS)) {
4028 4028 IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: MaxPaths that can be "
4029 4029 "requested is <%d> \n when IBT_PATH_AVAIL or IBT_PATH_PERF"
4030 4030 " flag is specified.", IBT_MAX_SPECIAL_PATHS);
4031 4031 return (IBT_INVALID_PARAM);
4032 4032 }
4033 4033
4034 4034 /* Only 2 destinations can be specified w/ APM flag. */
4035 4035 if ((flags & IBT_PATH_APM) && (attrp->ipa_ndst > 2)) {
4036 4036 IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: Max #Dest is 2, with "
4037 4037 "APM flag");
4038 4038 return (IBT_INVALID_PARAM);
4039 4039 }
4040 4040
4041 4041 /* Validate the destination info */
4042 4042 if ((attrp->ipa_ndst == 0) || (attrp->ipa_ndst == NULL)) {
4043 4043 IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: DstIP Not provided "
4044 4044 "dst_ip %p, ndst %d", attrp->ipa_dst_ip, attrp->ipa_ndst);
4045 4045 return (IBT_INVALID_PARAM);
4046 4046 }
4047 4047
4048 4048 /* Basic validation of Source IPADDR (if provided). */
4049 4049 IBCM_PRINT_IP("ibcm_val_ipattr SrcIP", &attrp->ipa_src_ip);
4050 4050 if ((attrp->ipa_src_ip.family == AF_INET) &&
4051 4051 (attrp->ipa_src_ip.un.ip4addr == htonl(INADDR_LOOPBACK) ||
4052 4052 attrp->ipa_src_ip.un.ip4addr == INADDR_ANY)) {
4053 4053 IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: SrcIP specified is "
4054 4054 "LOOPBACK/ZEROs: NOT SUPPORTED");
4055 4055 return (IBT_NOT_SUPPORTED);
4056 4056 } else if ((attrp->ipa_src_ip.family == AF_INET6) &&
4057 4057 (IN6_IS_ADDR_UNSPECIFIED(&attrp->ipa_src_ip.un.ip6addr) ||
4058 4058 IN6_IS_ADDR_LOOPBACK(&attrp->ipa_src_ip.un.ip6addr))) {
4059 4059 IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: SrcIP specified is "
4060 4060 "LOOPBACK/ZEROs: NOT SUPPORTED");
4061 4061 return (IBT_NOT_SUPPORTED);
4062 4062 }
4063 4063
4064 4064 if (ibcm_ip6_linklocal_addr_ok &&
4065 4065 (attrp->ipa_src_ip.family == AF_INET6) &&
4066 4066 (IN6_IS_ADDR_LINKLOCAL(&attrp->ipa_src_ip.un.ip6addr))) {
4067 4067 IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: SrcIP specified is "
4068 4068 "Link Local Address: NOT SUPPORTED");
4069 4069 return (IBT_NOT_SUPPORTED);
4070 4070 }
4071 4071
4072 4072 /* Basic validation of Dest IPADDR. */
4073 4073 for (i = 0; i < attrp->ipa_ndst; i++) {
4074 4074 ibt_ip_addr_t dst_ip = attrp->ipa_dst_ip[i];
4075 4075
4076 4076 IBCM_PRINT_IP("ibcm_val_ipattr DstIP", &dst_ip);
4077 4077
4078 4078 if (dst_ip.family == AF_UNSPEC) {
4079 4079 IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: ERROR: "
4080 4080 "Invalid DstIP specified");
4081 4081 return (IBT_INVALID_PARAM);
4082 4082 } else if ((dst_ip.family == AF_INET) &&
4083 4083 (dst_ip.un.ip4addr == htonl(INADDR_LOOPBACK) ||
4084 4084 dst_ip.un.ip4addr == INADDR_ANY)) {
4085 4085 IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: DstIP "
4086 4086 "specified is LOOPBACK/ZEROs: NOT SUPPORTED");
4087 4087 return (IBT_NOT_SUPPORTED);
4088 4088 } else if ((dst_ip.family == AF_INET6) &&
4089 4089 (IN6_IS_ADDR_UNSPECIFIED(&dst_ip.un.ip6addr) ||
4090 4090 IN6_IS_ADDR_LOOPBACK(&dst_ip.un.ip6addr))) {
4091 4091 IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: DstIP "
4092 4092 "specified is LOOPBACK/ZEROs: NOT SUPPORTED");
4093 4093 return (IBT_NOT_SUPPORTED);
4094 4094 }
4095 4095
4096 4096 /*
4097 4097 * If SrcIP is specified, make sure that SrcIP and DstIP
4098 4098 * belong to same family.
4099 4099 */
4100 4100 if ((attrp->ipa_src_ip.family != AF_UNSPEC) &&
4101 4101 (attrp->ipa_src_ip.family != dst_ip.family)) {
4102 4102 IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: ERROR: "
4103 4103 "Specified SrcIP (%d) and DstIP(%d) family diffs.",
4104 4104 attrp->ipa_src_ip.family, dst_ip.family);
4105 4105 return (IBT_INVALID_PARAM);
4106 4106 }
4107 4107 }
4108 4108
4109 4109 return (IBT_SUCCESS);
4110 4110 }
4111 4111
4112 4112
4113 4113 static ibt_status_t
4114 4114 ibcm_get_ip_path(ibt_clnt_hdl_t ibt_hdl, ibt_path_flags_t flags,
4115 4115 ibt_ip_path_attr_t *attrp, ibt_path_info_t *paths, uint8_t *num_path_p,
4116 4116 ibt_path_ip_src_t *src_ip_p, ibt_ip_path_handler_t func, void *arg)
4117 4117 {
4118 4118 ibcm_ip_path_tqargs_t *path_tq;
4119 4119 int sleep_flag = ((func == NULL) ? KM_SLEEP : KM_NOSLEEP);
4120 4120 uint_t len, ret;
4121 4121 ibt_status_t retval;
4122 4122
4123 4123 retval = ibcm_val_ipattr(attrp, flags);
4124 4124 if (retval != IBT_SUCCESS)
4125 4125 return (retval);
4126 4126
4127 4127 len = (attrp->ipa_ndst * sizeof (ibt_ip_addr_t)) +
4128 4128 sizeof (ibcm_ip_path_tqargs_t);
4129 4129 path_tq = kmem_zalloc(len, sleep_flag);
4130 4130 if (path_tq == NULL) {
4131 4131 IBTF_DPRINTF_L2(cmlog, "ibcm_get_ip_path: "
4132 4132 "Unable to allocate memory for local usage.");
4133 4133 return (IBT_INSUFF_KERNEL_RESOURCE);
4134 4134 }
4135 4135
4136 4136 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*path_tq))
4137 4137 bcopy(attrp, &path_tq->attr, sizeof (ibt_ip_path_attr_t));
4138 4138
4139 4139 path_tq->attr.ipa_dst_ip = (ibt_ip_addr_t *)(((uchar_t *)path_tq) +
4140 4140 sizeof (ibcm_ip_path_tqargs_t));
4141 4141 bcopy(attrp->ipa_dst_ip, path_tq->attr.ipa_dst_ip,
4142 4142 sizeof (ibt_ip_addr_t) * attrp->ipa_ndst);
4143 4143
4144 4144 /* Ignore IBT_PATH_AVAIL flag, if only one path is requested. */
4145 4145 if ((flags & IBT_PATH_AVAIL) && (attrp->ipa_max_paths == 1)) {
4146 4146 flags &= ~IBT_PATH_AVAIL;
4147 4147
4148 4148 IBTF_DPRINTF_L4(cmlog, "ibcm_get_ip_path: Ignoring "
4149 4149 "IBT_PATH_AVAIL flag, as only ONE path info is requested.");
4150 4150 }
4151 4151
4152 4152 path_tq->flags = flags;
4153 4153 path_tq->ibt_hdl = ibt_hdl;
4154 4154 path_tq->paths = paths;
4155 4155 path_tq->src_ip_p = src_ip_p;
4156 4156 path_tq->num_paths_p = num_path_p;
4157 4157 path_tq->func = func;
4158 4158 path_tq->arg = arg;
4159 4159 path_tq->len = len;
4160 4160 path_tq->ip_done = B_FALSE;
4161 4161 if (func == NULL) { /* Blocking */
4162 4162 mutex_init(&path_tq->ip_lock, NULL, MUTEX_DEFAULT, NULL);
4163 4163 cv_init(&path_tq->ip_cv, NULL, CV_DRIVER, NULL);
4164 4164 }
4165 4165
4166 4166 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*path_tq))
4167 4167
4168 4168 sleep_flag = ((func == NULL) ? TQ_SLEEP : TQ_NOSLEEP);
4169 4169 ret = taskq_dispatch(ibcm_taskq, ibcm_process_get_ip_paths, path_tq,
4170 4170 sleep_flag);
4171 4171 if (ret == 0) {
4172 4172 IBTF_DPRINTF_L2(cmlog, "ibcm_get_ip_path: Failed to dispatch "
4173 4173 "the TaskQ");
4174 4174 if (func == NULL) { /* Blocking */
4175 4175 cv_destroy(&path_tq->ip_cv);
4176 4176 mutex_destroy(&path_tq->ip_lock);
4177 4177 }
4178 4178 kmem_free(path_tq, len);
4179 4179 retval = IBT_INSUFF_KERNEL_RESOURCE;
4180 4180 } else {
4181 4181 if (func != NULL) { /* Non-Blocking */
4182 4182 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_path: NonBlocking");
4183 4183 retval = IBT_SUCCESS;
4184 4184 } else { /* Blocking */
4185 4185 IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_path: Blocking");
4186 4186 mutex_enter(&path_tq->ip_lock);
4187 4187 while (path_tq->ip_done != B_TRUE)
4188 4188 cv_wait(&path_tq->ip_cv, &path_tq->ip_lock);
4189 4189 retval = path_tq->retval;
4190 4190 mutex_exit(&path_tq->ip_lock);
4191 4191 cv_destroy(&path_tq->ip_cv);
4192 4192 mutex_destroy(&path_tq->ip_lock);
4193 4193 kmem_free(path_tq, len);
4194 4194 }
4195 4195 }
4196 4196
4197 4197 return (retval);
4198 4198 }
4199 4199
4200 4200
4201 4201 ibt_status_t
4202 4202 ibt_aget_ip_paths(ibt_clnt_hdl_t ibt_hdl, ibt_path_flags_t flags,
4203 4203 ibt_ip_path_attr_t *attrp, ibt_ip_path_handler_t func, void *arg)
4204 4204 {
4205 4205 IBTF_DPRINTF_L3(cmlog, "ibt_aget_ip_paths(%p (%s), 0x%X, %p, %p, %p)",
4206 4206 ibt_hdl, ibtl_cm_get_clnt_name(ibt_hdl), flags, attrp, func, arg);
4207 4207
4208 4208 if (func == NULL) {
4209 4209 IBTF_DPRINTF_L2(cmlog, "ibt_aget_ip_paths: Function Pointer is "
4210 4210 "NULL - ERROR ");
4211 4211 return (IBT_INVALID_PARAM);
4212 4212 }
4213 4213
4214 4214 /* path info will be allocated in ibcm_process_get_ip_paths() */
4215 4215 return (ibcm_get_ip_path(ibt_hdl, flags, attrp, NULL, NULL,
4216 4216 NULL, func, arg));
4217 4217 }
4218 4218
4219 4219
4220 4220 ibt_status_t
4221 4221 ibt_get_ip_paths(ibt_clnt_hdl_t ibt_hdl, ibt_path_flags_t flags,
4222 4222 ibt_ip_path_attr_t *attrp, ibt_path_info_t *paths, uint8_t *num_paths_p,
4223 4223 ibt_path_ip_src_t *src_ip_p)
4224 4224 {
4225 4225 IBTF_DPRINTF_L3(cmlog, "ibt_get_ip_paths(%p(%s), 0x%X, %p, %p, %p, %p)",
4226 4226 ibt_hdl, ibtl_cm_get_clnt_name(ibt_hdl), flags, attrp, paths,
4227 4227 num_paths_p, src_ip_p);
4228 4228
4229 4229 if (paths == NULL) {
4230 4230 IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_paths: Path Info Pointer is "
4231 4231 "NULL - ERROR ");
4232 4232 return (IBT_INVALID_PARAM);
4233 4233 }
4234 4234
4235 4235 if (num_paths_p != NULL)
4236 4236 *num_paths_p = 0;
4237 4237
4238 4238 return (ibcm_get_ip_path(ibt_hdl, flags, attrp, paths, num_paths_p,
4239 4239 src_ip_p, NULL, NULL));
4240 4240 }
4241 4241
4242 4242
4243 4243 ibt_status_t
4244 4244 ibt_get_ip_alt_path(ibt_channel_hdl_t rc_chan, ibt_path_flags_t flags,
4245 4245 ibt_alt_ip_path_attr_t *attrp, ibt_alt_path_info_t *api_p)
4246 4246 {
4247 4247 sa_multipath_record_t *mpr_req;
4248 4248 sa_path_record_t *pr_resp;
4249 4249 ibmf_saa_access_args_t access_args;
4250 4250 ibt_qp_query_attr_t qp_attr;
4251 4251 ibtl_cm_hca_port_t c_hp, n_hp;
4252 4252 ibcm_hca_info_t *hcap;
4253 4253 void *results_p;
4254 4254 uint64_t c_mask = 0;
4255 4255 ib_gid_t *gid_ptr = NULL;
4256 4256 ib_gid_t *sgids_p = NULL, *dgids_p = NULL;
4257 4257 ib_gid_t cur_dgid, cur_sgid;
4258 4258 ib_gid_t new_dgid, new_sgid;
4259 4259 ibmf_saa_handle_t saa_handle;
4260 4260 size_t length;
4261 4261 int i, j, template_len, rec_found;
4262 4262 uint_t snum = 0, dnum = 0, num_rec;
4263 4263 ibt_status_t retval;
4264 4264 ib_mtu_t prim_mtu;
4265 4265
4266 4266 IBTF_DPRINTF_L3(cmlog, "ibt_get_ip_alt_path(%p, %x, %p, %p)",
4267 4267 rc_chan, flags, attrp, api_p);
4268 4268
4269 4269 /* validate channel */
4270 4270 if (IBCM_INVALID_CHANNEL(rc_chan)) {
4271 4271 IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_alt_path: invalid channel");
4272 4272 return (IBT_CHAN_HDL_INVALID);
4273 4273 }
4274 4274
4275 4275 if (api_p == NULL) {
4276 4276 IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_alt_path: invalid attribute:"
4277 4277 " AltPathInfo can't be NULL");
4278 4278 return (IBT_INVALID_PARAM);
4279 4279 }
4280 4280
4281 4281 retval = ibt_query_qp(rc_chan, &qp_attr);
4282 4282 if (retval != IBT_SUCCESS) {
4283 4283 IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_alt_path: ibt_query_qp(%p) "
4284 4284 "failed %d", rc_chan, retval);
4285 4285 return (retval);
4286 4286 }
4287 4287
4288 4288 if (qp_attr.qp_info.qp_trans != IBT_RC_SRV) {
4289 4289 IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_alt_path: "
4290 4290 "Invalid Channel type: Applicable only to RC Channel");
4291 4291 return (IBT_CHAN_SRV_TYPE_INVALID);
4292 4292 }
4293 4293
4294 4294 cur_dgid =
4295 4295 qp_attr.qp_info.qp_transport.rc.rc_path.cep_adds_vect.av_dgid;
4296 4296 cur_sgid =
4297 4297 qp_attr.qp_info.qp_transport.rc.rc_path.cep_adds_vect.av_sgid;
4298 4298 prim_mtu = qp_attr.qp_info.qp_transport.rc.rc_path_mtu;
4299 4299
4300 4300 /* If optional attributes are specified, validate them. */
4301 4301 if (attrp) {
4302 4302 /* Get SGID and DGID for the specified input ip-addr */
4303 4303 retval = ibcm_arp_get_ibaddr(attrp->apa_zoneid,
4304 4304 attrp->apa_src_ip, attrp->apa_dst_ip, &new_sgid,
4305 4305 &new_dgid, NULL);
4306 4306 if (retval) {
4307 4307 IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_alt_path: "
4308 4308 "ibcm_arp_get_ibaddr() failed: %d", retval);
4309 4309 return (retval);
4310 4310 }
4311 4311 } else {
4312 4312 new_dgid.gid_prefix = 0;
4313 4313 new_dgid.gid_guid = 0;
4314 4314 new_sgid.gid_prefix = 0;
4315 4315 new_sgid.gid_guid = 0;
4316 4316 }
4317 4317
4318 4318 if ((new_dgid.gid_prefix != 0) && (new_sgid.gid_prefix != 0) &&
4319 4319 (new_dgid.gid_prefix != new_sgid.gid_prefix)) {
4320 4320 IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_alt_path: Specified SGID's "
4321 4321 "SNprefix (%llX) doesn't match with \n specified DGID's "
4322 4322 "SNprefix: %llX", new_sgid.gid_prefix, new_dgid.gid_prefix);
4323 4323 return (IBT_INVALID_PARAM);
4324 4324 }
4325 4325
4326 4326 /* For the specified SGID, get HCA information. */
4327 4327 retval = ibtl_cm_get_hca_port(cur_sgid, 0, &c_hp);
4328 4328 if (retval != IBT_SUCCESS) {
4329 4329 IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_alt_path: "
4330 4330 "Get HCA Port Failed: %d", retval);
4331 4331 return (retval);
4332 4332 }
4333 4333
4334 4334 hcap = ibcm_find_hca_entry(c_hp.hp_hca_guid);
4335 4335 if (hcap == NULL) {
4336 4336 IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_alt_path: NO HCA found");
4337 4337 return (IBT_HCA_BUSY_DETACHING);
4338 4338 }
4339 4339
4340 4340 /* Validate whether this HCA support APM */
4341 4341 if (!(hcap->hca_caps & IBT_HCA_AUTO_PATH_MIG)) {
4342 4342 IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_alt_path: "
4343 4343 "HCA (%llX) - APM NOT SUPPORTED ", c_hp.hp_hca_guid);
4344 4344 retval = IBT_APM_NOT_SUPPORTED;
4345 4345 goto get_ip_alt_path_done;
4346 4346 }
4347 4347
4348 4348 /* Get Companion Port GID of the current Channel's SGID */
4349 4349 if ((new_sgid.gid_guid == 0) || ((new_sgid.gid_guid != 0) &&
4350 4350 (new_sgid.gid_guid != cur_sgid.gid_guid))) {
4351 4351 IBTF_DPRINTF_L3(cmlog, "ibt_get_ip_alt_path: SRC: "
4352 4352 "Get Companion PortGids for - %llX:%llX",
4353 4353 cur_sgid.gid_prefix, cur_sgid.gid_guid);
4354 4354
4355 4355 retval = ibcm_get_comp_pgids(cur_sgid, new_sgid,
4356 4356 c_hp.hp_hca_guid, &sgids_p, &snum);
4357 4357 if (retval != IBT_SUCCESS)
4358 4358 goto get_ip_alt_path_done;
4359 4359 }
4360 4360
4361 4361 /* Get Companion Port GID of the current Channel's DGID */
4362 4362 if ((new_dgid.gid_guid == 0) || ((new_dgid.gid_guid != 0) &&
4363 4363 (new_dgid.gid_guid != cur_dgid.gid_guid))) {
4364 4364
4365 4365 IBTF_DPRINTF_L3(cmlog, "ibt_get_ip_alt_path: DEST: "
4366 4366 "Get Companion PortGids for - %llX:%llX",
4367 4367 cur_dgid.gid_prefix, cur_dgid.gid_guid);
4368 4368
4369 4369 retval = ibcm_get_comp_pgids(cur_dgid, new_dgid, 0, &dgids_p,
4370 4370 &dnum);
4371 4371 if (retval != IBT_SUCCESS)
4372 4372 goto get_ip_alt_path_done;
4373 4373 }
4374 4374
4375 4375 if ((new_dgid.gid_guid == 0) || (new_sgid.gid_guid == 0)) {
4376 4376 if (new_sgid.gid_guid == 0) {
4377 4377 for (i = 0; i < snum; i++) {
4378 4378 if (new_dgid.gid_guid == 0) {
4379 4379 for (j = 0; j < dnum; j++) {
4380 4380 if (sgids_p[i].gid_prefix ==
4381 4381 dgids_p[j].gid_prefix) {
4382 4382 new_dgid = dgids_p[j];
4383 4383 new_sgid = sgids_p[i];
4384 4384
4385 4385 goto get_ip_alt_proceed;
4386 4386 }
4387 4387 }
4388 4388 /* Current DGID */
4389 4389 if (sgids_p[i].gid_prefix ==
4390 4390 cur_dgid.gid_prefix) {
4391 4391 new_sgid = sgids_p[i];
4392 4392 goto get_ip_alt_proceed;
4393 4393 }
4394 4394 } else {
4395 4395 if (sgids_p[i].gid_prefix ==
4396 4396 new_dgid.gid_prefix) {
4397 4397 new_sgid = sgids_p[i];
4398 4398 goto get_ip_alt_proceed;
4399 4399 }
4400 4400 }
4401 4401 }
4402 4402 /* Current SGID */
4403 4403 if (new_dgid.gid_guid == 0) {
4404 4404 for (j = 0; j < dnum; j++) {
4405 4405 if (cur_sgid.gid_prefix ==
4406 4406 dgids_p[j].gid_prefix) {
4407 4407 new_dgid = dgids_p[j];
4408 4408
4409 4409 goto get_ip_alt_proceed;
4410 4410 }
4411 4411 }
4412 4412 }
4413 4413 } else if (new_dgid.gid_guid == 0) {
4414 4414 for (i = 0; i < dnum; i++) {
4415 4415 if (dgids_p[i].gid_prefix ==
4416 4416 new_sgid.gid_prefix) {
4417 4417 new_dgid = dgids_p[i];
4418 4418 goto get_ip_alt_proceed;
4419 4419 }
4420 4420 }
4421 4421 /* Current DGID */
4422 4422 if (cur_dgid.gid_prefix == new_sgid.gid_prefix) {
4423 4423 goto get_ip_alt_proceed;
4424 4424 }
4425 4425 }
4426 4426 /*
4427 4427 * hmm... No Companion Ports available.
4428 4428 * so we will be using current or specified attributes only.
4429 4429 */
4430 4430 }
4431 4431
4432 4432 get_ip_alt_proceed:
4433 4433 if (new_sgid.gid_guid != 0) {
4434 4434 retval = ibtl_cm_get_hca_port(new_sgid, 0, &n_hp);
4435 4435 if (retval != IBT_SUCCESS) {
4436 4436 IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_alt_path: "
4437 4437 "Get HCA Port Failed: %d", retval);
4438 4438 goto get_ip_alt_path_done;
4439 4439 }
4440 4440 }
4441 4441
4442 4442 /* Calculate the size for multi-path records template */
4443 4443 template_len = (2 * sizeof (ib_gid_t)) + sizeof (sa_multipath_record_t);
4444 4444
4445 4445 mpr_req = kmem_zalloc(template_len, KM_SLEEP);
4446 4446
4447 4447 ASSERT(mpr_req != NULL);
4448 4448
4449 4449 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mpr_req))
4450 4450
4451 4451 gid_ptr = (ib_gid_t *)(((uchar_t *)mpr_req) +
4452 4452 sizeof (sa_multipath_record_t));
4453 4453
4454 4454 /* SGID */
4455 4455 if (new_sgid.gid_guid == 0)
4456 4456 *gid_ptr = cur_sgid;
4457 4457 else
4458 4458 *gid_ptr = new_sgid;
4459 4459
4460 4460 IBTF_DPRINTF_L3(cmlog, "ibt_get_ip_alt_path: Get Path Between "
4461 4461 " SGID : %llX:%llX", gid_ptr->gid_prefix, gid_ptr->gid_guid);
4462 4462
4463 4463 gid_ptr++;
4464 4464
4465 4465 /* DGID */
4466 4466 if (new_dgid.gid_guid == 0)
4467 4467 *gid_ptr = cur_dgid;
4468 4468 else
4469 4469 *gid_ptr = new_dgid;
4470 4470
4471 4471 IBTF_DPRINTF_L3(cmlog, "ibt_get_ip_alt_path:\t\t DGID : %llX:%llX",
4472 4472 gid_ptr->gid_prefix, gid_ptr->gid_guid);
4473 4473
4474 4474 mpr_req->SGIDCount = 1;
4475 4475 c_mask = SA_MPR_COMPMASK_SGIDCOUNT;
4476 4476
4477 4477 mpr_req->DGIDCount = 1;
4478 4478 c_mask |= SA_MPR_COMPMASK_DGIDCOUNT;
4479 4479
4480 4480 /* Is Flow Label Specified. */
4481 4481 if (attrp) {
4482 4482 if (attrp->apa_flow) {
4483 4483 mpr_req->FlowLabel = attrp->apa_flow;
4484 4484 c_mask |= SA_MPR_COMPMASK_FLOWLABEL;
4485 4485 }
4486 4486
4487 4487 /* Is HopLimit Specified. */
4488 4488 if (flags & IBT_PATH_HOP) {
4489 4489 mpr_req->HopLimit = attrp->apa_hop;
4490 4490 c_mask |= SA_MPR_COMPMASK_HOPLIMIT;
4491 4491 }
4492 4492
4493 4493 /* Is TClass Specified. */
4494 4494 if (attrp->apa_tclass) {
4495 4495 mpr_req->TClass = attrp->apa_tclass;
4496 4496 c_mask |= SA_MPR_COMPMASK_TCLASS;
4497 4497 }
4498 4498
4499 4499 /* Is SL specified. */
4500 4500 if (attrp->apa_sl) {
4501 4501 mpr_req->SL = attrp->apa_sl;
4502 4502 c_mask |= SA_MPR_COMPMASK_SL;
4503 4503 }
4504 4504
4505 4505 if (flags & IBT_PATH_PERF) {
4506 4506 mpr_req->PacketLifeTimeSelector = IBT_BEST;
4507 4507 mpr_req->RateSelector = IBT_BEST;
4508 4508
4509 4509 c_mask |= SA_MPR_COMPMASK_PKTLTSELECTOR |
4510 4510 SA_MPR_COMPMASK_RATESELECTOR;
4511 4511 } else {
4512 4512 if (attrp->apa_pkt_lt.p_selector == IBT_BEST) {
4513 4513 mpr_req->PacketLifeTimeSelector = IBT_BEST;
4514 4514 c_mask |= SA_MPR_COMPMASK_PKTLTSELECTOR;
4515 4515 }
4516 4516
4517 4517 if (attrp->apa_srate.r_selector == IBT_BEST) {
4518 4518 mpr_req->RateSelector = IBT_BEST;
4519 4519 c_mask |= SA_MPR_COMPMASK_RATESELECTOR;
4520 4520 }
4521 4521 }
4522 4522
4523 4523 /*
4524 4524 * Honor individual selection of these attributes,
4525 4525 * even if IBT_PATH_PERF is set.
4526 4526 */
4527 4527 /* Check out whether Packet Life Time is specified. */
4528 4528 if (attrp->apa_pkt_lt.p_pkt_lt) {
4529 4529 mpr_req->PacketLifeTime =
4530 4530 ibt_usec2ib(attrp->apa_pkt_lt.p_pkt_lt);
4531 4531 mpr_req->PacketLifeTimeSelector =
4532 4532 attrp->apa_pkt_lt.p_selector;
4533 4533
4534 4534 c_mask |= SA_MPR_COMPMASK_PKTLT |
4535 4535 SA_MPR_COMPMASK_PKTLTSELECTOR;
4536 4536 }
4537 4537
4538 4538 /* Is SRATE specified. */
4539 4539 if (attrp->apa_srate.r_srate) {
4540 4540 mpr_req->Rate = attrp->apa_srate.r_srate;
4541 4541 mpr_req->RateSelector = attrp->apa_srate.r_selector;
4542 4542
4543 4543 c_mask |= SA_MPR_COMPMASK_RATE |
4544 4544 SA_MPR_COMPMASK_RATESELECTOR;
4545 4545 }
4546 4546 }
4547 4547
4548 4548 /* Alt PathMTU can be GT or EQU to current channel's Pri PathMTU */
4549 4549
4550 4550 /* P_Key must be same as that of primary path */
4551 4551 retval = ibt_index2pkey_byguid(c_hp.hp_hca_guid, c_hp.hp_port,
4552 4552 qp_attr.qp_info.qp_transport.rc.rc_path.cep_pkey_ix,
4553 4553 &mpr_req->P_Key);
4554 4554 if (retval != IBT_SUCCESS) {
4555 4555 IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_alt_path: PKeyIdx2Pkey "
4556 4556 "Failed: %d", retval);
4557 4557 goto get_ip_alt_path_done;
4558 4558 }
4559 4559 c_mask |= SA_MPR_COMPMASK_PKEY;
4560 4560
4561 4561 mpr_req->Reversible = 1; /* We always get REVERSIBLE paths. */
4562 4562 mpr_req->IndependenceSelector = 1;
4563 4563 c_mask |= SA_MPR_COMPMASK_REVERSIBLE | SA_MPR_COMPMASK_INDEPSEL;
4564 4564
4565 4565 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*mpr_req))
4566 4566
4567 4567 IBTF_DPRINTF_L3(cmlog, "ibt_get_ip_alt_path: CMask: 0x%llX", c_mask);
4568 4568
4569 4569 /* NOTE: We will **NOT** specify how many records we want. */
4570 4570
4571 4571 IBTF_DPRINTF_L3(cmlog, "ibt_get_ip_alt_path: Primary: MTU %d, PKey[%d]="
4572 4572 "0x%X\n\tSGID = %llX:%llX, DGID = %llX:%llX", prim_mtu,
4573 4573 qp_attr.qp_info.qp_transport.rc.rc_path.cep_pkey_ix, mpr_req->P_Key,
4574 4574 cur_sgid.gid_prefix, cur_sgid.gid_guid, cur_dgid.gid_prefix,
4575 4575 cur_dgid.gid_guid);
4576 4576
4577 4577 /* Get SA Access Handle. */
4578 4578 if (new_sgid.gid_guid != 0)
4579 4579 saa_handle = ibcm_get_saa_handle(hcap, n_hp.hp_port);
4580 4580 else
4581 4581 saa_handle = ibcm_get_saa_handle(hcap, c_hp.hp_port);
4582 4582 if (saa_handle == NULL) {
4583 4583 retval = IBT_HCA_PORT_NOT_ACTIVE;
4584 4584 goto get_ip_alt_path_done;
4585 4585 }
4586 4586
4587 4587 /* Contact SA Access to retrieve Path Records. */
4588 4588 access_args.sq_attr_id = SA_MULTIPATHRECORD_ATTRID;
4589 4589 access_args.sq_access_type = IBMF_SAA_RETRIEVE;
4590 4590 access_args.sq_component_mask = c_mask;
4591 4591 access_args.sq_template = mpr_req;
4592 4592 access_args.sq_template_length = sizeof (sa_multipath_record_t);
4593 4593 access_args.sq_callback = NULL;
4594 4594 access_args.sq_callback_arg = NULL;
4595 4595
4596 4596 retval = ibcm_contact_sa_access(saa_handle, &access_args, &length,
4597 4597 &results_p);
4598 4598 if (retval != IBT_SUCCESS) {
4599 4599 goto get_ip_alt_path_done;
4600 4600 }
4601 4601
4602 4602 num_rec = length / sizeof (sa_path_record_t);
4603 4603
4604 4604 kmem_free(mpr_req, template_len);
4605 4605
4606 4606 IBTF_DPRINTF_L3(cmlog, "ibt_get_ip_alt_path: Found %d Paths", num_rec);
4607 4607
4608 4608 rec_found = 0;
4609 4609 if ((results_p != NULL) && (num_rec > 0)) {
4610 4610 /* Update the PathInfo with the response Path Records */
4611 4611 pr_resp = (sa_path_record_t *)results_p;
4612 4612 for (i = 0; i < num_rec; i++, pr_resp++) {
4613 4613 if (prim_mtu > pr_resp->Mtu) {
4614 4614 IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_alt_path: "
4615 4615 "Alt PathMTU(%d) must be GT or EQU to Pri "
4616 4616 "PathMTU(%d). Ignore this rec",
4617 4617 pr_resp->Mtu, prim_mtu);
4618 4618 continue;
4619 4619 }
4620 4620
4621 4621 if ((new_sgid.gid_guid == 0) &&
4622 4622 (new_dgid.gid_guid == 0)) {
4623 4623 /* Reject PathRec if it same as Primary Path. */
4624 4624 if (ibcm_compare_paths(pr_resp,
4625 4625 &qp_attr.qp_info.qp_transport.rc.rc_path,
4626 4626 &c_hp)) {
4627 4627 IBTF_DPRINTF_L3(cmlog,
4628 4628 "ibt_get_ip_alt_path: PathRec "
4629 4629 "obtained is similar to Prim Path, "
4630 4630 "ignore this record");
4631 4631 continue;
4632 4632 }
4633 4633 }
4634 4634
4635 4635 if (new_sgid.gid_guid == 0) {
4636 4636 retval = ibcm_update_cep_info(pr_resp, NULL,
4637 4637 &c_hp, &api_p->ap_alt_cep_path);
4638 4638 } else {
4639 4639 retval = ibcm_update_cep_info(pr_resp, NULL,
4640 4640 &n_hp, &api_p->ap_alt_cep_path);
4641 4641 }
4642 4642 if (retval != IBT_SUCCESS)
4643 4643 continue;
4644 4644
4645 4645 /* Update some leftovers */
4646 4646 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*api_p))
4647 4647
4648 4648 api_p->ap_alt_pkt_lt = pr_resp->PacketLifeTime;
4649 4649
4650 4650 _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*api_p))
4651 4651
4652 4652 rec_found = 1;
4653 4653 break;
4654 4654 }
4655 4655 kmem_free(results_p, length);
4656 4656 }
4657 4657
4658 4658 if (rec_found == 0) {
4659 4659 IBTF_DPRINTF_L3(cmlog, "ibt_get_ip_alt_path: AltPath cannot"
4660 4660 " be established");
4661 4661 retval = IBT_PATH_RECORDS_NOT_FOUND;
4662 4662 } else
4663 4663 retval = IBT_SUCCESS;
4664 4664
4665 4665 get_ip_alt_path_done:
4666 4666 if ((snum) && (sgids_p))
4667 4667 kmem_free(sgids_p, snum * sizeof (ib_gid_t));
4668 4668
4669 4669 if ((dnum) && (dgids_p))
4670 4670 kmem_free(dgids_p, dnum * sizeof (ib_gid_t));
4671 4671
4672 4672 ibcm_dec_hca_acc_cnt(hcap);
4673 4673
4674 4674 IBTF_DPRINTF_L3(cmlog, "ibt_get_ip_alt_path: Done (status %d)", retval);
4675 4675
4676 4676 return (retval);
4677 4677 }
4678 4678
4679 4679
4680 4680 /* Routines for warlock */
4681 4681
4682 4682 /* ARGSUSED */
4683 4683 static void
4684 4684 ibcm_dummy_path_handler(void *arg, ibt_status_t retval, ibt_path_info_t *paths,
4685 4685 uint8_t num_path)
4686 4686 {
4687 4687 ibcm_path_tqargs_t dummy_path;
4688 4688
4689 4689 dummy_path.func = ibcm_dummy_path_handler;
4690 4690
4691 4691 IBTF_DPRINTF_L5(cmlog, "ibcm_dummy_path_handler: "
4692 4692 "dummy_path.func %p", dummy_path.func);
4693 4693 }
4694 4694
4695 4695 /* ARGSUSED */
4696 4696 static void
4697 4697 ibcm_dummy_ip_path_handler(void *arg, ibt_status_t retval,
4698 4698 ibt_path_info_t *paths, uint8_t num_path, ibt_path_ip_src_t *src_ip)
4699 4699 {
4700 4700 ibcm_ip_path_tqargs_t dummy_path;
4701 4701
4702 4702 dummy_path.func = ibcm_dummy_ip_path_handler;
4703 4703
4704 4704 IBTF_DPRINTF_L5(cmlog, "ibcm_dummy_ip_path_handler: "
4705 4705 "dummy_path.func %p", dummy_path.func);
4706 4706 }
↓ open down ↓ |
4485 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX