10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
51495Shiremath * Common Development and Distribution License (the "License").
61495Shiremath * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
2212251SJohnny.Cheung@Sun.COM * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate */
240Sstevel@tonic-gate
250Sstevel@tonic-gate #include <sys/ib/mgt/ibcm/ibcm_impl.h>
264703Shiremath #include <sys/ib/mgt/ibcm/ibcm_arp.h>
270Sstevel@tonic-gate
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate * ibcm_path.c
300Sstevel@tonic-gate *
310Sstevel@tonic-gate * ibt_get_paths() implement the Path Informations related functionality.
320Sstevel@tonic-gate */
330Sstevel@tonic-gate
340Sstevel@tonic-gate /* ibcm_saa_service_rec() fills in ServiceID and DGID. */
350Sstevel@tonic-gate typedef struct ibcm_dest_s {
360Sstevel@tonic-gate ib_gid_t d_gid;
370Sstevel@tonic-gate ib_svc_id_t d_sid;
380Sstevel@tonic-gate ibt_srv_data_t d_sdata;
390Sstevel@tonic-gate ib_pkey_t d_pkey;
409645SShantkumar.Hiremath@Sun.COM uint_t d_tag; /* 0 = Unicast, 1 = Multicast */
410Sstevel@tonic-gate } ibcm_dest_t;
420Sstevel@tonic-gate
430Sstevel@tonic-gate /* Holds Destination information needed to fill in ibt_path_info_t. */
440Sstevel@tonic-gate typedef struct ibcm_dinfo_s {
450Sstevel@tonic-gate uint8_t num_dest;
460Sstevel@tonic-gate ib_pkey_t p_key;
470Sstevel@tonic-gate ibcm_dest_t dest[1];
480Sstevel@tonic-gate } ibcm_dinfo_t;
490Sstevel@tonic-gate
500Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("Temporary path storage", ibcm_dinfo_s))
510Sstevel@tonic-gate _NOTE(READ_ONLY_DATA(ibt_path_attr_s))
520Sstevel@tonic-gate
530Sstevel@tonic-gate typedef struct ibcm_path_tqargs_s {
540Sstevel@tonic-gate ibt_path_attr_t attr;
550Sstevel@tonic-gate ibt_path_info_t *paths;
560Sstevel@tonic-gate uint8_t *num_paths_p;
570Sstevel@tonic-gate ibt_path_handler_t func;
580Sstevel@tonic-gate void *arg;
590Sstevel@tonic-gate ibt_path_flags_t flags;
600Sstevel@tonic-gate uint8_t max_paths;
610Sstevel@tonic-gate } ibcm_path_tqargs_t;
620Sstevel@tonic-gate
630Sstevel@tonic-gate
640Sstevel@tonic-gate /* Prototype Declarations. */
650Sstevel@tonic-gate static ibt_status_t ibcm_saa_path_rec(ibcm_path_tqargs_t *,
660Sstevel@tonic-gate ibtl_cm_port_list_t *, ibcm_dinfo_t *, uint8_t *);
670Sstevel@tonic-gate
680Sstevel@tonic-gate static ibt_status_t ibcm_update_cep_info(sa_path_record_t *,
690Sstevel@tonic-gate ibtl_cm_port_list_t *, ibtl_cm_hca_port_t *, ibt_cep_path_t *);
700Sstevel@tonic-gate
710Sstevel@tonic-gate static ibt_status_t ibcm_saa_service_rec(ibcm_path_tqargs_t *,
720Sstevel@tonic-gate ibtl_cm_port_list_t *, ibcm_dinfo_t *);
730Sstevel@tonic-gate
740Sstevel@tonic-gate static ibt_status_t ibcm_get_single_pathrec(ibcm_path_tqargs_t *,
750Sstevel@tonic-gate ibtl_cm_port_list_t *, ibcm_dinfo_t *, uint8_t,
760Sstevel@tonic-gate uint8_t *, ibt_path_info_t *);
770Sstevel@tonic-gate
780Sstevel@tonic-gate static ibt_status_t ibcm_get_multi_pathrec(ibcm_path_tqargs_t *,
790Sstevel@tonic-gate ibtl_cm_port_list_t *, ibcm_dinfo_t *dinfo,
800Sstevel@tonic-gate uint8_t *, ibt_path_info_t *);
810Sstevel@tonic-gate
820Sstevel@tonic-gate static ibt_status_t ibcm_validate_path_attributes(ibt_path_attr_t *attrp,
830Sstevel@tonic-gate ibt_path_flags_t flags, uint8_t max_paths);
840Sstevel@tonic-gate
850Sstevel@tonic-gate static ibt_status_t ibcm_handle_get_path(ibt_path_attr_t *attrp,
860Sstevel@tonic-gate ibt_path_flags_t flags, uint8_t max_paths, ibt_path_info_t *paths,
870Sstevel@tonic-gate uint8_t *num_path_p, ibt_path_handler_t func, void *arg);
880Sstevel@tonic-gate
890Sstevel@tonic-gate static void ibcm_process_async_get_paths(void *tq_arg);
900Sstevel@tonic-gate
910Sstevel@tonic-gate static ibt_status_t ibcm_process_get_paths(void *tq_arg);
920Sstevel@tonic-gate
930Sstevel@tonic-gate static ibt_status_t ibcm_get_comp_pgids(ib_gid_t, ib_gid_t, ib_guid_t,
940Sstevel@tonic-gate ib_gid_t **, uint_t *);
950Sstevel@tonic-gate
960Sstevel@tonic-gate /*
970Sstevel@tonic-gate * Function:
980Sstevel@tonic-gate * ibt_aget_paths
990Sstevel@tonic-gate * Input:
1000Sstevel@tonic-gate * ibt_hdl The handle returned to the client by the IBTF from an
1010Sstevel@tonic-gate * ibt_attach() call. Can be used by the IBTF Policy module
1020Sstevel@tonic-gate * and CM in the determination of the "best" path to the
1030Sstevel@tonic-gate * specified destination for this class of driver.
1040Sstevel@tonic-gate * flags Path flags.
1050Sstevel@tonic-gate * attrp Points to an ibt_path_attr_t struct that contains
1060Sstevel@tonic-gate * required and optional attributes.
1070Sstevel@tonic-gate * func A pointer to an ibt_path_handler_t function to call
1080Sstevel@tonic-gate * when ibt_aget_paths() completes.
1090Sstevel@tonic-gate * arg The argument to 'func'.
1100Sstevel@tonic-gate * Returns:
1110Sstevel@tonic-gate * IBT_SUCCESS on early validation of attributes else appropriate error.
1120Sstevel@tonic-gate * Description:
1130Sstevel@tonic-gate * Finds the best path to a specified destination or service
1140Sstevel@tonic-gate * asynchronously (as determined by the IBTL) that satisfies the
1150Sstevel@tonic-gate * requirements specified in an ibt_path_attr_t struct.
1160Sstevel@tonic-gate * ibt_aget_paths() is a Non-Blocking version of ibt_get_paths().
1170Sstevel@tonic-gate */
1180Sstevel@tonic-gate ibt_status_t
ibt_aget_paths(ibt_clnt_hdl_t ibt_hdl,ibt_path_flags_t flags,ibt_path_attr_t * attrp,uint8_t max_paths,ibt_path_handler_t func,void * arg)1190Sstevel@tonic-gate ibt_aget_paths(ibt_clnt_hdl_t ibt_hdl, ibt_path_flags_t flags,
1200Sstevel@tonic-gate ibt_path_attr_t *attrp, uint8_t max_paths, ibt_path_handler_t func,
1210Sstevel@tonic-gate void *arg)
1220Sstevel@tonic-gate {
1239349SShantkumar.Hiremath@Sun.COM IBTF_DPRINTF_L3(cmlog, "ibt_aget_paths(%p(%s), 0x%X, %p, %d, %p)",
1249349SShantkumar.Hiremath@Sun.COM ibt_hdl, ibtl_cm_get_clnt_name(ibt_hdl), flags, attrp, max_paths,
1259349SShantkumar.Hiremath@Sun.COM func);
1260Sstevel@tonic-gate
1270Sstevel@tonic-gate if (func == NULL) {
1280Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibt_aget_paths: Function Pointer is "
1290Sstevel@tonic-gate "NULL - ERROR ");
1300Sstevel@tonic-gate return (IBT_INVALID_PARAM);
1310Sstevel@tonic-gate }
1320Sstevel@tonic-gate
1330Sstevel@tonic-gate /* Memory for path info will be allocated in ibcm_process_get_paths() */
1340Sstevel@tonic-gate return (ibcm_handle_get_path(attrp, flags, max_paths, NULL, NULL,
1350Sstevel@tonic-gate func, arg));
1360Sstevel@tonic-gate }
1370Sstevel@tonic-gate
1380Sstevel@tonic-gate
1390Sstevel@tonic-gate /*
140557Shiremath * ibt_get_paths() cache consists of one or more of:
141557Shiremath *
142557Shiremath * ib_gid_t dgid (attrp->pa_dgids[0])
143557Shiremath * ibt_path_attr_t attr
144557Shiremath * ibt_path_flags_t flags
145557Shiremath * ibt_path_info_t path
146557Shiremath *
147557Shiremath * If the first 3 match, max_paths is 1, sname is NULL, and sid is 0,
148557Shiremath * then the path is returned immediately.
149557Shiremath *
150557Shiremath * Note that a compare of "attr" is non-trivial. Only accept ones
151557Shiremath * that memcmp() succeeds, i.e., basically assume a bzero was done.
152557Shiremath *
153557Shiremath * Cache must be invalidated if PORT_DOWN event or GID_UNAVAIL occurs.
154557Shiremath * Cache must be freed as part of _fini.
155557Shiremath */
156557Shiremath
157557Shiremath #define IBCM_PATH_CACHE_SIZE 16 /* keep small for linear search */
158557Shiremath #define IBCM_PATH_CACHE_TIMEOUT 60 /* purge cache after 60 seconds */
159557Shiremath
160557Shiremath typedef struct ibcm_path_cache_s {
161557Shiremath ib_gid_t dgid;
162557Shiremath ibt_path_attr_t attr;
163557Shiremath ibt_path_flags_t flags;
164557Shiremath ibt_path_info_t path;
165557Shiremath } ibcm_path_cache_t;
166557Shiremath
167557Shiremath kmutex_t ibcm_path_cache_mutex;
168557Shiremath int ibcm_path_cache_invalidate; /* invalidate cache on next ibt_get_paths */
169557Shiremath clock_t ibcm_path_cache_timeout = IBCM_PATH_CACHE_TIMEOUT; /* tunable */
170557Shiremath timeout_id_t ibcm_path_cache_timeout_id;
171557Shiremath int ibcm_path_cache_size_init = IBCM_PATH_CACHE_SIZE; /* tunable */
172557Shiremath int ibcm_path_cache_size;
173557Shiremath ibcm_path_cache_t *ibcm_path_cachep;
174557Shiremath
1759349SShantkumar.Hiremath@Sun.COM /* tunable, set to 1 to not allow link-local address */
1769349SShantkumar.Hiremath@Sun.COM int ibcm_ip6_linklocal_addr_ok = 0;
1779349SShantkumar.Hiremath@Sun.COM
178557Shiremath struct ibcm_path_cache_stat_s {
179557Shiremath int hits;
180557Shiremath int misses;
181557Shiremath int adds;
182557Shiremath int already_in_cache;
183557Shiremath int bad_path_for_cache;
184557Shiremath int purges;
185557Shiremath int timeouts;
186557Shiremath } ibcm_path_cache_stats;
187557Shiremath
188557Shiremath /*ARGSUSED*/
189557Shiremath static void
ibcm_path_cache_timeout_cb(void * arg)190557Shiremath ibcm_path_cache_timeout_cb(void *arg)
191557Shiremath {
192557Shiremath clock_t timeout_in_hz;
193557Shiremath
194557Shiremath timeout_in_hz = drv_usectohz(ibcm_path_cache_timeout * 1000000);
195557Shiremath mutex_enter(&ibcm_path_cache_mutex);
196557Shiremath ibcm_path_cache_invalidate = 1; /* invalidate cache on next check */
197557Shiremath if (ibcm_path_cache_timeout_id)
198557Shiremath ibcm_path_cache_timeout_id = timeout(ibcm_path_cache_timeout_cb,
199557Shiremath NULL, timeout_in_hz);
200557Shiremath /* else we're in _fini */
201557Shiremath mutex_exit(&ibcm_path_cache_mutex);
202557Shiremath }
203557Shiremath
204557Shiremath void
ibcm_path_cache_init(void)205557Shiremath ibcm_path_cache_init(void)
206557Shiremath {
207557Shiremath clock_t timeout_in_hz;
208557Shiremath int cache_size = ibcm_path_cache_size_init;
209557Shiremath ibcm_path_cache_t *path_cachep;
210557Shiremath
211557Shiremath timeout_in_hz = drv_usectohz(ibcm_path_cache_timeout * 1000000);
212557Shiremath path_cachep = kmem_zalloc(cache_size * sizeof (*path_cachep), KM_SLEEP);
2134703Shiremath mutex_init(&ibcm_path_cache_mutex, NULL, MUTEX_DEFAULT, NULL);
214557Shiremath mutex_enter(&ibcm_path_cache_mutex);
215557Shiremath ibcm_path_cache_size = cache_size;
216557Shiremath ibcm_path_cachep = path_cachep;
217557Shiremath ibcm_path_cache_timeout_id = timeout(ibcm_path_cache_timeout_cb,
218557Shiremath NULL, timeout_in_hz);
219557Shiremath mutex_exit(&ibcm_path_cache_mutex);
220557Shiremath }
221557Shiremath
222557Shiremath void
ibcm_path_cache_fini(void)223557Shiremath ibcm_path_cache_fini(void)
224557Shiremath {
225557Shiremath timeout_id_t tmp_timeout_id;
226557Shiremath int cache_size;
227557Shiremath ibcm_path_cache_t *path_cachep;
228557Shiremath
229557Shiremath mutex_enter(&ibcm_path_cache_mutex);
230557Shiremath if (ibcm_path_cache_timeout_id) {
231557Shiremath tmp_timeout_id = ibcm_path_cache_timeout_id;
232557Shiremath ibcm_path_cache_timeout_id = 0; /* no more timeouts */
233557Shiremath }
234557Shiremath cache_size = ibcm_path_cache_size;
235557Shiremath path_cachep = ibcm_path_cachep;
236557Shiremath mutex_exit(&ibcm_path_cache_mutex);
237557Shiremath if (tmp_timeout_id)
238557Shiremath (void) untimeout(tmp_timeout_id);
239557Shiremath mutex_destroy(&ibcm_path_cache_mutex);
240557Shiremath kmem_free(path_cachep, cache_size * sizeof (*path_cachep));
241557Shiremath }
242557Shiremath
243557Shiremath static ibcm_status_t
ibcm_path_cache_check(ibt_path_flags_t flags,ibt_path_attr_t * attrp,uint8_t max_paths,ibt_path_info_t * path,uint8_t * num_paths_p)244557Shiremath ibcm_path_cache_check(ibt_path_flags_t flags, ibt_path_attr_t *attrp,
245557Shiremath uint8_t max_paths, ibt_path_info_t *path, uint8_t *num_paths_p)
246557Shiremath {
247557Shiremath int i;
248557Shiremath ib_gid_t dgid;
249557Shiremath ibcm_path_cache_t *path_cachep;
250557Shiremath
251557Shiremath if (max_paths != 1 || attrp->pa_num_dgids != 1 ||
252557Shiremath attrp->pa_sname != NULL || attrp->pa_sid != 0) {
253557Shiremath mutex_enter(&ibcm_path_cache_mutex);
254557Shiremath ibcm_path_cache_stats.bad_path_for_cache++;
255557Shiremath mutex_exit(&ibcm_path_cache_mutex);
256557Shiremath return (IBCM_FAILURE);
257557Shiremath }
258557Shiremath
259557Shiremath dgid = attrp->pa_dgids[0];
260557Shiremath if ((dgid.gid_guid | dgid.gid_prefix) == 0ULL)
261557Shiremath return (IBCM_FAILURE);
262557Shiremath
263557Shiremath mutex_enter(&ibcm_path_cache_mutex);
264557Shiremath if (ibcm_path_cache_invalidate) { /* invalidate all entries */
265557Shiremath ibcm_path_cache_stats.timeouts++;
266557Shiremath ibcm_path_cache_invalidate = 0;
267557Shiremath path_cachep = ibcm_path_cachep;
268557Shiremath for (i = 0; i < ibcm_path_cache_size; i++, path_cachep++) {
269557Shiremath path_cachep->dgid.gid_guid = 0ULL;
270557Shiremath path_cachep->dgid.gid_prefix = 0ULL;
271557Shiremath }
272557Shiremath mutex_exit(&ibcm_path_cache_mutex);
273557Shiremath return (IBCM_FAILURE);
274557Shiremath }
275557Shiremath
276557Shiremath path_cachep = ibcm_path_cachep;
277557Shiremath for (i = 0; i < ibcm_path_cache_size; i++, path_cachep++) {
278557Shiremath if (path_cachep->dgid.gid_guid == 0ULL)
279557Shiremath break; /* end of search, no more valid cache entries */
280557Shiremath
281557Shiremath /* make pa_dgids pointers match, so we can use memcmp */
282557Shiremath path_cachep->attr.pa_dgids = attrp->pa_dgids;
283557Shiremath if (path_cachep->flags != flags ||
284557Shiremath path_cachep->dgid.gid_guid != dgid.gid_guid ||
285557Shiremath path_cachep->dgid.gid_prefix != dgid.gid_prefix ||
286557Shiremath memcmp(&(path_cachep->attr), attrp, sizeof (*attrp)) != 0) {
287557Shiremath /* make pa_dgids NULL again */
288557Shiremath path_cachep->attr.pa_dgids = NULL;
289557Shiremath continue;
290557Shiremath }
291557Shiremath /* else we have a match */
292557Shiremath /* make pa_dgids NULL again */
293557Shiremath path_cachep->attr.pa_dgids = NULL;
294557Shiremath *path = path_cachep->path; /* retval */
295557Shiremath if (num_paths_p)
296557Shiremath *num_paths_p = 1; /* retval */
297557Shiremath ibcm_path_cache_stats.hits++;
298557Shiremath mutex_exit(&ibcm_path_cache_mutex);
299557Shiremath return (IBCM_SUCCESS);
300557Shiremath }
301557Shiremath ibcm_path_cache_stats.misses++;
302557Shiremath mutex_exit(&ibcm_path_cache_mutex);
303557Shiremath return (IBCM_FAILURE);
304557Shiremath }
305557Shiremath
306557Shiremath static void
ibcm_path_cache_add(ibt_path_flags_t flags,ibt_path_attr_t * attrp,uint8_t max_paths,ibt_path_info_t * path)307557Shiremath ibcm_path_cache_add(ibt_path_flags_t flags,
308557Shiremath ibt_path_attr_t *attrp, uint8_t max_paths, ibt_path_info_t *path)
309557Shiremath {
310557Shiremath int i;
311557Shiremath ib_gid_t dgid;
312557Shiremath ibcm_path_cache_t *path_cachep;
313557Shiremath
314557Shiremath if (max_paths != 1 || attrp->pa_num_dgids != 1 ||
315557Shiremath attrp->pa_sname != NULL || attrp->pa_sid != 0)
316557Shiremath return;
317557Shiremath
318557Shiremath dgid = attrp->pa_dgids[0];
319557Shiremath if ((dgid.gid_guid | dgid.gid_prefix) == 0ULL)
320557Shiremath return;
321557Shiremath
322557Shiremath mutex_enter(&ibcm_path_cache_mutex);
323557Shiremath path_cachep = ibcm_path_cachep;
324557Shiremath for (i = 0; i < ibcm_path_cache_size; i++, path_cachep++) {
325557Shiremath path_cachep->attr.pa_dgids = attrp->pa_dgids;
326557Shiremath if (path_cachep->flags == flags &&
327557Shiremath path_cachep->dgid.gid_guid == dgid.gid_guid &&
328557Shiremath path_cachep->dgid.gid_prefix == dgid.gid_prefix &&
329557Shiremath memcmp(&(path_cachep->attr), attrp, sizeof (*attrp)) == 0) {
330557Shiremath /* already in cache */
331557Shiremath ibcm_path_cache_stats.already_in_cache++;
332557Shiremath path_cachep->attr.pa_dgids = NULL;
333557Shiremath mutex_exit(&ibcm_path_cache_mutex);
334557Shiremath return;
335557Shiremath }
336557Shiremath if (path_cachep->dgid.gid_guid != 0ULL) {
337557Shiremath path_cachep->attr.pa_dgids = NULL;
338557Shiremath continue;
339557Shiremath }
340557Shiremath /* else the rest of the entries are free, so use this one */
341557Shiremath ibcm_path_cache_stats.adds++;
342557Shiremath path_cachep->flags = flags;
343557Shiremath path_cachep->attr = *attrp;
344557Shiremath path_cachep->attr.pa_dgids = NULL;
345557Shiremath path_cachep->dgid = attrp->pa_dgids[0];
346557Shiremath path_cachep->path = *path;
347557Shiremath mutex_exit(&ibcm_path_cache_mutex);
348557Shiremath return;
349557Shiremath }
350557Shiremath mutex_exit(&ibcm_path_cache_mutex);
351557Shiremath }
352557Shiremath
353557Shiremath void
ibcm_path_cache_purge(void)354557Shiremath ibcm_path_cache_purge(void)
355557Shiremath {
356557Shiremath mutex_enter(&ibcm_path_cache_mutex);
357557Shiremath ibcm_path_cache_invalidate = 1; /* invalidate cache on next check */
358557Shiremath ibcm_path_cache_stats.purges++;
359557Shiremath mutex_exit(&ibcm_path_cache_mutex);
360557Shiremath }
361557Shiremath
362557Shiremath /*
3630Sstevel@tonic-gate * Function:
3640Sstevel@tonic-gate * ibt_get_paths
3650Sstevel@tonic-gate * Input:
3660Sstevel@tonic-gate * ibt_hdl The handle returned to the client by the IBTF from an
3670Sstevel@tonic-gate * ibt_attach() call. Can be used by the IBTF Policy module
3680Sstevel@tonic-gate * and CM in the determination of the "best" path to the
3690Sstevel@tonic-gate * specified destination for this class of driver.
3700Sstevel@tonic-gate * flags Path flags.
3710Sstevel@tonic-gate * attrp Points to an ibt_path_attr_t struct that contains
3720Sstevel@tonic-gate * required and optional attributes.
3730Sstevel@tonic-gate * max_paths The size of the "paths" array argument. Also, this
3740Sstevel@tonic-gate * is the limit on the number of paths returned.
3750Sstevel@tonic-gate * max_paths indicates the number of requested paths to
3760Sstevel@tonic-gate * the specified destination(s).
3770Sstevel@tonic-gate * Output:
3780Sstevel@tonic-gate * paths An array of ibt_path_info_t structs filled in by
3790Sstevel@tonic-gate * ibt_get_paths() as output parameters. Upon return,
3800Sstevel@tonic-gate * array elements with non-NULL HCA GUIDs are valid.
3810Sstevel@tonic-gate * num_paths_p If non-NULL, return the actual number of paths found.
3820Sstevel@tonic-gate * Returns:
3830Sstevel@tonic-gate * IBT_SUCCESS on Success else appropriate error.
3840Sstevel@tonic-gate * Description:
3850Sstevel@tonic-gate * Finds the best path to a specified destination (as determined by the
3860Sstevel@tonic-gate * IBTL) that satisfies the requirements specified in an ibt_path_attr_t
3870Sstevel@tonic-gate * struct.
3880Sstevel@tonic-gate *
3890Sstevel@tonic-gate * This routine can not be called from interrupt context.
3900Sstevel@tonic-gate */
3910Sstevel@tonic-gate ibt_status_t
ibt_get_paths(ibt_clnt_hdl_t ibt_hdl,ibt_path_flags_t flags,ibt_path_attr_t * attrp,uint8_t max_paths,ibt_path_info_t * paths,uint8_t * num_paths_p)3920Sstevel@tonic-gate ibt_get_paths(ibt_clnt_hdl_t ibt_hdl, ibt_path_flags_t flags,
3930Sstevel@tonic-gate ibt_path_attr_t *attrp, uint8_t max_paths, ibt_path_info_t *paths,
3940Sstevel@tonic-gate uint8_t *num_paths_p)
3950Sstevel@tonic-gate {
396557Shiremath ibt_status_t retval;
397557Shiremath
3980Sstevel@tonic-gate ASSERT(paths != NULL);
3990Sstevel@tonic-gate
4009349SShantkumar.Hiremath@Sun.COM IBTF_DPRINTF_L3(cmlog, "ibt_get_paths(%p(%s), 0x%X, %p, %d)",
4019349SShantkumar.Hiremath@Sun.COM ibt_hdl, ibtl_cm_get_clnt_name(ibt_hdl), flags, attrp, max_paths);
4020Sstevel@tonic-gate
4030Sstevel@tonic-gate if (paths == NULL) {
4040Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibt_get_paths: Path Info Pointer is "
4050Sstevel@tonic-gate "NULL - ERROR ");
4060Sstevel@tonic-gate return (IBT_INVALID_PARAM);
4070Sstevel@tonic-gate }
4080Sstevel@tonic-gate
4090Sstevel@tonic-gate if (num_paths_p != NULL)
4100Sstevel@tonic-gate *num_paths_p = 0;
4110Sstevel@tonic-gate
412557Shiremath if (ibcm_path_cache_check(flags, attrp, max_paths, paths,
413557Shiremath num_paths_p) == IBCM_SUCCESS)
414557Shiremath return (IBT_SUCCESS);
415557Shiremath
416557Shiremath retval = ibcm_handle_get_path(attrp, flags, max_paths, paths,
417557Shiremath num_paths_p, NULL, NULL);
418557Shiremath
419557Shiremath if (retval == IBT_SUCCESS)
420557Shiremath ibcm_path_cache_add(flags, attrp, max_paths, paths);
421557Shiremath return (retval);
4220Sstevel@tonic-gate }
4230Sstevel@tonic-gate
4240Sstevel@tonic-gate
4250Sstevel@tonic-gate static ibt_status_t
ibcm_handle_get_path(ibt_path_attr_t * attrp,ibt_path_flags_t flags,uint8_t max_paths,ibt_path_info_t * paths,uint8_t * num_path_p,ibt_path_handler_t func,void * arg)4260Sstevel@tonic-gate ibcm_handle_get_path(ibt_path_attr_t *attrp, ibt_path_flags_t flags,
4270Sstevel@tonic-gate uint8_t max_paths, ibt_path_info_t *paths, uint8_t *num_path_p,
4280Sstevel@tonic-gate ibt_path_handler_t func, void *arg)
4290Sstevel@tonic-gate {
4300Sstevel@tonic-gate ibcm_path_tqargs_t *path_tq;
4310Sstevel@tonic-gate int sleep_flag = ((func == NULL) ? KM_SLEEP : KM_NOSLEEP);
4320Sstevel@tonic-gate int len;
4330Sstevel@tonic-gate ibt_status_t retval;
4340Sstevel@tonic-gate
4350Sstevel@tonic-gate retval = ibcm_validate_path_attributes(attrp, flags, max_paths);
4360Sstevel@tonic-gate if (retval != IBT_SUCCESS)
4370Sstevel@tonic-gate return (retval);
4380Sstevel@tonic-gate
4390Sstevel@tonic-gate len = (attrp->pa_num_dgids * sizeof (ib_gid_t)) +
4400Sstevel@tonic-gate sizeof (ibcm_path_tqargs_t);
4410Sstevel@tonic-gate
4420Sstevel@tonic-gate path_tq = kmem_alloc(len, sleep_flag);
4430Sstevel@tonic-gate if (path_tq == NULL) {
4440Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_handle_get_path: "
4450Sstevel@tonic-gate "Unable to allocate memory for local usage.");
4460Sstevel@tonic-gate return (IBT_INSUFF_KERNEL_RESOURCE);
4470Sstevel@tonic-gate }
4480Sstevel@tonic-gate
4490Sstevel@tonic-gate _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*path_tq))
4500Sstevel@tonic-gate
4510Sstevel@tonic-gate bcopy(attrp, &path_tq->attr, sizeof (ibt_path_attr_t));
4520Sstevel@tonic-gate
4530Sstevel@tonic-gate if (attrp->pa_num_dgids) {
4540Sstevel@tonic-gate path_tq->attr.pa_dgids = (ib_gid_t *)(((uchar_t *)path_tq) +
4550Sstevel@tonic-gate sizeof (ibcm_path_tqargs_t));
4560Sstevel@tonic-gate
4570Sstevel@tonic-gate bcopy(attrp->pa_dgids, path_tq->attr.pa_dgids,
4580Sstevel@tonic-gate sizeof (ib_gid_t) * attrp->pa_num_dgids);
4590Sstevel@tonic-gate } else {
4600Sstevel@tonic-gate path_tq->attr.pa_dgids = NULL;
4610Sstevel@tonic-gate }
4620Sstevel@tonic-gate
4630Sstevel@tonic-gate /* Ignore IBT_PATH_AVAIL flag, if only one path is requested. */
4640Sstevel@tonic-gate if ((flags & IBT_PATH_AVAIL) && (max_paths == 1)) {
4650Sstevel@tonic-gate flags &= ~IBT_PATH_AVAIL;
4660Sstevel@tonic-gate
4670Sstevel@tonic-gate IBTF_DPRINTF_L4(cmlog, "ibcm_handle_get_path: "
4680Sstevel@tonic-gate "Ignoring IBT_PATH_AVAIL flag, as only ONE path "
4690Sstevel@tonic-gate "information is requested.");
4700Sstevel@tonic-gate }
4710Sstevel@tonic-gate
4720Sstevel@tonic-gate path_tq->flags = flags;
4730Sstevel@tonic-gate path_tq->max_paths = max_paths;
4740Sstevel@tonic-gate path_tq->paths = paths;
4750Sstevel@tonic-gate path_tq->num_paths_p = num_path_p;
4760Sstevel@tonic-gate path_tq->func = func;
4770Sstevel@tonic-gate path_tq->arg = arg;
4780Sstevel@tonic-gate
4790Sstevel@tonic-gate _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*path_tq))
4800Sstevel@tonic-gate
4810Sstevel@tonic-gate if (func != NULL) { /* Non-Blocking */
4820Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_handle_get_path: Non Blocking");
4830Sstevel@tonic-gate if (taskq_dispatch(ibcm_taskq, ibcm_process_async_get_paths,
4840Sstevel@tonic-gate path_tq, TQ_NOSLEEP) == 0) {
4850Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_handle_get_path: "
4860Sstevel@tonic-gate "Failed to dispatch the TaskQ");
4870Sstevel@tonic-gate kmem_free(path_tq, len);
4880Sstevel@tonic-gate return (IBT_INSUFF_KERNEL_RESOURCE);
4890Sstevel@tonic-gate } else
4900Sstevel@tonic-gate return (IBT_SUCCESS);
4910Sstevel@tonic-gate } else { /* Blocking */
4920Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_handle_get_path: Blocking");
4930Sstevel@tonic-gate return (ibcm_process_get_paths(path_tq));
4940Sstevel@tonic-gate }
4950Sstevel@tonic-gate }
4960Sstevel@tonic-gate
4970Sstevel@tonic-gate
4980Sstevel@tonic-gate static void
ibcm_process_async_get_paths(void * tq_arg)4990Sstevel@tonic-gate ibcm_process_async_get_paths(void *tq_arg)
5000Sstevel@tonic-gate {
5010Sstevel@tonic-gate (void) ibcm_process_get_paths(tq_arg);
5020Sstevel@tonic-gate }
5030Sstevel@tonic-gate
5040Sstevel@tonic-gate
5050Sstevel@tonic-gate static ibt_status_t
ibcm_validate_path_attributes(ibt_path_attr_t * attrp,ibt_path_flags_t flags,uint8_t max_paths)5060Sstevel@tonic-gate ibcm_validate_path_attributes(ibt_path_attr_t *attrp, ibt_path_flags_t flags,
5070Sstevel@tonic-gate uint8_t max_paths)
5080Sstevel@tonic-gate {
5090Sstevel@tonic-gate uint_t i;
5100Sstevel@tonic-gate
5110Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: Inputs are: "
5120Sstevel@tonic-gate "HCA (%llX, %d),\n\tSGID(%llX:%llX), SName=\"%s\",\n\tSID= %llX, "
5130Sstevel@tonic-gate "Maxpath= %d, Flags= 0x%X, #Dgid= %d, SDFlag= 0x%llX",
5140Sstevel@tonic-gate attrp->pa_hca_guid, attrp->pa_hca_port_num,
5150Sstevel@tonic-gate attrp->pa_sgid.gid_prefix, attrp->pa_sgid.gid_guid,
5160Sstevel@tonic-gate ((attrp->pa_sname != NULL) ? attrp->pa_sname : ""), attrp->pa_sid,
5170Sstevel@tonic-gate max_paths, flags, attrp->pa_num_dgids, attrp->pa_sd_flags);
5180Sstevel@tonic-gate
5190Sstevel@tonic-gate /*
5200Sstevel@tonic-gate * Validate Path Flags.
5210Sstevel@tonic-gate * IBT_PATH_AVAIL & IBT_PATH_PERF are mutually exclusive.
5220Sstevel@tonic-gate */
5230Sstevel@tonic-gate if ((flags & IBT_PATH_AVAIL) && (flags & IBT_PATH_PERF)) {
5240Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: "
5250Sstevel@tonic-gate "Invalid Flags: 0x%X,\n\t AVAIL and PERF flags cannot "
5260Sstevel@tonic-gate "specified together.", flags);
5270Sstevel@tonic-gate return (IBT_INVALID_PARAM);
5280Sstevel@tonic-gate }
5290Sstevel@tonic-gate
5300Sstevel@tonic-gate /* Validate number of records requested. */
5310Sstevel@tonic-gate if ((flags & (IBT_PATH_AVAIL | IBT_PATH_PERF)) &&
5320Sstevel@tonic-gate (max_paths > IBT_MAX_SPECIAL_PATHS)) {
5330Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: "
5340Sstevel@tonic-gate "Max records that can be requested is <%d> \n"
5350Sstevel@tonic-gate "when IBT_PATH_AVAIL or IBT_PATH_PERF flag is specified.",
5360Sstevel@tonic-gate IBT_MAX_SPECIAL_PATHS);
5370Sstevel@tonic-gate return (IBT_INVALID_PARAM);
5380Sstevel@tonic-gate }
5390Sstevel@tonic-gate
5400Sstevel@tonic-gate /* Only 2 destinations can be specified w/ APM flag. */
5410Sstevel@tonic-gate if ((flags & IBT_PATH_APM) && (attrp->pa_num_dgids > 2)) {
5420Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes:\n\t Max "
5430Sstevel@tonic-gate "number of DGIDs that can be specified w/APM flag is 2");
5440Sstevel@tonic-gate return (IBT_INVALID_PARAM);
5450Sstevel@tonic-gate }
5460Sstevel@tonic-gate
5470Sstevel@tonic-gate /*
5480Sstevel@tonic-gate * Max_paths of "0" is invalid.
5490Sstevel@tonic-gate * w/ IBT_PATH_MULTI_SVC_DEST flag, max_paths must be greater than "1".
5500Sstevel@tonic-gate */
5510Sstevel@tonic-gate if ((max_paths == 0) ||
5520Sstevel@tonic-gate ((flags & IBT_PATH_MULTI_SVC_DEST) && (max_paths < 2))) {
5530Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: "
5540Sstevel@tonic-gate "Invalid number of records requested:\n flags 0x%X, "
5550Sstevel@tonic-gate "max_paths %d", flags, max_paths);
5560Sstevel@tonic-gate return (IBT_INVALID_PARAM);
5570Sstevel@tonic-gate }
5580Sstevel@tonic-gate
5590Sstevel@tonic-gate /*
5600Sstevel@tonic-gate * If IBT_PATH_MULTI_SVC_DEST is set, then ServiceName and/or Service ID
5610Sstevel@tonic-gate * must be specified and DGIDs SHOULD NOT be specified.
5620Sstevel@tonic-gate */
5630Sstevel@tonic-gate if ((flags & IBT_PATH_MULTI_SVC_DEST) && ((attrp->pa_num_dgids > 0) ||
5640Sstevel@tonic-gate ((attrp->pa_sid == 0) && ((attrp->pa_sname == NULL) ||
5650Sstevel@tonic-gate ((attrp->pa_sname != NULL) && (strlen(attrp->pa_sname) == 0)))))) {
5660Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: "
5670Sstevel@tonic-gate "Invalid Flags: 0x%X, IBT_PATH_MULTI_SVC_DEST flag set "
5680Sstevel@tonic-gate "but Service Name \n or Service ID NOT specified or DGIDs "
5690Sstevel@tonic-gate "are specified.", flags);
5700Sstevel@tonic-gate return (IBT_INVALID_PARAM);
5710Sstevel@tonic-gate }
5720Sstevel@tonic-gate
5730Sstevel@tonic-gate /*
5740Sstevel@tonic-gate * User need to specify the destination information, which can be
5750Sstevel@tonic-gate * provided as one or more of the following.
5760Sstevel@tonic-gate * o ServiceName
5770Sstevel@tonic-gate * o ServiceID
5780Sstevel@tonic-gate * o Array of DGIDs w/Num of DGIDs, (max of 2)
5790Sstevel@tonic-gate */
5800Sstevel@tonic-gate if ((attrp->pa_sid == 0) && (attrp->pa_num_dgids == 0) &&
5810Sstevel@tonic-gate ((attrp->pa_sname == NULL) || ((attrp->pa_sname != NULL) &&
5820Sstevel@tonic-gate (strlen(attrp->pa_sname) == 0)))) {
5830Sstevel@tonic-gate /* Destination information not provided, bail out. */
5840Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: "
5850Sstevel@tonic-gate "Client's MUST supply DestInfo.");
5860Sstevel@tonic-gate return (IBT_INVALID_PARAM);
5870Sstevel@tonic-gate }
5880Sstevel@tonic-gate
5890Sstevel@tonic-gate /* If DGIDs are provided, validate them. */
5900Sstevel@tonic-gate if (attrp->pa_num_dgids > 0) {
5910Sstevel@tonic-gate if (attrp->pa_dgids == NULL) {
5920Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: "
5930Sstevel@tonic-gate "pa_dgids NULL, but pa_num_dgids : %d",
5940Sstevel@tonic-gate attrp->pa_num_dgids);
5950Sstevel@tonic-gate return (IBT_INVALID_PARAM);
5960Sstevel@tonic-gate }
5970Sstevel@tonic-gate
5980Sstevel@tonic-gate /* Validate DGIDs */
5990Sstevel@tonic-gate for (i = 0; i < attrp->pa_num_dgids; i++) {
6000Sstevel@tonic-gate ib_gid_t gid = attrp->pa_dgids[i];
6010Sstevel@tonic-gate
6021495Shiremath IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: "
6030Sstevel@tonic-gate "DGID[%d] = %llX:%llX", i, gid.gid_prefix,
6040Sstevel@tonic-gate gid.gid_guid);
6050Sstevel@tonic-gate
6060Sstevel@tonic-gate /* APM request for MultiCast destination is invalid. */
6070Sstevel@tonic-gate if ((gid.gid_prefix >> 56ULL & 0xFF) == 0xFF) {
6080Sstevel@tonic-gate if (flags & IBT_PATH_APM) {
6090Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog,
6100Sstevel@tonic-gate "ibcm_validate_path_attributes: "
6110Sstevel@tonic-gate "APM for MGIDs not supported.");
6120Sstevel@tonic-gate return (IBT_INVALID_PARAM);
6130Sstevel@tonic-gate }
6140Sstevel@tonic-gate } else if ((gid.gid_prefix == 0) ||
6150Sstevel@tonic-gate (gid.gid_guid == 0)) {
6160Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog,
6170Sstevel@tonic-gate "ibcm_validate_path_attributes: ERROR: "
6180Sstevel@tonic-gate "Invalid DGIDs specified");
6190Sstevel@tonic-gate return (IBT_INVALID_PARAM);
6200Sstevel@tonic-gate }
6210Sstevel@tonic-gate }
6220Sstevel@tonic-gate }
6230Sstevel@tonic-gate
6240Sstevel@tonic-gate /* Check for valid Service Name length. */
6250Sstevel@tonic-gate if ((attrp->pa_sname != NULL) &&
6260Sstevel@tonic-gate (strlen(attrp->pa_sname) >= IB_SVC_NAME_LEN)) {
6270Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: "
6280Sstevel@tonic-gate "ServiceName too long");
6290Sstevel@tonic-gate return (IBT_INVALID_PARAM);
6300Sstevel@tonic-gate }
6310Sstevel@tonic-gate
6320Sstevel@tonic-gate /* If P_Key is specified, check for invalid p_key's */
6330Sstevel@tonic-gate if (flags & IBT_PATH_PKEY) {
6340Sstevel@tonic-gate /* Limited P_Key is NOT supported as of now!. */
6350Sstevel@tonic-gate if ((attrp->pa_pkey == IB_PKEY_INVALID_FULL) ||
6360Sstevel@tonic-gate (attrp->pa_pkey & 0x8000) == 0) {
6370Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_validate_path_attributes: "
6380Sstevel@tonic-gate "Specified P_Key is invalid: 0x%X", attrp->pa_pkey);
6390Sstevel@tonic-gate return (IBT_INVALID_PARAM);
6400Sstevel@tonic-gate }
6410Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_validate_path_attributes: "
6420Sstevel@tonic-gate "P_Key= 0x%X", attrp->pa_pkey);
6430Sstevel@tonic-gate }
6440Sstevel@tonic-gate
6450Sstevel@tonic-gate return (IBT_SUCCESS);
6460Sstevel@tonic-gate }
6470Sstevel@tonic-gate
6480Sstevel@tonic-gate
6490Sstevel@tonic-gate static ibt_status_t
ibcm_process_get_paths(void * tq_arg)6500Sstevel@tonic-gate ibcm_process_get_paths(void *tq_arg)
6510Sstevel@tonic-gate {
6520Sstevel@tonic-gate ibcm_path_tqargs_t *p_arg = (ibcm_path_tqargs_t *)tq_arg;
6530Sstevel@tonic-gate ibcm_dinfo_t *dinfo;
6540Sstevel@tonic-gate int len;
6550Sstevel@tonic-gate uint8_t max_paths, num_path;
6560Sstevel@tonic-gate ibt_status_t retval;
6570Sstevel@tonic-gate ib_gid_t *d_gids_p = NULL;
6580Sstevel@tonic-gate ibtl_cm_port_list_t *slistp = NULL;
65911951SShantkumar.Hiremath@Sun.COM uint_t dnum = 0;
66011951SShantkumar.Hiremath@Sun.COM uint8_t num_dest, i, j;
6610Sstevel@tonic-gate ibcm_hca_info_t *hcap;
6620Sstevel@tonic-gate ibmf_saa_handle_t saa_handle;
6630Sstevel@tonic-gate
6640Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_paths(%p, 0x%X, %d) ",
6650Sstevel@tonic-gate p_arg, p_arg->flags, p_arg->max_paths);
6660Sstevel@tonic-gate
6670Sstevel@tonic-gate max_paths = num_path = p_arg->max_paths;
6680Sstevel@tonic-gate
6690Sstevel@tonic-gate /*
6700Sstevel@tonic-gate * Prepare the Destination list based on the input DGIDs and
6710Sstevel@tonic-gate * other attributes.
6720Sstevel@tonic-gate *
6730Sstevel@tonic-gate * APM is requested and pa_dgids are specified. If multiple DGIDs are
6740Sstevel@tonic-gate * specified, check out whether they are companion to each other or if
6750Sstevel@tonic-gate * only one DGID is specified, then get the companion port GID for that.
6760Sstevel@tonic-gate */
6770Sstevel@tonic-gate if (p_arg->attr.pa_num_dgids) {
6780Sstevel@tonic-gate if (p_arg->flags & IBT_PATH_APM) {
6790Sstevel@tonic-gate ib_gid_t c_gid, n_gid;
6800Sstevel@tonic-gate
6810Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_paths: "
6820Sstevel@tonic-gate "DGIDs specified w/ APM Flag");
6830Sstevel@tonic-gate
6840Sstevel@tonic-gate c_gid = p_arg->attr.pa_dgids[0];
6850Sstevel@tonic-gate if (p_arg->attr.pa_num_dgids > 1)
6860Sstevel@tonic-gate n_gid = p_arg->attr.pa_dgids[1];
6870Sstevel@tonic-gate else
6880Sstevel@tonic-gate n_gid.gid_prefix = n_gid.gid_guid = 0;
6890Sstevel@tonic-gate
6900Sstevel@tonic-gate retval = ibcm_get_comp_pgids(c_gid, n_gid, 0, &d_gids_p,
6910Sstevel@tonic-gate &dnum);
6920Sstevel@tonic-gate if ((retval != IBT_SUCCESS) &&
6930Sstevel@tonic-gate (retval != IBT_GIDS_NOT_FOUND)) {
6940Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths:"
6950Sstevel@tonic-gate " Invalid DGIDs specified w/ APM Flag");
6964460Shiremath goto path_error2;
6970Sstevel@tonic-gate }
6980Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_paths: "
6990Sstevel@tonic-gate "Found %d Comp DGID", dnum);
7000Sstevel@tonic-gate }
7010Sstevel@tonic-gate
7020Sstevel@tonic-gate if (dnum) {
7030Sstevel@tonic-gate len = 1;
7040Sstevel@tonic-gate } else {
7050Sstevel@tonic-gate len = p_arg->attr.pa_num_dgids - 1;
7060Sstevel@tonic-gate }
7070Sstevel@tonic-gate num_dest = len + 1;
7080Sstevel@tonic-gate
7090Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_paths: #dgid %d, dnum "
7100Sstevel@tonic-gate "%d, #dest %d", p_arg->attr.pa_num_dgids, dnum, num_dest);
7110Sstevel@tonic-gate } else {
7120Sstevel@tonic-gate if (p_arg->flags & IBT_PATH_MULTI_SVC_DEST) {
7130Sstevel@tonic-gate IBTF_DPRINTF_L4(cmlog, "ibcm_process_get_paths: "
7140Sstevel@tonic-gate "IBT_PATH_MULTI_SVC_DEST flags set");
7150Sstevel@tonic-gate len = max_paths - 1;
7160Sstevel@tonic-gate } else if (p_arg->flags & IBT_PATH_APM) {
7170Sstevel@tonic-gate len = 1;
7180Sstevel@tonic-gate } else {
7190Sstevel@tonic-gate len = 0;
7200Sstevel@tonic-gate }
7210Sstevel@tonic-gate num_dest = 0;
7220Sstevel@tonic-gate }
7230Sstevel@tonic-gate
7240Sstevel@tonic-gate /* Allocate memory and accumulate all destination information */
7250Sstevel@tonic-gate len = (len * sizeof (ibcm_dest_t)) + sizeof (ibcm_dinfo_t);
7260Sstevel@tonic-gate
7270Sstevel@tonic-gate dinfo = kmem_zalloc(len, KM_SLEEP);
7280Sstevel@tonic-gate dinfo->num_dest = num_dest;
7290Sstevel@tonic-gate if (p_arg->flags & IBT_PATH_PKEY)
7300Sstevel@tonic-gate dinfo->p_key = p_arg->attr.pa_pkey;
7310Sstevel@tonic-gate
7320Sstevel@tonic-gate for (i = 0, j = 0; i < num_dest; i++) {
7330Sstevel@tonic-gate if (i < p_arg->attr.pa_num_dgids)
7340Sstevel@tonic-gate dinfo->dest[i].d_gid = p_arg->attr.pa_dgids[i];
7350Sstevel@tonic-gate else
7360Sstevel@tonic-gate dinfo->dest[i].d_gid = d_gids_p[j++];
7370Sstevel@tonic-gate }
7380Sstevel@tonic-gate
7390Sstevel@tonic-gate _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*p_arg))
7400Sstevel@tonic-gate
7410Sstevel@tonic-gate /* IBTF allocates memory for path_info in case of Async Get Paths */
7420Sstevel@tonic-gate if (p_arg->paths == NULL)
7430Sstevel@tonic-gate p_arg->paths = kmem_zalloc(sizeof (ibt_path_info_t) * max_paths,
7440Sstevel@tonic-gate KM_SLEEP);
7450Sstevel@tonic-gate
7460Sstevel@tonic-gate _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*p_arg))
7470Sstevel@tonic-gate
7484703Shiremath /*
7494703Shiremath * Get list of active HCA<->Port list, that matches input specified attr
7504703Shiremath */
7514703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_paths: Get Paths from \n HCA "
7524703Shiremath "(%llX:%d), SGID %llX:%llX", p_arg->attr.pa_hca_guid,
7534703Shiremath p_arg->attr.pa_hca_port_num, p_arg->attr.pa_sgid.gid_prefix,
7544703Shiremath p_arg->attr.pa_sgid.gid_guid);
7554703Shiremath
7564703Shiremath retval = ibtl_cm_get_active_plist(&p_arg->attr, p_arg->flags, &slistp);
7574703Shiremath if (retval != IBT_SUCCESS) {
7584703Shiremath IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths: HCA capable of "
7594703Shiremath "requested source attributes NOT available.");
7604703Shiremath goto path_error;
7610Sstevel@tonic-gate }
7620Sstevel@tonic-gate
7630Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_paths: HCA (%llX, %d)",
7640Sstevel@tonic-gate slistp->p_hca_guid, slistp->p_port_num);
7650Sstevel@tonic-gate
7660Sstevel@tonic-gate hcap = ibcm_find_hca_entry(slistp->p_hca_guid);
7670Sstevel@tonic-gate if (hcap == NULL) {
7680Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths: "
7690Sstevel@tonic-gate "NO HCA found");
7700Sstevel@tonic-gate retval = IBT_HCA_BUSY_DETACHING;
7710Sstevel@tonic-gate goto path_error;
7720Sstevel@tonic-gate }
7730Sstevel@tonic-gate
7740Sstevel@tonic-gate /* Get SA Access Handle. */
7750Sstevel@tonic-gate for (i = 0; i < slistp->p_count; i++) {
7760Sstevel@tonic-gate if (i == 0) {
7770Sstevel@tonic-gate /* Validate whether this HCA supports APM */
7780Sstevel@tonic-gate if ((p_arg->flags & IBT_PATH_APM) &&
7790Sstevel@tonic-gate (!(hcap->hca_caps & IBT_HCA_AUTO_PATH_MIG))) {
7800Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths:"
7810Sstevel@tonic-gate " HCA (%llX): APM NOT SUPPORTED ",
7820Sstevel@tonic-gate slistp[i].p_hca_guid);
7830Sstevel@tonic-gate retval = IBT_APM_NOT_SUPPORTED;
7840Sstevel@tonic-gate goto path_error1;
7850Sstevel@tonic-gate }
7860Sstevel@tonic-gate }
7870Sstevel@tonic-gate
7880Sstevel@tonic-gate saa_handle = ibcm_get_saa_handle(hcap, slistp[i].p_port_num);
7890Sstevel@tonic-gate if (saa_handle == NULL) {
7900Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths: "
7910Sstevel@tonic-gate "SAA HDL NULL, HCA (%llX:%d) NOT ACTIVE",
7920Sstevel@tonic-gate slistp[i].p_hca_guid, slistp[i].p_port_num);
7930Sstevel@tonic-gate retval = IBT_HCA_PORT_NOT_ACTIVE;
7940Sstevel@tonic-gate goto path_error1;
7950Sstevel@tonic-gate }
7960Sstevel@tonic-gate _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*slistp))
7970Sstevel@tonic-gate slistp[i].p_saa_hdl = saa_handle;
7980Sstevel@tonic-gate _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*slistp))
7990Sstevel@tonic-gate }
8000Sstevel@tonic-gate
8010Sstevel@tonic-gate /*
8020Sstevel@tonic-gate * If Service Name or Service ID are specified, first retrieve
8030Sstevel@tonic-gate * Service Records.
8040Sstevel@tonic-gate */
8050Sstevel@tonic-gate if ((p_arg->attr.pa_sid != 0) || ((p_arg->attr.pa_sname != NULL) &&
8060Sstevel@tonic-gate (strlen(p_arg->attr.pa_sname) != 0))) {
8070Sstevel@tonic-gate
8080Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_paths: Get Service "
8090Sstevel@tonic-gate "Record for \n\t(%llX, \"%s\")", p_arg->attr.pa_sid,
8100Sstevel@tonic-gate ((p_arg->attr.pa_sname != NULL) ?
8110Sstevel@tonic-gate p_arg->attr.pa_sname : ""));
8120Sstevel@tonic-gate
8130Sstevel@tonic-gate /* Get Service Records. */
8140Sstevel@tonic-gate retval = ibcm_saa_service_rec(p_arg, slistp, dinfo);
8150Sstevel@tonic-gate if ((retval != IBT_SUCCESS) && (retval != IBT_INSUFF_DATA)) {
8160Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths: Status="
8170Sstevel@tonic-gate "%d, Failed to get Service Record for \n\t"
8180Sstevel@tonic-gate "(%llX, \"%s\")", retval, p_arg->attr.pa_sid,
8190Sstevel@tonic-gate ((p_arg->attr.pa_sname != NULL) ?
8200Sstevel@tonic-gate p_arg->attr.pa_sname : ""));
8210Sstevel@tonic-gate goto path_error1;
8220Sstevel@tonic-gate }
8230Sstevel@tonic-gate }
8240Sstevel@tonic-gate
8250Sstevel@tonic-gate /* Get Path Records. */
8260Sstevel@tonic-gate retval = ibcm_saa_path_rec(p_arg, slistp, dinfo, &num_path);
8270Sstevel@tonic-gate
8280Sstevel@tonic-gate path_error1:
8290Sstevel@tonic-gate ibcm_dec_hca_acc_cnt(hcap);
8300Sstevel@tonic-gate
8310Sstevel@tonic-gate path_error:
8320Sstevel@tonic-gate if (slistp)
8330Sstevel@tonic-gate ibtl_cm_free_active_plist(slistp);
8340Sstevel@tonic-gate
8350Sstevel@tonic-gate if (dinfo)
8360Sstevel@tonic-gate kmem_free(dinfo, len);
8370Sstevel@tonic-gate
8380Sstevel@tonic-gate path_error2:
8390Sstevel@tonic-gate if ((retval != IBT_SUCCESS) && (retval != IBT_INSUFF_DATA))
8400Sstevel@tonic-gate num_path = 0;
8410Sstevel@tonic-gate
8420Sstevel@tonic-gate if (p_arg->num_paths_p != NULL)
8430Sstevel@tonic-gate *p_arg->num_paths_p = num_path;
8440Sstevel@tonic-gate
8450Sstevel@tonic-gate if ((dnum) && (d_gids_p))
8460Sstevel@tonic-gate kmem_free(d_gids_p, dnum * sizeof (ib_gid_t));
8470Sstevel@tonic-gate
8480Sstevel@tonic-gate if (p_arg->func) { /* Do these only for Async Get Paths */
8490Sstevel@tonic-gate ibt_path_info_t *tmp_path_p;
8500Sstevel@tonic-gate
8510Sstevel@tonic-gate if (retval == IBT_INSUFF_DATA) {
8520Sstevel@tonic-gate /*
8530Sstevel@tonic-gate * We allocated earlier memory based on "max_paths",
8540Sstevel@tonic-gate * but we got lesser path-records, so re-adjust that
8550Sstevel@tonic-gate * buffer so that caller can free the correct memory.
8560Sstevel@tonic-gate */
8570Sstevel@tonic-gate tmp_path_p = kmem_alloc(
8580Sstevel@tonic-gate sizeof (ibt_path_info_t) * num_path, KM_SLEEP);
8590Sstevel@tonic-gate
8600Sstevel@tonic-gate bcopy(p_arg->paths, tmp_path_p,
8610Sstevel@tonic-gate num_path * sizeof (ibt_path_info_t));
8620Sstevel@tonic-gate
8630Sstevel@tonic-gate kmem_free(p_arg->paths,
8640Sstevel@tonic-gate sizeof (ibt_path_info_t) * max_paths);
8650Sstevel@tonic-gate } else if (retval != IBT_SUCCESS) {
8660Sstevel@tonic-gate if (p_arg->paths)
8670Sstevel@tonic-gate kmem_free(p_arg->paths,
8680Sstevel@tonic-gate sizeof (ibt_path_info_t) * max_paths);
8690Sstevel@tonic-gate tmp_path_p = NULL;
8700Sstevel@tonic-gate } else {
8710Sstevel@tonic-gate tmp_path_p = p_arg->paths;
8720Sstevel@tonic-gate }
8730Sstevel@tonic-gate (*(p_arg->func))(p_arg->arg, retval, tmp_path_p, num_path);
8740Sstevel@tonic-gate }
8750Sstevel@tonic-gate
8760Sstevel@tonic-gate len = (sizeof (ib_gid_t) * p_arg->attr.pa_num_dgids) +
8770Sstevel@tonic-gate sizeof (ibcm_path_tqargs_t);
8780Sstevel@tonic-gate
8790Sstevel@tonic-gate if (p_arg && len)
8800Sstevel@tonic-gate kmem_free(p_arg, len);
8810Sstevel@tonic-gate
8820Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_paths: done: status %d, "
8830Sstevel@tonic-gate "Found %d/%d Path Records", retval, num_path, max_paths);
8840Sstevel@tonic-gate
8850Sstevel@tonic-gate return (retval);
8860Sstevel@tonic-gate }
8870Sstevel@tonic-gate
8880Sstevel@tonic-gate
8890Sstevel@tonic-gate /*
8900Sstevel@tonic-gate * Perform SA Access to retrieve Path Records.
8910Sstevel@tonic-gate */
8920Sstevel@tonic-gate static ibt_status_t
ibcm_saa_path_rec(ibcm_path_tqargs_t * p_arg,ibtl_cm_port_list_t * sl,ibcm_dinfo_t * dinfo,uint8_t * max_count)8930Sstevel@tonic-gate ibcm_saa_path_rec(ibcm_path_tqargs_t *p_arg, ibtl_cm_port_list_t *sl,
8940Sstevel@tonic-gate ibcm_dinfo_t *dinfo, uint8_t *max_count)
8950Sstevel@tonic-gate {
8960Sstevel@tonic-gate uint8_t num_path = *max_count;
8970Sstevel@tonic-gate uint8_t num_path_plus;
89811951SShantkumar.Hiremath@Sun.COM uint8_t extra, idx, rec_found = 0;
8990Sstevel@tonic-gate ibt_status_t retval = IBT_SUCCESS;
9000Sstevel@tonic-gate int unicast_dgid_present = 0;
9010Sstevel@tonic-gate uint8_t i;
9020Sstevel@tonic-gate
9030Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec(%p, %p, %p, 0x%X, %d)",
9040Sstevel@tonic-gate p_arg, sl, dinfo, p_arg->flags, *max_count);
9050Sstevel@tonic-gate
9060Sstevel@tonic-gate if ((dinfo->num_dest == 0) || (num_path == 0) || (sl == NULL)) {
9070Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec: Invalid Counters");
9080Sstevel@tonic-gate return (IBT_INVALID_PARAM);
9090Sstevel@tonic-gate }
9100Sstevel@tonic-gate
9110Sstevel@tonic-gate /*
9120Sstevel@tonic-gate * Of the total needed "X" number of paths to "Y" number of destination
9130Sstevel@tonic-gate * we need to get X/Y plus X%Y extra paths to each destination,
9140Sstevel@tonic-gate * We do this so that we can choose the required number of path records
9150Sstevel@tonic-gate * for the specific destination.
9160Sstevel@tonic-gate */
9170Sstevel@tonic-gate num_path /= dinfo->num_dest;
9180Sstevel@tonic-gate extra = (*max_count % dinfo->num_dest);
9190Sstevel@tonic-gate
9200Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec: numpath %d extra %d dest %d",
9210Sstevel@tonic-gate num_path, extra, dinfo->num_dest);
9220Sstevel@tonic-gate
9239645SShantkumar.Hiremath@Sun.COM /* Find out whether we need to get PathRecord for a MGID as DGID. */
9240Sstevel@tonic-gate for (idx = 0; idx < dinfo->num_dest; idx++) {
9250Sstevel@tonic-gate ib_gid_t dgid = dinfo->dest[idx].d_gid;
9260Sstevel@tonic-gate
9270Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec: DGID[%d]: %llX:%llX",
9280Sstevel@tonic-gate idx, dgid.gid_prefix, dgid.gid_guid);
9290Sstevel@tonic-gate
9300Sstevel@tonic-gate if ((dgid.gid_prefix >> 56ULL & 0xFF) == 0xFF) {
931401Shiremath if (extra)
9320Sstevel@tonic-gate num_path_plus = num_path + 1;
933401Shiremath else
9340Sstevel@tonic-gate num_path_plus = num_path;
9350Sstevel@tonic-gate
9360Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec: Get %d Paths"
9370Sstevel@tonic-gate "- MGID(%016llX%016llX)", num_path_plus,
9380Sstevel@tonic-gate dgid.gid_prefix, dgid.gid_guid);
9390Sstevel@tonic-gate
9400Sstevel@tonic-gate dinfo->dest[idx].d_tag = 1; /* MultiCast */
9410Sstevel@tonic-gate
9420Sstevel@tonic-gate /* Yes, it's Single PathRec query for MGID as DGID. */
9430Sstevel@tonic-gate retval = ibcm_get_single_pathrec(p_arg, sl, dinfo, idx,
9440Sstevel@tonic-gate &num_path_plus, &p_arg->paths[rec_found]);
9450Sstevel@tonic-gate if ((retval != IBT_SUCCESS) &&
9460Sstevel@tonic-gate (retval != IBT_INSUFF_DATA)) {
9470Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec: "
9480Sstevel@tonic-gate "Failed to get PathRec for MGID %d",
9490Sstevel@tonic-gate retval);
9500Sstevel@tonic-gate continue;
9510Sstevel@tonic-gate }
952401Shiremath if (extra)
953401Shiremath extra--;
9540Sstevel@tonic-gate
9550Sstevel@tonic-gate rec_found += num_path_plus;
9560Sstevel@tonic-gate }
9570Sstevel@tonic-gate if (rec_found == *max_count)
9580Sstevel@tonic-gate break;
9590Sstevel@tonic-gate }
9600Sstevel@tonic-gate
9610Sstevel@tonic-gate for (i = 0; i < dinfo->num_dest; i++) {
9620Sstevel@tonic-gate if (dinfo->dest[i].d_tag == 0) {
9630Sstevel@tonic-gate unicast_dgid_present++;
9640Sstevel@tonic-gate }
9650Sstevel@tonic-gate }
9660Sstevel@tonic-gate
9670Sstevel@tonic-gate num_path_plus = *max_count - rec_found;
9680Sstevel@tonic-gate
9690Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec: Recfound: %d, need to find "
9700Sstevel@tonic-gate "%d, UniCastGID present %d", rec_found, num_path_plus,
9710Sstevel@tonic-gate unicast_dgid_present);
9720Sstevel@tonic-gate
9730Sstevel@tonic-gate if ((unicast_dgid_present != 0) && (num_path_plus > 0)) {
974401Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec: MultiSM=%X, #SRC=%d,"
975401Shiremath "Dest%d", sl->p_multi, sl->p_count, unicast_dgid_present);
976401Shiremath
977401Shiremath if ((sl->p_multi != IBTL_CM_SIMPLE_SETUP) ||
9780Sstevel@tonic-gate ((unicast_dgid_present == 1) && (sl->p_count == 1))) {
9790Sstevel@tonic-gate /*
9800Sstevel@tonic-gate * Use SinglePathRec if we are dealing w/ MultiSM or
9810Sstevel@tonic-gate * request is for one SGID to one DGID.
9820Sstevel@tonic-gate */
9830Sstevel@tonic-gate retval = ibcm_get_single_pathrec(p_arg, sl, dinfo, 0xFF,
9840Sstevel@tonic-gate &num_path_plus, &p_arg->paths[rec_found]);
9850Sstevel@tonic-gate } else {
9867354SGiri.Adari@Sun.COM uint8_t old_num_path_plus = num_path_plus;
9877354SGiri.Adari@Sun.COM
9880Sstevel@tonic-gate /* MultiPathRec will be used for other queries. */
9890Sstevel@tonic-gate retval = ibcm_get_multi_pathrec(p_arg, sl, dinfo,
9900Sstevel@tonic-gate &num_path_plus, &p_arg->paths[rec_found]);
9917354SGiri.Adari@Sun.COM if ((retval != IBT_SUCCESS) &&
9927354SGiri.Adari@Sun.COM (retval != IBT_INSUFF_DATA) &&
9937354SGiri.Adari@Sun.COM (sl->p_count > 0) &&
9947354SGiri.Adari@Sun.COM (dinfo->num_dest > 0)) {
9957354SGiri.Adari@Sun.COM ibtl_cm_port_list_t sl_tmp = *sl;
9967354SGiri.Adari@Sun.COM ibcm_dinfo_t dinfo_tmp = *dinfo;
9977354SGiri.Adari@Sun.COM
9987354SGiri.Adari@Sun.COM sl_tmp.p_count = 1;
9997354SGiri.Adari@Sun.COM dinfo_tmp.num_dest = 1;
10007354SGiri.Adari@Sun.COM num_path_plus = old_num_path_plus;
10017354SGiri.Adari@Sun.COM retval = ibcm_get_single_pathrec(p_arg, &sl_tmp,
10027354SGiri.Adari@Sun.COM &dinfo_tmp, 0xFF, &num_path_plus,
10037354SGiri.Adari@Sun.COM &p_arg->paths[rec_found]);
10047354SGiri.Adari@Sun.COM }
10050Sstevel@tonic-gate }
10060Sstevel@tonic-gate if ((retval != IBT_SUCCESS) && (retval != IBT_INSUFF_DATA)) {
10070Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_saa_path_rec: "
10080Sstevel@tonic-gate "Failed to get PathRec: Status %d", retval);
10090Sstevel@tonic-gate } else {
10100Sstevel@tonic-gate rec_found += num_path_plus;
10110Sstevel@tonic-gate }
10120Sstevel@tonic-gate }
10130Sstevel@tonic-gate
10141495Shiremath if (rec_found == 0) {
10151495Shiremath if (retval == IBT_SUCCESS)
10161495Shiremath retval = IBT_PATH_RECORDS_NOT_FOUND;
10171495Shiremath } else if (rec_found != *max_count)
10180Sstevel@tonic-gate retval = IBT_INSUFF_DATA;
1019401Shiremath else if (rec_found != 0)
1020401Shiremath retval = IBT_SUCCESS;
10210Sstevel@tonic-gate
10220Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_path_rec: done. Status = %d, "
10230Sstevel@tonic-gate "Found %d/%d Paths", retval, rec_found, *max_count);
10240Sstevel@tonic-gate
10250Sstevel@tonic-gate *max_count = rec_found; /* Update the return count. */
10260Sstevel@tonic-gate
10270Sstevel@tonic-gate return (retval);
10280Sstevel@tonic-gate }
10290Sstevel@tonic-gate
10300Sstevel@tonic-gate ibt_status_t
ibcm_contact_sa_access(ibmf_saa_handle_t saa_handle,ibmf_saa_access_args_t * access_args,size_t * length,void ** results_p)10310Sstevel@tonic-gate ibcm_contact_sa_access(ibmf_saa_handle_t saa_handle,
10320Sstevel@tonic-gate ibmf_saa_access_args_t *access_args, size_t *length, void **results_p)
10330Sstevel@tonic-gate {
10340Sstevel@tonic-gate int retry;
10350Sstevel@tonic-gate int sa_retval;
10360Sstevel@tonic-gate
10370Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_contact_sa_access(%p, %p)",
10380Sstevel@tonic-gate saa_handle, access_args);
10390Sstevel@tonic-gate
10400Sstevel@tonic-gate ibcm_sa_access_enter();
10410Sstevel@tonic-gate
10420Sstevel@tonic-gate for (retry = 0; retry < ibcm_max_sa_retries; retry++) {
10430Sstevel@tonic-gate sa_retval = ibmf_sa_access(saa_handle, access_args, 0,
10440Sstevel@tonic-gate length, results_p);
10450Sstevel@tonic-gate if (sa_retval != IBMF_TRANS_TIMEOUT)
10460Sstevel@tonic-gate break;
10470Sstevel@tonic-gate
10480Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_contact_sa_access: "
10490Sstevel@tonic-gate "ibmf_sa_access() - Timed Out (%d)", sa_retval);
10500Sstevel@tonic-gate delay(ibcm_sa_timeout_delay);
10510Sstevel@tonic-gate }
10520Sstevel@tonic-gate
10530Sstevel@tonic-gate ibcm_sa_access_exit();
10540Sstevel@tonic-gate
10550Sstevel@tonic-gate if ((sa_retval == IBMF_SUCCESS) || (sa_retval == IBMF_NO_RECORDS) ||
10560Sstevel@tonic-gate (sa_retval == IBMF_REQ_INVALID)) {
10570Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_contact_sa_access: "
10580Sstevel@tonic-gate "ibmf_sa_access() returned (%d)", sa_retval);
10590Sstevel@tonic-gate return (IBT_SUCCESS);
10600Sstevel@tonic-gate } else {
10610Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_contact_sa_access: "
10620Sstevel@tonic-gate "ibmf_sa_access(): Failed (%d)", sa_retval);
10630Sstevel@tonic-gate return (ibcm_ibmf_analyze_error(sa_retval));
10640Sstevel@tonic-gate }
10650Sstevel@tonic-gate }
10660Sstevel@tonic-gate
10670Sstevel@tonic-gate
10680Sstevel@tonic-gate static ibt_status_t
ibcm_update_pri(sa_path_record_t * pr_resp,ibtl_cm_port_list_t * sl,ibcm_dinfo_t * dinfo,ibt_path_info_t * paths)10690Sstevel@tonic-gate ibcm_update_pri(sa_path_record_t *pr_resp, ibtl_cm_port_list_t *sl,
10700Sstevel@tonic-gate ibcm_dinfo_t *dinfo, ibt_path_info_t *paths)
10710Sstevel@tonic-gate {
10720Sstevel@tonic-gate ibt_status_t retval = IBT_SUCCESS;
10730Sstevel@tonic-gate int d, s;
10740Sstevel@tonic-gate
10750Sstevel@tonic-gate retval = ibcm_update_cep_info(pr_resp, sl, NULL,
10760Sstevel@tonic-gate &paths->pi_prim_cep_path);
10770Sstevel@tonic-gate if (retval != IBT_SUCCESS)
10780Sstevel@tonic-gate return (retval);
10790Sstevel@tonic-gate
10800Sstevel@tonic-gate /* Update some leftovers */
10810Sstevel@tonic-gate paths->pi_prim_pkt_lt = pr_resp->PacketLifeTime;
10820Sstevel@tonic-gate paths->pi_path_mtu = pr_resp->Mtu;
10830Sstevel@tonic-gate
10840Sstevel@tonic-gate for (d = 0; d < dinfo->num_dest; d++) {
10850Sstevel@tonic-gate if (pr_resp->DGID.gid_guid == dinfo->dest[d].d_gid.gid_guid) {
10860Sstevel@tonic-gate paths->pi_sid = dinfo->dest[d].d_sid;
10870Sstevel@tonic-gate if (paths->pi_sid != 0) {
10880Sstevel@tonic-gate bcopy(&dinfo->dest[d].d_sdata,
10890Sstevel@tonic-gate &paths->pi_sdata, sizeof (ibt_srv_data_t));
10900Sstevel@tonic-gate }
10910Sstevel@tonic-gate break;
10920Sstevel@tonic-gate }
10930Sstevel@tonic-gate }
10940Sstevel@tonic-gate
10950Sstevel@tonic-gate for (s = 0; s < sl->p_count; s++) {
10960Sstevel@tonic-gate if (pr_resp->SGID.gid_guid == sl[s].p_sgid.gid_guid) {
10970Sstevel@tonic-gate paths->pi_hca_guid = sl[s].p_hca_guid;
10980Sstevel@tonic-gate }
10990Sstevel@tonic-gate }
11000Sstevel@tonic-gate
11010Sstevel@tonic-gate /* Set Alternate Path to invalid state. */
11020Sstevel@tonic-gate paths->pi_alt_cep_path.cep_hca_port_num = 0;
11030Sstevel@tonic-gate paths->pi_alt_cep_path.cep_adds_vect.av_dlid = 0;
11040Sstevel@tonic-gate
11050Sstevel@tonic-gate IBTF_DPRINTF_L5(cmlog, "Path: HCA GUID = 0x%llX", paths->pi_hca_guid);
11060Sstevel@tonic-gate IBTF_DPRINTF_L5(cmlog, "Path: ServiceID = 0x%llX", paths->pi_sid);
11070Sstevel@tonic-gate
11080Sstevel@tonic-gate return (retval);
11090Sstevel@tonic-gate }
11100Sstevel@tonic-gate
11110Sstevel@tonic-gate
11120Sstevel@tonic-gate static ibt_status_t
ibcm_get_single_pathrec(ibcm_path_tqargs_t * p_arg,ibtl_cm_port_list_t * sl,ibcm_dinfo_t * dinfo,uint8_t idx,uint8_t * num_path,ibt_path_info_t * paths)11130Sstevel@tonic-gate ibcm_get_single_pathrec(ibcm_path_tqargs_t *p_arg, ibtl_cm_port_list_t *sl,
11140Sstevel@tonic-gate ibcm_dinfo_t *dinfo, uint8_t idx, uint8_t *num_path, ibt_path_info_t *paths)
11150Sstevel@tonic-gate {
11160Sstevel@tonic-gate sa_path_record_t pathrec_req;
11170Sstevel@tonic-gate sa_path_record_t *pr_resp;
11180Sstevel@tonic-gate ibmf_saa_access_args_t access_args;
11190Sstevel@tonic-gate uint64_t c_mask = 0;
11200Sstevel@tonic-gate void *results_p;
11210Sstevel@tonic-gate uint8_t num_rec;
11220Sstevel@tonic-gate size_t length;
11230Sstevel@tonic-gate ibt_status_t retval;
11240Sstevel@tonic-gate int i, j, k;
112511951SShantkumar.Hiremath@Sun.COM uint8_t found, p_fnd;
11260Sstevel@tonic-gate ibt_path_attr_t *attrp = &p_arg->attr;
11270Sstevel@tonic-gate ibmf_saa_handle_t saa_handle;
11280Sstevel@tonic-gate
11290Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_get_single_pathrec(%p, %p, %p, %d)",
11300Sstevel@tonic-gate p_arg, sl, dinfo, *num_path);
11310Sstevel@tonic-gate
11320Sstevel@tonic-gate bzero(&pathrec_req, sizeof (sa_path_record_t));
11330Sstevel@tonic-gate
11340Sstevel@tonic-gate /* Is Flow Label Specified. */
11350Sstevel@tonic-gate if (attrp->pa_flow) {
11360Sstevel@tonic-gate pathrec_req.FlowLabel = attrp->pa_flow;
11370Sstevel@tonic-gate c_mask |= SA_PR_COMPMASK_FLOWLABEL;
11380Sstevel@tonic-gate }
11390Sstevel@tonic-gate
11400Sstevel@tonic-gate /* Is HopLimit Specified. */
11410Sstevel@tonic-gate if (p_arg->flags & IBT_PATH_HOP) {
11420Sstevel@tonic-gate pathrec_req.HopLimit = attrp->pa_hop;
11430Sstevel@tonic-gate c_mask |= SA_PR_COMPMASK_HOPLIMIT;
11440Sstevel@tonic-gate }
11450Sstevel@tonic-gate
11460Sstevel@tonic-gate /* Is P_Key Specified. */
11470Sstevel@tonic-gate if (dinfo->p_key) {
11480Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_get_single_pathrec: "
11490Sstevel@tonic-gate "Specified or Global PKEY 0x%X", dinfo->p_key);
11500Sstevel@tonic-gate pathrec_req.P_Key = dinfo->p_key;
11510Sstevel@tonic-gate c_mask |= SA_PR_COMPMASK_PKEY;
11520Sstevel@tonic-gate }
11530Sstevel@tonic-gate
11540Sstevel@tonic-gate /* Is TClass Specified. */
11550Sstevel@tonic-gate if (attrp->pa_tclass) {
11560Sstevel@tonic-gate pathrec_req.TClass = attrp->pa_tclass;
11570Sstevel@tonic-gate c_mask |= SA_PR_COMPMASK_TCLASS;
11580Sstevel@tonic-gate }
11590Sstevel@tonic-gate
11600Sstevel@tonic-gate /* Is SL specified. */
11610Sstevel@tonic-gate if (attrp->pa_sl) {
11620Sstevel@tonic-gate pathrec_req.SL = attrp->pa_sl;
11630Sstevel@tonic-gate c_mask |= SA_PR_COMPMASK_SL;
11640Sstevel@tonic-gate }
11650Sstevel@tonic-gate
11660Sstevel@tonic-gate /* If IBT_PATH_PERF is set, then mark all selectors to BEST. */
11670Sstevel@tonic-gate if (p_arg->flags & IBT_PATH_PERF) {
11680Sstevel@tonic-gate pathrec_req.PacketLifeTimeSelector = IBT_BEST;
11690Sstevel@tonic-gate pathrec_req.MtuSelector = IBT_BEST;
11700Sstevel@tonic-gate pathrec_req.RateSelector = IBT_BEST;
11710Sstevel@tonic-gate
11720Sstevel@tonic-gate c_mask |= SA_PR_COMPMASK_PKTLTSELECTOR |
11730Sstevel@tonic-gate SA_PR_COMPMASK_RATESELECTOR | SA_PR_COMPMASK_MTUSELECTOR;
11740Sstevel@tonic-gate } else {
11750Sstevel@tonic-gate if (attrp->pa_pkt_lt.p_selector == IBT_BEST) {
11760Sstevel@tonic-gate pathrec_req.PacketLifeTimeSelector = IBT_BEST;
11770Sstevel@tonic-gate c_mask |= SA_PR_COMPMASK_PKTLTSELECTOR;
11780Sstevel@tonic-gate }
11790Sstevel@tonic-gate
11800Sstevel@tonic-gate if (attrp->pa_srate.r_selector == IBT_BEST) {
11810Sstevel@tonic-gate pathrec_req.RateSelector = IBT_BEST;
11820Sstevel@tonic-gate c_mask |= SA_PR_COMPMASK_RATESELECTOR;
11830Sstevel@tonic-gate }
11840Sstevel@tonic-gate
11850Sstevel@tonic-gate if (attrp->pa_mtu.r_selector == IBT_BEST) {
11860Sstevel@tonic-gate pathrec_req.MtuSelector = IBT_BEST;
11870Sstevel@tonic-gate c_mask |= SA_PR_COMPMASK_MTUSELECTOR;
11880Sstevel@tonic-gate }
11890Sstevel@tonic-gate }
11900Sstevel@tonic-gate
11910Sstevel@tonic-gate /*
11920Sstevel@tonic-gate * Honor individual selection of these attributes,
11930Sstevel@tonic-gate * even if IBT_PATH_PERF is set.
11940Sstevel@tonic-gate */
11950Sstevel@tonic-gate /* Check out whether Packet Life Time is specified. */
11960Sstevel@tonic-gate if (attrp->pa_pkt_lt.p_pkt_lt) {
11970Sstevel@tonic-gate pathrec_req.PacketLifeTime =
11980Sstevel@tonic-gate ibt_usec2ib(attrp->pa_pkt_lt.p_pkt_lt);
11990Sstevel@tonic-gate pathrec_req.PacketLifeTimeSelector =
12000Sstevel@tonic-gate attrp->pa_pkt_lt.p_selector;
12010Sstevel@tonic-gate
12020Sstevel@tonic-gate c_mask |= SA_PR_COMPMASK_PKTLT | SA_PR_COMPMASK_PKTLTSELECTOR;
12030Sstevel@tonic-gate }
12040Sstevel@tonic-gate
12050Sstevel@tonic-gate /* Is SRATE specified. */
12060Sstevel@tonic-gate if (attrp->pa_srate.r_srate) {
12070Sstevel@tonic-gate pathrec_req.Rate = attrp->pa_srate.r_srate;
12080Sstevel@tonic-gate pathrec_req.RateSelector = attrp->pa_srate.r_selector;
12090Sstevel@tonic-gate
12100Sstevel@tonic-gate c_mask |= SA_PR_COMPMASK_RATE | SA_PR_COMPMASK_RATESELECTOR;
12110Sstevel@tonic-gate }
12120Sstevel@tonic-gate
12130Sstevel@tonic-gate /* Is MTU specified. */
12140Sstevel@tonic-gate if (attrp->pa_mtu.r_mtu) {
12150Sstevel@tonic-gate pathrec_req.Mtu = attrp->pa_mtu.r_mtu;
12160Sstevel@tonic-gate pathrec_req.MtuSelector = attrp->pa_mtu.r_selector;
12170Sstevel@tonic-gate
12180Sstevel@tonic-gate c_mask |= SA_PR_COMPMASK_MTU | SA_PR_COMPMASK_MTUSELECTOR;
12190Sstevel@tonic-gate }
12200Sstevel@tonic-gate
12210Sstevel@tonic-gate /* We always get REVERSIBLE paths. */
12220Sstevel@tonic-gate pathrec_req.Reversible = 1;
12230Sstevel@tonic-gate c_mask |= SA_PR_COMPMASK_REVERSIBLE;
12240Sstevel@tonic-gate
12250Sstevel@tonic-gate pathrec_req.NumbPath = *num_path;
12260Sstevel@tonic-gate c_mask |= SA_PR_COMPMASK_NUMBPATH;
12270Sstevel@tonic-gate
12280Sstevel@tonic-gate if (idx != 0xFF) {
12290Sstevel@tonic-gate /* MGID */
12300Sstevel@tonic-gate pathrec_req.DGID = dinfo->dest[idx].d_gid;
12310Sstevel@tonic-gate c_mask |= SA_PR_COMPMASK_DGID;
12320Sstevel@tonic-gate }
12330Sstevel@tonic-gate
1234401Shiremath p_fnd = found = 0;
12350Sstevel@tonic-gate
12360Sstevel@tonic-gate for (i = 0; i < sl->p_count; i++) {
12370Sstevel@tonic-gate /* SGID */
12380Sstevel@tonic-gate pathrec_req.SGID = sl[i].p_sgid;
12390Sstevel@tonic-gate c_mask |= SA_PR_COMPMASK_SGID;
12400Sstevel@tonic-gate saa_handle = sl[i].p_saa_hdl;
12410Sstevel@tonic-gate
12420Sstevel@tonic-gate for (k = 0; k < dinfo->num_dest; k++) {
12430Sstevel@tonic-gate if (idx == 0xFF) { /* DGID */
12440Sstevel@tonic-gate if (dinfo->dest[k].d_tag != 0)
12450Sstevel@tonic-gate continue;
12460Sstevel@tonic-gate
1247401Shiremath if (pathrec_req.SGID.gid_prefix !=
1248401Shiremath dinfo->dest[k].d_gid.gid_prefix) {
1249401Shiremath IBTF_DPRINTF_L3(cmlog,
1250401Shiremath "ibcm_get_single_pathrec: SGID_pfx="
1251401Shiremath "%llX, DGID_pfx=%llX doesn't match",
1252401Shiremath pathrec_req.SGID.gid_prefix,
1253401Shiremath dinfo->dest[k].d_gid.gid_prefix);
1254401Shiremath continue;
1255401Shiremath }
1256401Shiremath
12570Sstevel@tonic-gate pathrec_req.DGID = dinfo->dest[k].d_gid;
12580Sstevel@tonic-gate c_mask |= SA_PR_COMPMASK_DGID;
12590Sstevel@tonic-gate
12600Sstevel@tonic-gate /*
12610Sstevel@tonic-gate * If we had performed Service Look-up, then we
12620Sstevel@tonic-gate * got P_Key from ServiceRecord, so get path
12630Sstevel@tonic-gate * records that satisfy this particular P_Key.
12640Sstevel@tonic-gate */
12650Sstevel@tonic-gate if ((dinfo->p_key == 0) &&
12660Sstevel@tonic-gate (dinfo->dest[k].d_pkey != 0)) {
12670Sstevel@tonic-gate pathrec_req.P_Key =
12680Sstevel@tonic-gate dinfo->dest[k].d_pkey;
12690Sstevel@tonic-gate c_mask |= SA_PR_COMPMASK_PKEY;
12700Sstevel@tonic-gate }
12710Sstevel@tonic-gate }
12720Sstevel@tonic-gate
12730Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_get_single_pathrec: "
12744703Shiremath "Get %d Path(s) between\nSGID %llX:%llX "
12754703Shiremath "DGID %llX:%llX", pathrec_req.NumbPath,
12760Sstevel@tonic-gate pathrec_req.SGID.gid_prefix,
12770Sstevel@tonic-gate pathrec_req.SGID.gid_guid,
12780Sstevel@tonic-gate pathrec_req.DGID.gid_prefix,
12790Sstevel@tonic-gate pathrec_req.DGID.gid_guid);
12800Sstevel@tonic-gate
12810Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_get_single_pathrec: CMask"
12820Sstevel@tonic-gate "=0x%llX, PKey=0x%X", c_mask, pathrec_req.P_Key);
12830Sstevel@tonic-gate
12840Sstevel@tonic-gate /* Contact SA Access to retrieve Path Records. */
12850Sstevel@tonic-gate access_args.sq_attr_id = SA_PATHRECORD_ATTRID;
12860Sstevel@tonic-gate access_args.sq_template = &pathrec_req;
12870Sstevel@tonic-gate access_args.sq_access_type = IBMF_SAA_RETRIEVE;
12880Sstevel@tonic-gate access_args.sq_template_length =
12890Sstevel@tonic-gate sizeof (sa_path_record_t);
12900Sstevel@tonic-gate access_args.sq_component_mask = c_mask;
12910Sstevel@tonic-gate access_args.sq_callback = NULL;
12920Sstevel@tonic-gate access_args.sq_callback_arg = NULL;
12930Sstevel@tonic-gate
12940Sstevel@tonic-gate retval = ibcm_contact_sa_access(saa_handle,
12950Sstevel@tonic-gate &access_args, &length, &results_p);
12960Sstevel@tonic-gate if (retval != IBT_SUCCESS) {
12970Sstevel@tonic-gate *num_path = 0;
12980Sstevel@tonic-gate return (retval);
12990Sstevel@tonic-gate }
13000Sstevel@tonic-gate
13010Sstevel@tonic-gate num_rec = length / sizeof (sa_path_record_t);
13020Sstevel@tonic-gate
13030Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_get_single_pathrec: "
13040Sstevel@tonic-gate "FOUND %d/%d path requested", num_rec, *num_path);
13050Sstevel@tonic-gate
13060Sstevel@tonic-gate if ((results_p == NULL) || (num_rec == 0)) {
13070Sstevel@tonic-gate if (idx != 0xFF)
13080Sstevel@tonic-gate break;
13090Sstevel@tonic-gate else
13100Sstevel@tonic-gate continue;
13110Sstevel@tonic-gate }
13120Sstevel@tonic-gate
13130Sstevel@tonic-gate /* Update the PathInfo from the response. */
13140Sstevel@tonic-gate pr_resp = (sa_path_record_t *)results_p;
13150Sstevel@tonic-gate for (j = 0; j < num_rec; j++, pr_resp++) {
13160Sstevel@tonic-gate if ((p_fnd != 0) &&
13170Sstevel@tonic-gate (p_arg->flags & IBT_PATH_APM)) {
13180Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog,
13190Sstevel@tonic-gate "ibcm_get_single_pathrec: "
13200Sstevel@tonic-gate "Fill Alternate Path");
13210Sstevel@tonic-gate retval = ibcm_update_cep_info(pr_resp,
13220Sstevel@tonic-gate sl, NULL,
1323401Shiremath &paths[found - 1].pi_alt_cep_path);
13240Sstevel@tonic-gate if (retval != IBT_SUCCESS)
13250Sstevel@tonic-gate continue;
13260Sstevel@tonic-gate
13270Sstevel@tonic-gate /* Update some leftovers */
1328401Shiremath paths[found - 1].pi_alt_pkt_lt =
13290Sstevel@tonic-gate pr_resp->PacketLifeTime;
1330401Shiremath p_fnd = 0;
13310Sstevel@tonic-gate } else {
13320Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog,
13330Sstevel@tonic-gate "ibcm_get_single_pathrec: "
13340Sstevel@tonic-gate "Fill Primary Path");
1335401Shiremath
1336401Shiremath if (found == *num_path)
1337401Shiremath break;
1338401Shiremath
13390Sstevel@tonic-gate retval = ibcm_update_pri(pr_resp, sl,
1340401Shiremath dinfo, &paths[found]);
13410Sstevel@tonic-gate if (retval != IBT_SUCCESS)
13420Sstevel@tonic-gate continue;
1343401Shiremath p_fnd = 1;
1344401Shiremath found++;
13450Sstevel@tonic-gate }
13460Sstevel@tonic-gate
13470Sstevel@tonic-gate }
13480Sstevel@tonic-gate /* Deallocate the memory for results_p. */
13490Sstevel@tonic-gate kmem_free(results_p, length);
13500Sstevel@tonic-gate
13510Sstevel@tonic-gate if (idx != 0xFF)
13520Sstevel@tonic-gate break; /* We r here for MGID */
13530Sstevel@tonic-gate }
1354401Shiremath if ((idx != 0xFF) && (found == *num_path))
1355401Shiremath break; /* We r here for MGID */
13560Sstevel@tonic-gate }
13570Sstevel@tonic-gate
1358401Shiremath if (found == 0)
1359401Shiremath retval = IBT_PATH_RECORDS_NOT_FOUND;
1360401Shiremath else if (found != *num_path)
13610Sstevel@tonic-gate retval = IBT_INSUFF_DATA;
1362401Shiremath else
1363401Shiremath retval = IBT_SUCCESS;
13640Sstevel@tonic-gate
13650Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_get_single_pathrec: done. Status %d, "
13660Sstevel@tonic-gate "Found %d/%d Paths", retval, found, *num_path);
13670Sstevel@tonic-gate
13680Sstevel@tonic-gate *num_path = found;
13690Sstevel@tonic-gate
13700Sstevel@tonic-gate return (retval);
13710Sstevel@tonic-gate }
13720Sstevel@tonic-gate
13730Sstevel@tonic-gate
13740Sstevel@tonic-gate static ibt_status_t
ibcm_get_multi_pathrec(ibcm_path_tqargs_t * p_arg,ibtl_cm_port_list_t * sl,ibcm_dinfo_t * dinfo,uint8_t * num_path,ibt_path_info_t * paths)13750Sstevel@tonic-gate ibcm_get_multi_pathrec(ibcm_path_tqargs_t *p_arg, ibtl_cm_port_list_t *sl,
13760Sstevel@tonic-gate ibcm_dinfo_t *dinfo, uint8_t *num_path, ibt_path_info_t *paths)
13770Sstevel@tonic-gate {
13780Sstevel@tonic-gate sa_multipath_record_t *mpr_req;
13790Sstevel@tonic-gate sa_path_record_t *pr_resp;
13800Sstevel@tonic-gate ibmf_saa_access_args_t access_args;
13810Sstevel@tonic-gate void *results_p;
13820Sstevel@tonic-gate uint64_t c_mask = 0;
13830Sstevel@tonic-gate ib_gid_t *gid_ptr, *gid_s_ptr;
13840Sstevel@tonic-gate size_t length;
138511951SShantkumar.Hiremath@Sun.COM int template_len;
138611951SShantkumar.Hiremath@Sun.COM uint8_t found, num_rec;
13870Sstevel@tonic-gate int i, k;
13880Sstevel@tonic-gate ibt_status_t retval;
13890Sstevel@tonic-gate uint8_t sgid_cnt, dgid_cnt;
13900Sstevel@tonic-gate ibt_path_attr_t *attrp = &p_arg->attr;
13910Sstevel@tonic-gate
13920Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec(%p, %p, %p, %d)",
13930Sstevel@tonic-gate attrp, sl, dinfo, *num_path);
13940Sstevel@tonic-gate
13950Sstevel@tonic-gate for (i = 0, dgid_cnt = 0; i < dinfo->num_dest; i++) {
13960Sstevel@tonic-gate if (dinfo->dest[i].d_tag == 0)
13970Sstevel@tonic-gate dgid_cnt++;
13980Sstevel@tonic-gate }
13990Sstevel@tonic-gate
14000Sstevel@tonic-gate sgid_cnt = sl->p_count;
14010Sstevel@tonic-gate
14020Sstevel@tonic-gate if ((sgid_cnt == 0) || (dgid_cnt == 0)) {
14030Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_get_multi_pathrec: sgid_cnt(%d) or"
14040Sstevel@tonic-gate " dgid_cnt(%d) is zero", sgid_cnt, dgid_cnt);
14050Sstevel@tonic-gate return (IBT_INVALID_PARAM);
14060Sstevel@tonic-gate }
14070Sstevel@tonic-gate
14080Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: Get %d records between "
14090Sstevel@tonic-gate "%d Src(s) <=> %d Dest(s)", *num_path, sgid_cnt, dgid_cnt);
14100Sstevel@tonic-gate
14110Sstevel@tonic-gate /*
14120Sstevel@tonic-gate * Calculate the size for multi-path records template, which includes
14130Sstevel@tonic-gate * constant portion of the multipath record, plus variable size for
14140Sstevel@tonic-gate * SGID (sgid_cnt) and DGID (dgid_cnt).
14150Sstevel@tonic-gate */
14160Sstevel@tonic-gate template_len = ((dgid_cnt + sgid_cnt) * sizeof (ib_gid_t)) +
14170Sstevel@tonic-gate sizeof (sa_multipath_record_t);
14180Sstevel@tonic-gate
14190Sstevel@tonic-gate mpr_req = kmem_zalloc(template_len, KM_SLEEP);
14200Sstevel@tonic-gate
14210Sstevel@tonic-gate ASSERT(mpr_req != NULL);
14220Sstevel@tonic-gate
14230Sstevel@tonic-gate gid_ptr = (ib_gid_t *)(((uchar_t *)mpr_req) +
14240Sstevel@tonic-gate sizeof (sa_multipath_record_t));
14250Sstevel@tonic-gate
14260Sstevel@tonic-gate /* Get the starting pointer where GIDs are stored. */
14270Sstevel@tonic-gate gid_s_ptr = gid_ptr;
14280Sstevel@tonic-gate
14290Sstevel@tonic-gate /* SGID */
14309645SShantkumar.Hiremath@Sun.COM for (i = 0; i < sgid_cnt; i++) {
14310Sstevel@tonic-gate *gid_ptr = sl[i].p_sgid;
14320Sstevel@tonic-gate
14330Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: SGID[%d] = "
14340Sstevel@tonic-gate "(%llX:%llX)", i, gid_ptr->gid_prefix, gid_ptr->gid_guid);
14350Sstevel@tonic-gate
14360Sstevel@tonic-gate gid_ptr++;
14370Sstevel@tonic-gate }
14380Sstevel@tonic-gate
14390Sstevel@tonic-gate _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mpr_req))
14400Sstevel@tonic-gate
14410Sstevel@tonic-gate mpr_req->SGIDCount = sgid_cnt;
14420Sstevel@tonic-gate c_mask = SA_MPR_COMPMASK_SGIDCOUNT;
14430Sstevel@tonic-gate
14440Sstevel@tonic-gate /* DGIDs */
14450Sstevel@tonic-gate for (i = 0; i < dinfo->num_dest; i++) {
14460Sstevel@tonic-gate if (dinfo->dest[i].d_tag == 0) {
14470Sstevel@tonic-gate *gid_ptr = dinfo->dest[i].d_gid;
14480Sstevel@tonic-gate
14490Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: "
14500Sstevel@tonic-gate "DGID[%d] = (%llX:%llX)", i, gid_ptr->gid_prefix,
14510Sstevel@tonic-gate gid_ptr->gid_guid);
14520Sstevel@tonic-gate gid_ptr++;
14530Sstevel@tonic-gate }
14540Sstevel@tonic-gate }
14550Sstevel@tonic-gate
14560Sstevel@tonic-gate mpr_req->DGIDCount = dgid_cnt;
14570Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_DGIDCOUNT;
14580Sstevel@tonic-gate
14590Sstevel@tonic-gate /* Is Flow Label Specified. */
14600Sstevel@tonic-gate if (attrp->pa_flow) {
14610Sstevel@tonic-gate mpr_req->FlowLabel = attrp->pa_flow;
14620Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_FLOWLABEL;
14630Sstevel@tonic-gate }
14640Sstevel@tonic-gate
14650Sstevel@tonic-gate /* Is HopLimit Specified. */
14660Sstevel@tonic-gate if (p_arg->flags & IBT_PATH_HOP) {
14670Sstevel@tonic-gate mpr_req->HopLimit = attrp->pa_hop;
14680Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_HOPLIMIT;
14690Sstevel@tonic-gate }
14700Sstevel@tonic-gate
14710Sstevel@tonic-gate /* Is TClass Specified. */
14720Sstevel@tonic-gate if (attrp->pa_tclass) {
14730Sstevel@tonic-gate mpr_req->TClass = attrp->pa_tclass;
14740Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_TCLASS;
14750Sstevel@tonic-gate }
14760Sstevel@tonic-gate
14770Sstevel@tonic-gate /* Is SL specified. */
14780Sstevel@tonic-gate if (attrp->pa_sl) {
14790Sstevel@tonic-gate mpr_req->SL = attrp->pa_sl;
14800Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_SL;
14810Sstevel@tonic-gate }
14820Sstevel@tonic-gate
14830Sstevel@tonic-gate if (p_arg->flags & IBT_PATH_PERF) {
14840Sstevel@tonic-gate mpr_req->PacketLifeTimeSelector = IBT_BEST;
14850Sstevel@tonic-gate mpr_req->RateSelector = IBT_BEST;
14860Sstevel@tonic-gate mpr_req->MtuSelector = IBT_BEST;
14870Sstevel@tonic-gate
14880Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_PKTLTSELECTOR |
14890Sstevel@tonic-gate SA_MPR_COMPMASK_RATESELECTOR | SA_MPR_COMPMASK_MTUSELECTOR;
14900Sstevel@tonic-gate } else {
14910Sstevel@tonic-gate if (attrp->pa_pkt_lt.p_selector == IBT_BEST) {
14920Sstevel@tonic-gate mpr_req->PacketLifeTimeSelector = IBT_BEST;
14930Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_PKTLTSELECTOR;
14940Sstevel@tonic-gate }
14950Sstevel@tonic-gate
14960Sstevel@tonic-gate if (attrp->pa_srate.r_selector == IBT_BEST) {
14970Sstevel@tonic-gate mpr_req->RateSelector = IBT_BEST;
14980Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_RATESELECTOR;
14990Sstevel@tonic-gate }
15000Sstevel@tonic-gate
15010Sstevel@tonic-gate if (attrp->pa_mtu.r_selector == IBT_BEST) {
15020Sstevel@tonic-gate mpr_req->MtuSelector = IBT_BEST;
15030Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_MTUSELECTOR;
15040Sstevel@tonic-gate }
15050Sstevel@tonic-gate }
15060Sstevel@tonic-gate
15070Sstevel@tonic-gate /*
15080Sstevel@tonic-gate * Honor individual selection of these attributes,
15090Sstevel@tonic-gate * even if IBT_PATH_PERF is set.
15100Sstevel@tonic-gate */
15110Sstevel@tonic-gate /* Check out whether Packet Life Time is specified. */
15120Sstevel@tonic-gate if (attrp->pa_pkt_lt.p_pkt_lt) {
15130Sstevel@tonic-gate mpr_req->PacketLifeTime =
15140Sstevel@tonic-gate ibt_usec2ib(attrp->pa_pkt_lt.p_pkt_lt);
15150Sstevel@tonic-gate mpr_req->PacketLifeTimeSelector =
15160Sstevel@tonic-gate attrp->pa_pkt_lt.p_selector;
15170Sstevel@tonic-gate
15180Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_PKTLT |
15190Sstevel@tonic-gate SA_MPR_COMPMASK_PKTLTSELECTOR;
15200Sstevel@tonic-gate }
15210Sstevel@tonic-gate
15220Sstevel@tonic-gate /* Is SRATE specified. */
15230Sstevel@tonic-gate if (attrp->pa_srate.r_srate) {
15240Sstevel@tonic-gate mpr_req->Rate = attrp->pa_srate.r_srate;
15250Sstevel@tonic-gate mpr_req->RateSelector = attrp->pa_srate.r_selector;
15260Sstevel@tonic-gate
15270Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_RATE |
15280Sstevel@tonic-gate SA_MPR_COMPMASK_RATESELECTOR;
15290Sstevel@tonic-gate }
15300Sstevel@tonic-gate
15310Sstevel@tonic-gate /* Is MTU specified. */
15320Sstevel@tonic-gate if (attrp->pa_mtu.r_mtu) {
15330Sstevel@tonic-gate mpr_req->Mtu = attrp->pa_mtu.r_mtu;
15340Sstevel@tonic-gate mpr_req->MtuSelector = attrp->pa_mtu.r_selector;
15350Sstevel@tonic-gate
15360Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_MTU |
15370Sstevel@tonic-gate SA_MPR_COMPMASK_MTUSELECTOR;
15380Sstevel@tonic-gate }
15390Sstevel@tonic-gate
15400Sstevel@tonic-gate /* Is P_Key Specified or obtained during Service Look-up. */
15410Sstevel@tonic-gate if (dinfo->p_key) {
15420Sstevel@tonic-gate mpr_req->P_Key = dinfo->p_key;
15430Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_PKEY;
15440Sstevel@tonic-gate }
15450Sstevel@tonic-gate
15460Sstevel@tonic-gate /* We always get REVERSIBLE paths. */
15470Sstevel@tonic-gate mpr_req->Reversible = 1;
15480Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_REVERSIBLE;
15490Sstevel@tonic-gate
15500Sstevel@tonic-gate if (p_arg->flags & IBT_PATH_AVAIL) {
15510Sstevel@tonic-gate mpr_req->IndependenceSelector = 1;
15520Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_INDEPSEL;
15530Sstevel@tonic-gate }
15540Sstevel@tonic-gate
15550Sstevel@tonic-gate /* we will not specify how many records we want. */
15560Sstevel@tonic-gate
15570Sstevel@tonic-gate _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*mpr_req))
15580Sstevel@tonic-gate
15590Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: CMask: %llX Pkey: %X",
15600Sstevel@tonic-gate c_mask, mpr_req->P_Key);
15610Sstevel@tonic-gate
15620Sstevel@tonic-gate /* Contact SA Access to retrieve Path Records. */
15630Sstevel@tonic-gate access_args.sq_attr_id = SA_MULTIPATHRECORD_ATTRID;
15640Sstevel@tonic-gate access_args.sq_access_type = IBMF_SAA_RETRIEVE;
15650Sstevel@tonic-gate access_args.sq_component_mask = c_mask;
15660Sstevel@tonic-gate access_args.sq_template = mpr_req;
15670Sstevel@tonic-gate access_args.sq_template_length = sizeof (sa_multipath_record_t);
15680Sstevel@tonic-gate access_args.sq_callback = NULL;
15690Sstevel@tonic-gate access_args.sq_callback_arg = NULL;
15700Sstevel@tonic-gate
15710Sstevel@tonic-gate retval = ibcm_contact_sa_access(sl->p_saa_hdl, &access_args, &length,
15720Sstevel@tonic-gate &results_p);
15730Sstevel@tonic-gate if (retval != IBT_SUCCESS) {
15740Sstevel@tonic-gate *num_path = 0; /* Update the return count. */
15750Sstevel@tonic-gate kmem_free(mpr_req, template_len);
15760Sstevel@tonic-gate return (retval);
15770Sstevel@tonic-gate }
15780Sstevel@tonic-gate
15790Sstevel@tonic-gate num_rec = length / sizeof (sa_path_record_t);
15800Sstevel@tonic-gate
15810Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: Found %d Paths",
15820Sstevel@tonic-gate num_rec);
15830Sstevel@tonic-gate
15840Sstevel@tonic-gate found = 0;
15850Sstevel@tonic-gate if ((results_p != NULL) && (num_rec > 0)) {
15860Sstevel@tonic-gate /* Update the PathInfo with the response Path Records */
15870Sstevel@tonic-gate pr_resp = (sa_path_record_t *)results_p;
15880Sstevel@tonic-gate
15890Sstevel@tonic-gate for (i = 0; i < num_rec; i++) {
15900Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: "
15910Sstevel@tonic-gate "P[%d]: SG %llX, DG %llX", i,
15920Sstevel@tonic-gate pr_resp[i].SGID.gid_guid, pr_resp[i].DGID.gid_guid);
15930Sstevel@tonic-gate }
15940Sstevel@tonic-gate
15953826Shiremath if (p_arg->flags & (IBT_PATH_APM | IBT_PATH_AVAIL)) {
15960Sstevel@tonic-gate sa_path_record_t *p_resp = NULL, *a_resp = NULL;
15973826Shiremath sa_path_record_t *p_tmp = NULL, *a_tmp = NULL;
15980Sstevel@tonic-gate int p_found = 0, a_found = 0;
15990Sstevel@tonic-gate ib_gid_t p_sg, a_sg, p_dg, a_dg;
16003826Shiremath int p_tmp_found = 0, a_tmp_found = 0;
16010Sstevel@tonic-gate
16020Sstevel@tonic-gate p_sg = gid_s_ptr[0];
16030Sstevel@tonic-gate if (sgid_cnt > 1)
16040Sstevel@tonic-gate a_sg = gid_s_ptr[1];
16050Sstevel@tonic-gate else
16060Sstevel@tonic-gate a_sg = p_sg;
16070Sstevel@tonic-gate
16080Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: "
16090Sstevel@tonic-gate "REQ: P_SG: %llX, A_SG: %llX",
16100Sstevel@tonic-gate p_sg.gid_guid, a_sg.gid_guid);
16110Sstevel@tonic-gate
16120Sstevel@tonic-gate p_dg = gid_s_ptr[sgid_cnt];
16130Sstevel@tonic-gate if (dgid_cnt > 1)
16140Sstevel@tonic-gate a_dg = gid_s_ptr[sgid_cnt + 1];
16150Sstevel@tonic-gate else
16160Sstevel@tonic-gate a_dg = p_dg;
16170Sstevel@tonic-gate
16180Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: "
16190Sstevel@tonic-gate "REQ: P_DG: %llX, A_DG: %llX",
16200Sstevel@tonic-gate p_dg.gid_guid, a_dg.gid_guid);
16210Sstevel@tonic-gate
16220Sstevel@tonic-gate /*
16230Sstevel@tonic-gate * If SGID and/or DGID is specified by user, make sure
16240Sstevel@tonic-gate * he gets his primary-path on those node points.
16250Sstevel@tonic-gate */
16260Sstevel@tonic-gate for (i = 0; i < num_rec; i++, pr_resp++) {
16270Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec:"
16280Sstevel@tonic-gate " PF %d, AF %d,\n\t\t P[%d] = SG: %llX, "
16290Sstevel@tonic-gate "DG: %llX", p_found, a_found, i,
16300Sstevel@tonic-gate pr_resp->SGID.gid_guid,
16310Sstevel@tonic-gate pr_resp->DGID.gid_guid);
16320Sstevel@tonic-gate
16330Sstevel@tonic-gate if ((!p_found) &&
16340Sstevel@tonic-gate (p_dg.gid_guid == pr_resp->DGID.gid_guid)) {
16350Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog,
16360Sstevel@tonic-gate "ibcm_get_multi_pathrec: "
16370Sstevel@tonic-gate "Pri DGID Match.. ");
16383826Shiremath if (p_sg.gid_guid ==
16393826Shiremath pr_resp->SGID.gid_guid) {
16400Sstevel@tonic-gate p_found = 1;
16410Sstevel@tonic-gate p_resp = pr_resp;
16420Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog,
16430Sstevel@tonic-gate "ibcm_get_multi_pathrec: "
16440Sstevel@tonic-gate "Primary Path Found");
16450Sstevel@tonic-gate
16460Sstevel@tonic-gate if (a_found)
16470Sstevel@tonic-gate break;
16480Sstevel@tonic-gate else
16490Sstevel@tonic-gate continue;
16503826Shiremath } else if ((!p_tmp_found) &&
16513826Shiremath (a_sg.gid_guid ==
16523826Shiremath pr_resp->SGID.gid_guid)) {
16533826Shiremath p_tmp_found = 1;
16543826Shiremath p_tmp = pr_resp;
16553826Shiremath IBTF_DPRINTF_L3(cmlog,
16563826Shiremath "ibcm_get_multi_pathrec: "
16573826Shiremath "Tmp Pri Path Found");
16580Sstevel@tonic-gate }
16590Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog,
16600Sstevel@tonic-gate "ibcm_get_multi_pathrec:"
16610Sstevel@tonic-gate "Pri SGID Don't Match.. ");
16620Sstevel@tonic-gate }
16630Sstevel@tonic-gate
16640Sstevel@tonic-gate if ((!a_found) &&
16650Sstevel@tonic-gate (a_dg.gid_guid == pr_resp->DGID.gid_guid)) {
16660Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog,
16670Sstevel@tonic-gate "ibcm_get_multi_pathrec:"
16680Sstevel@tonic-gate "Alt DGID Match.. ");
16693826Shiremath if (a_sg.gid_guid ==
16703826Shiremath pr_resp->SGID.gid_guid) {
16710Sstevel@tonic-gate a_found = 1;
16720Sstevel@tonic-gate a_resp = pr_resp;
16730Sstevel@tonic-gate
16740Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog,
16750Sstevel@tonic-gate "ibcm_get_multi_pathrec:"
16760Sstevel@tonic-gate "Alternate Path Found ");
16770Sstevel@tonic-gate
16780Sstevel@tonic-gate if (p_found)
16790Sstevel@tonic-gate break;
16800Sstevel@tonic-gate else
16810Sstevel@tonic-gate continue;
16823826Shiremath } else if ((!a_tmp_found) &&
16833826Shiremath (p_sg.gid_guid ==
16843826Shiremath pr_resp->SGID.gid_guid)) {
16853826Shiremath a_tmp_found = 1;
16863826Shiremath a_tmp = pr_resp;
16873826Shiremath
16883826Shiremath IBTF_DPRINTF_L3(cmlog,
16893826Shiremath "ibcm_get_multi_pathrec:"
16903826Shiremath "Tmp Alt Path Found ");
16910Sstevel@tonic-gate }
16920Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog,
16930Sstevel@tonic-gate "ibcm_get_multi_pathrec:"
16940Sstevel@tonic-gate "Alt SGID Don't Match.. ");
16950Sstevel@tonic-gate }
16960Sstevel@tonic-gate }
16970Sstevel@tonic-gate
16983826Shiremath if ((p_found == 0) && (a_found == 0) &&
16993826Shiremath (p_tmp_found == 0) && (a_tmp_found == 0)) {
17003826Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec:"
17010Sstevel@tonic-gate " Path to desired node points NOT "
17020Sstevel@tonic-gate "Available.");
17030Sstevel@tonic-gate retval = IBT_PATH_RECORDS_NOT_FOUND;
17043826Shiremath goto get_mpr_end;
17050Sstevel@tonic-gate }
17060Sstevel@tonic-gate
17073826Shiremath if (p_resp == NULL) {
17083826Shiremath if (a_resp != NULL) {
17093826Shiremath p_resp = a_resp;
17103826Shiremath a_resp = NULL;
17113826Shiremath } else if (p_tmp != NULL) {
17123826Shiremath p_resp = p_tmp;
17133826Shiremath p_tmp = NULL;
17143826Shiremath } else if (a_tmp != NULL) {
17153826Shiremath p_resp = a_tmp;
17163826Shiremath a_tmp = NULL;
17173826Shiremath }
17183826Shiremath }
17193826Shiremath if (a_resp == NULL) {
17203826Shiremath if (a_tmp != NULL) {
17213826Shiremath a_resp = a_tmp;
17223826Shiremath a_tmp = NULL;
17233826Shiremath } else if (p_tmp != NULL) {
17243826Shiremath a_resp = p_tmp;
17253826Shiremath p_tmp = NULL;
17263826Shiremath }
17270Sstevel@tonic-gate }
17280Sstevel@tonic-gate
17290Sstevel@tonic-gate /* Fill in Primary Path */
17300Sstevel@tonic-gate retval = ibcm_update_pri(p_resp, sl, dinfo,
17310Sstevel@tonic-gate &paths[found]);
17320Sstevel@tonic-gate if (retval != IBT_SUCCESS)
17333826Shiremath goto get_mpr_end;
17343826Shiremath
17353826Shiremath if (p_arg->flags & IBT_PATH_APM) {
17363826Shiremath /* Fill in Alternate Path */
17373826Shiremath if (a_resp != NULL) {
17383826Shiremath /*
17393826Shiremath * a_resp will point to AltPathInfo
17403826Shiremath * buffer.
17413826Shiremath */
17423826Shiremath retval = ibcm_update_cep_info(a_resp,
17433826Shiremath sl, NULL,
17443826Shiremath &paths[found].pi_alt_cep_path);
17453826Shiremath if (retval != IBT_SUCCESS)
17463826Shiremath goto get_mpr_end;
17473826Shiremath
17483826Shiremath /* Update some leftovers */
17493826Shiremath paths[found].pi_alt_pkt_lt =
17503826Shiremath a_resp->PacketLifeTime;
17513826Shiremath } else {
17523826Shiremath IBTF_DPRINTF_L3(cmlog,
17533826Shiremath "ibcm_get_multi_pathrec:"
17543826Shiremath " Alternate Path NOT Available.");
17553826Shiremath retval = IBT_INSUFF_DATA;
17563826Shiremath }
17573826Shiremath found++;
17583826Shiremath } else if (p_arg->flags & IBT_PATH_AVAIL) {
17593826Shiremath found++;
17603826Shiremath
17613826Shiremath if (found < *num_path) {
17623826Shiremath
17633826Shiremath /* Fill in second Path */
17643826Shiremath if (a_resp != NULL) {
17653826Shiremath retval = ibcm_update_pri(a_resp,
17663826Shiremath sl, dinfo, &paths[found]);
17673826Shiremath if (retval != IBT_SUCCESS)
17683826Shiremath goto get_mpr_end;
17693826Shiremath else
17703826Shiremath found++;
17713826Shiremath } else {
17723826Shiremath IBTF_DPRINTF_L3(cmlog,
17733826Shiremath "ibcm_get_multi_pathrec: "
17743826Shiremath "SecondPath NOT Available");
17753826Shiremath retval = IBT_INSUFF_DATA;
17763826Shiremath }
17773826Shiremath }
17780Sstevel@tonic-gate }
17790Sstevel@tonic-gate } else { /* If NOT APM */
17800Sstevel@tonic-gate boolean_t check_pkey = B_FALSE;
17810Sstevel@tonic-gate
17820Sstevel@tonic-gate /* mark flag whether to validate PKey or not. */
17830Sstevel@tonic-gate if ((dinfo->p_key == 0) && (dinfo->dest[0].d_pkey != 0))
17840Sstevel@tonic-gate check_pkey = B_TRUE;
17850Sstevel@tonic-gate
17860Sstevel@tonic-gate for (i = 0; i < num_rec; i++, pr_resp++) {
17870Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec:"
17880Sstevel@tonic-gate " PKeyCheck - %s, PKey=0x%X, DGID(%llX)",
17890Sstevel@tonic-gate ((check_pkey == B_TRUE)?"REQD":"NOT_REQD"),
17900Sstevel@tonic-gate pr_resp->P_Key, pr_resp->DGID.gid_guid);
17910Sstevel@tonic-gate
17929349SShantkumar.Hiremath@Sun.COM if (check_pkey) {
17930Sstevel@tonic-gate boolean_t match_found = B_FALSE;
17940Sstevel@tonic-gate
17950Sstevel@tonic-gate /* For all DGIDs */
17960Sstevel@tonic-gate for (k = 0; k < dinfo->num_dest; k++) {
17970Sstevel@tonic-gate if (dinfo->dest[k].d_tag != 0)
17980Sstevel@tonic-gate continue;
17990Sstevel@tonic-gate
18000Sstevel@tonic-gate if ((dinfo->dest[k].d_gid.
18010Sstevel@tonic-gate gid_guid ==
18020Sstevel@tonic-gate pr_resp->DGID.gid_guid) &&
18030Sstevel@tonic-gate (dinfo->dest[k].d_pkey ==
18040Sstevel@tonic-gate pr_resp->P_Key)) {
18050Sstevel@tonic-gate match_found = B_TRUE;
18060Sstevel@tonic-gate break;
18070Sstevel@tonic-gate }
18080Sstevel@tonic-gate }
18099349SShantkumar.Hiremath@Sun.COM if (!match_found)
18100Sstevel@tonic-gate continue;
18110Sstevel@tonic-gate }
18120Sstevel@tonic-gate /* Fill in Primary Path */
18130Sstevel@tonic-gate retval = ibcm_update_pri(pr_resp, sl, dinfo,
18140Sstevel@tonic-gate &paths[found]);
18150Sstevel@tonic-gate if (retval != IBT_SUCCESS)
18160Sstevel@tonic-gate continue;
18170Sstevel@tonic-gate
18180Sstevel@tonic-gate if (++found == *num_path)
18190Sstevel@tonic-gate break;
18200Sstevel@tonic-gate }
18210Sstevel@tonic-gate }
18223826Shiremath get_mpr_end:
18230Sstevel@tonic-gate kmem_free(results_p, length);
18240Sstevel@tonic-gate }
18250Sstevel@tonic-gate kmem_free(mpr_req, template_len);
18260Sstevel@tonic-gate
1827401Shiremath if (found == 0)
1828401Shiremath retval = IBT_PATH_RECORDS_NOT_FOUND;
1829401Shiremath else if (found != *num_path)
1830401Shiremath retval = IBT_INSUFF_DATA;
1831401Shiremath else
1832401Shiremath retval = IBT_SUCCESS;
18330Sstevel@tonic-gate
18340Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_get_multi_pathrec: Done (status %d). "
18350Sstevel@tonic-gate "Found %d/%d Paths", retval, found, *num_path);
18360Sstevel@tonic-gate
18370Sstevel@tonic-gate *num_path = found; /* Update the return count. */
18380Sstevel@tonic-gate
18390Sstevel@tonic-gate return (retval);
18400Sstevel@tonic-gate }
18410Sstevel@tonic-gate
18420Sstevel@tonic-gate
18430Sstevel@tonic-gate /*
18440Sstevel@tonic-gate * Update the output path records buffer with the values as obtained from
18450Sstevel@tonic-gate * SA Access retrieve call results for Path Records.
18460Sstevel@tonic-gate */
18470Sstevel@tonic-gate static ibt_status_t
ibcm_update_cep_info(sa_path_record_t * prec_resp,ibtl_cm_port_list_t * sl,ibtl_cm_hca_port_t * hport,ibt_cep_path_t * cep_p)18480Sstevel@tonic-gate ibcm_update_cep_info(sa_path_record_t *prec_resp, ibtl_cm_port_list_t *sl,
18490Sstevel@tonic-gate ibtl_cm_hca_port_t *hport, ibt_cep_path_t *cep_p)
18500Sstevel@tonic-gate {
18510Sstevel@tonic-gate ibt_status_t retval;
18520Sstevel@tonic-gate int i;
18530Sstevel@tonic-gate
18540Sstevel@tonic-gate IBCM_DUMP_PATH_REC(prec_resp);
18550Sstevel@tonic-gate
18560Sstevel@tonic-gate /*
18570Sstevel@tonic-gate * If path's packet life time is more than 4 seconds, IBCM cannot
18580Sstevel@tonic-gate * handle this path connection, so discard this path record.
18590Sstevel@tonic-gate */
18600Sstevel@tonic-gate if (prec_resp->PacketLifeTime > ibcm_max_ib_pkt_lt) {
18610Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_update_cep_info: Path's Packet "
18620Sstevel@tonic-gate "LifeTime too high %d, Maximum allowed %d IB Time (4 sec)",
18630Sstevel@tonic-gate prec_resp->PacketLifeTime, ibcm_max_ib_pkt_lt);
1864929Ssrust return (ibt_get_module_failure(IBT_FAILURE_IBSM, 0));
18650Sstevel@tonic-gate }
18660Sstevel@tonic-gate
18670Sstevel@tonic-gate if ((prec_resp->Mtu > IB_MTU_4K) || (prec_resp->Mtu < IB_MTU_256)) {
18680Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_update_cep_info: MTU (%d) from "
18690Sstevel@tonic-gate "pathrecord is invalid, reject it.", prec_resp->Mtu);
1870929Ssrust return (ibt_get_module_failure(IBT_FAILURE_IBSM, 0));
18710Sstevel@tonic-gate }
18720Sstevel@tonic-gate
18730Sstevel@tonic-gate /* Source Node Information. */
18740Sstevel@tonic-gate cep_p->cep_adds_vect.av_sgid = prec_resp->SGID;
18750Sstevel@tonic-gate if (hport != NULL) {
18760Sstevel@tonic-gate /* Convert P_Key to P_Key_Index */
18770Sstevel@tonic-gate retval = ibt_pkey2index_byguid(hport->hp_hca_guid,
18780Sstevel@tonic-gate hport->hp_port, prec_resp->P_Key, &cep_p->cep_pkey_ix);
18790Sstevel@tonic-gate if (retval != IBT_SUCCESS) {
18800Sstevel@tonic-gate /* Failed to get pkey_index from pkey */
18810Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_update_cep_info: "
18824908Shiremath "Pkey2Index (PKey = %X) conversion failed: %d",
18834908Shiremath prec_resp->P_Key, retval);
1884929Ssrust return (ibt_get_module_failure(IBT_FAILURE_IBSM, 0));
18850Sstevel@tonic-gate }
18860Sstevel@tonic-gate cep_p->cep_adds_vect.av_sgid_ix = hport->hp_sgid_ix;
18870Sstevel@tonic-gate cep_p->cep_adds_vect.av_src_path =
18880Sstevel@tonic-gate prec_resp->SLID - hport->hp_base_lid;
18890Sstevel@tonic-gate cep_p->cep_adds_vect.av_port_num = cep_p->cep_hca_port_num =
18900Sstevel@tonic-gate hport->hp_port;
18910Sstevel@tonic-gate } else if (sl != NULL) {
18920Sstevel@tonic-gate for (i = 0; i < sl->p_count; i++) {
18930Sstevel@tonic-gate if (prec_resp->SGID.gid_guid == sl[i].p_sgid.gid_guid) {
18940Sstevel@tonic-gate /* Convert P_Key to P_Key_Index */
18950Sstevel@tonic-gate retval = ibt_pkey2index_byguid(sl[i].p_hca_guid,
18960Sstevel@tonic-gate sl[i].p_port_num, prec_resp->P_Key,
18970Sstevel@tonic-gate &cep_p->cep_pkey_ix);
18980Sstevel@tonic-gate if (retval != IBT_SUCCESS) {
18990Sstevel@tonic-gate /* Failed to get pkey_index from pkey */
19000Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog,
19010Sstevel@tonic-gate "ibcm_update_cep_info: Pkey2Index "
19024908Shiremath "(PKey = %X) conversion failed: %d",
19034908Shiremath prec_resp->P_Key, retval);
1904929Ssrust return (ibt_get_module_failure(
1905929Ssrust IBT_FAILURE_IBSM, 0));
19060Sstevel@tonic-gate }
19070Sstevel@tonic-gate
19080Sstevel@tonic-gate cep_p->cep_adds_vect.av_sgid_ix =
19090Sstevel@tonic-gate sl[i].p_sgid_ix;
19100Sstevel@tonic-gate cep_p->cep_adds_vect.av_src_path =
19110Sstevel@tonic-gate prec_resp->SLID - sl[i].p_base_lid;
19120Sstevel@tonic-gate cep_p->cep_adds_vect.av_port_num =
19130Sstevel@tonic-gate sl[i].p_port_num;
19140Sstevel@tonic-gate cep_p->cep_hca_port_num = sl[i].p_port_num;
19150Sstevel@tonic-gate
19160Sstevel@tonic-gate break;
19170Sstevel@tonic-gate }
19180Sstevel@tonic-gate }
19190Sstevel@tonic-gate } else {
19200Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_update_cep_info: Sl or Hport "
19210Sstevel@tonic-gate "must be non-null");
19220Sstevel@tonic-gate return (IBT_INVALID_PARAM);
19230Sstevel@tonic-gate }
19240Sstevel@tonic-gate
19254460Shiremath if (prec_resp->Rate) {
19260Sstevel@tonic-gate cep_p->cep_adds_vect.av_srate = prec_resp->Rate;
19274460Shiremath } else {
19280Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_update_cep_info: SRate (%d) from "
19290Sstevel@tonic-gate "pathrecord is invalid, reject it.", prec_resp->Rate);
1930929Ssrust return (ibt_get_module_failure(IBT_FAILURE_IBSM, 0));
19310Sstevel@tonic-gate }
19320Sstevel@tonic-gate /*
19330Sstevel@tonic-gate * If both Source and Destination GID prefix are same, then GRH is not
19340Sstevel@tonic-gate * valid, so make it as false, else set this field as true.
19350Sstevel@tonic-gate */
19360Sstevel@tonic-gate if (prec_resp->SGID.gid_prefix == prec_resp->DGID.gid_prefix)
19370Sstevel@tonic-gate cep_p->cep_adds_vect.av_send_grh = B_FALSE;
19380Sstevel@tonic-gate else
19390Sstevel@tonic-gate cep_p->cep_adds_vect.av_send_grh = B_TRUE;
19400Sstevel@tonic-gate
19410Sstevel@tonic-gate /* SGID and SGID Index. */
19420Sstevel@tonic-gate cep_p->cep_adds_vect.av_sgid = prec_resp->SGID;
19430Sstevel@tonic-gate cep_p->cep_adds_vect.av_flow = prec_resp->FlowLabel;
19440Sstevel@tonic-gate cep_p->cep_adds_vect.av_tclass = prec_resp->TClass;
19450Sstevel@tonic-gate cep_p->cep_adds_vect.av_hop = prec_resp->HopLimit;
19460Sstevel@tonic-gate
19470Sstevel@tonic-gate /* Address Vector Definition. */
19480Sstevel@tonic-gate cep_p->cep_adds_vect.av_dlid = prec_resp->DLID;
19490Sstevel@tonic-gate cep_p->cep_adds_vect.av_srvl = prec_resp->SL;
19500Sstevel@tonic-gate
19510Sstevel@tonic-gate /* DGID */
19520Sstevel@tonic-gate cep_p->cep_adds_vect.av_dgid = prec_resp->DGID;
19530Sstevel@tonic-gate
19540Sstevel@tonic-gate /* CEP Timeout is NOT filled in by PATH routines. */
19550Sstevel@tonic-gate cep_p->cep_timeout = 0;
19560Sstevel@tonic-gate
19574908Shiremath IBTF_DPRINTF_L2(cmlog, "ibcm_update_cep_info: Done. Port=%d, PKey=%X\n"
19584908Shiremath "SGID=%llX:%llX DGID=%llX:%llX", cep_p->cep_adds_vect.av_port_num,
19594908Shiremath prec_resp->P_Key,
19600Sstevel@tonic-gate prec_resp->SGID.gid_prefix, prec_resp->SGID.gid_guid,
19610Sstevel@tonic-gate prec_resp->DGID.gid_prefix, prec_resp->DGID.gid_guid);
19620Sstevel@tonic-gate
19630Sstevel@tonic-gate return (IBT_SUCCESS);
19640Sstevel@tonic-gate }
19650Sstevel@tonic-gate
19660Sstevel@tonic-gate
19670Sstevel@tonic-gate static void
ibcm_fill_svcinfo(sa_service_record_t * sr_resp,ibcm_dest_t * dest)19680Sstevel@tonic-gate ibcm_fill_svcinfo(sa_service_record_t *sr_resp, ibcm_dest_t *dest)
19690Sstevel@tonic-gate {
19700Sstevel@tonic-gate _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*dest))
19710Sstevel@tonic-gate
19720Sstevel@tonic-gate dest->d_gid = sr_resp->ServiceGID;
19730Sstevel@tonic-gate dest->d_sid = sr_resp->ServiceID;
19740Sstevel@tonic-gate ibcm_swizzle_to_srv(sr_resp->ServiceData, &dest->d_sdata);
19750Sstevel@tonic-gate dest->d_pkey = sr_resp->ServiceP_Key;
19760Sstevel@tonic-gate
19770Sstevel@tonic-gate _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*dest))
19780Sstevel@tonic-gate
19790Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_fill_svcinfo: SID(%llX), GID(%llX:%llX)"
19800Sstevel@tonic-gate "\n\tSvcPKey 0x%X", dest->d_sid, dest->d_gid.gid_prefix,
19810Sstevel@tonic-gate dest->d_gid.gid_guid, dest->d_pkey);
19820Sstevel@tonic-gate }
19830Sstevel@tonic-gate
19840Sstevel@tonic-gate
19850Sstevel@tonic-gate static ib_gid_t
ibcm_saa_get_agid(ibtl_cm_port_list_t * sl,ib_gid_t * gidp,uint_t ngid)19860Sstevel@tonic-gate ibcm_saa_get_agid(ibtl_cm_port_list_t *sl, ib_gid_t *gidp, uint_t ngid)
19870Sstevel@tonic-gate {
19880Sstevel@tonic-gate int k, l;
19890Sstevel@tonic-gate ib_gid_t a_gid;
19900Sstevel@tonic-gate
19910Sstevel@tonic-gate a_gid.gid_prefix = a_gid.gid_guid = 0;
19920Sstevel@tonic-gate
19930Sstevel@tonic-gate for (k = 0; k < sl->p_count; k++) {
19940Sstevel@tonic-gate for (l = 0; l < ngid; l++) {
19950Sstevel@tonic-gate
19960Sstevel@tonic-gate if (gidp->gid_prefix == sl->p_sgid.gid_prefix) {
19970Sstevel@tonic-gate a_gid = *gidp;
19980Sstevel@tonic-gate break;
19990Sstevel@tonic-gate }
20000Sstevel@tonic-gate if (a_gid.gid_guid && a_gid.gid_prefix)
20010Sstevel@tonic-gate break;
20020Sstevel@tonic-gate gidp++;
20030Sstevel@tonic-gate }
20040Sstevel@tonic-gate if (a_gid.gid_guid && a_gid.gid_prefix)
20050Sstevel@tonic-gate break;
20060Sstevel@tonic-gate sl++;
20070Sstevel@tonic-gate }
20080Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_get_agid: AltGID = %llX:%llX",
20090Sstevel@tonic-gate a_gid.gid_prefix, a_gid.gid_guid);
20100Sstevel@tonic-gate
20110Sstevel@tonic-gate return (a_gid);
20120Sstevel@tonic-gate }
20130Sstevel@tonic-gate
20140Sstevel@tonic-gate /*
20150Sstevel@tonic-gate * Perform SA Access to retrieve Service Records.
20160Sstevel@tonic-gate * On Success, returns ServiceID and ServiceGID info in '*dinfo'.
20170Sstevel@tonic-gate */
20180Sstevel@tonic-gate static ibt_status_t
ibcm_saa_service_rec(ibcm_path_tqargs_t * p_arg,ibtl_cm_port_list_t * sl,ibcm_dinfo_t * dinfo)20190Sstevel@tonic-gate ibcm_saa_service_rec(ibcm_path_tqargs_t *p_arg, ibtl_cm_port_list_t *sl,
20200Sstevel@tonic-gate ibcm_dinfo_t *dinfo)
20210Sstevel@tonic-gate {
20220Sstevel@tonic-gate sa_service_record_t svcrec_req;
20230Sstevel@tonic-gate sa_service_record_t *svcrec_resp;
20240Sstevel@tonic-gate void *results_p;
20250Sstevel@tonic-gate uint64_t component_mask = 0;
20260Sstevel@tonic-gate size_t length;
2027401Shiremath uint8_t i, j, k, rec_found, s;
20280Sstevel@tonic-gate ibmf_saa_access_args_t access_args;
20290Sstevel@tonic-gate ibt_status_t retval;
20300Sstevel@tonic-gate ibt_path_attr_t *attrp = &p_arg->attr;
20310Sstevel@tonic-gate uint64_t tmp_sd_flag = attrp->pa_sd_flags;
20320Sstevel@tonic-gate uint8_t num_req;
20330Sstevel@tonic-gate
20340Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec(%p, %p)", p_arg, sl);
20350Sstevel@tonic-gate
20360Sstevel@tonic-gate bzero(&svcrec_req, sizeof (svcrec_req));
20370Sstevel@tonic-gate
20380Sstevel@tonic-gate /* Service Name */
20390Sstevel@tonic-gate if ((attrp->pa_sname != NULL) && (strlen(attrp->pa_sname) != 0)) {
20400Sstevel@tonic-gate (void) strncpy((char *)(svcrec_req.ServiceName),
20410Sstevel@tonic-gate attrp->pa_sname, IB_SVC_NAME_LEN);
20420Sstevel@tonic-gate
20430Sstevel@tonic-gate component_mask |= SA_SR_COMPMASK_NAME;
20440Sstevel@tonic-gate }
20450Sstevel@tonic-gate
20460Sstevel@tonic-gate /* Service ID */
20470Sstevel@tonic-gate if (attrp->pa_sid) {
20480Sstevel@tonic-gate svcrec_req.ServiceID = attrp->pa_sid;
20490Sstevel@tonic-gate component_mask |= SA_SR_COMPMASK_ID;
20500Sstevel@tonic-gate }
20510Sstevel@tonic-gate
20520Sstevel@tonic-gate /* Is P_Key Specified. */
20530Sstevel@tonic-gate if (p_arg->flags & IBT_PATH_PKEY) {
20540Sstevel@tonic-gate svcrec_req.ServiceP_Key = attrp->pa_pkey;
20550Sstevel@tonic-gate component_mask |= SA_SR_COMPMASK_PKEY;
20560Sstevel@tonic-gate }
20570Sstevel@tonic-gate
20580Sstevel@tonic-gate /* Is ServiceData Specified. */
20590Sstevel@tonic-gate if (attrp->pa_sd_flags != IBT_NO_SDATA) {
20600Sstevel@tonic-gate /* Handle endianess for service data. */
20610Sstevel@tonic-gate ibcm_swizzle_from_srv(&attrp->pa_sdata, svcrec_req.ServiceData);
20620Sstevel@tonic-gate
20630Sstevel@tonic-gate /*
20640Sstevel@tonic-gate * Lets not interpret each and every ServiceData flags,
20650Sstevel@tonic-gate * just pass it on to SAA. Shift the flag, to suit
20660Sstevel@tonic-gate * SA_SR_COMPMASK_ALL_DATA definition.
20670Sstevel@tonic-gate */
20680Sstevel@tonic-gate component_mask |= (tmp_sd_flag << 7);
20690Sstevel@tonic-gate }
20700Sstevel@tonic-gate
20710Sstevel@tonic-gate if (dinfo->num_dest == 1) {
20720Sstevel@tonic-gate
20730Sstevel@tonic-gate /* If a single DGID is specified, provide it */
20740Sstevel@tonic-gate svcrec_req.ServiceGID = dinfo->dest->d_gid;
20750Sstevel@tonic-gate component_mask |= SA_SR_COMPMASK_GID;
20760Sstevel@tonic-gate
20770Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec:%llX:%llX",
20780Sstevel@tonic-gate svcrec_req.ServiceGID.gid_prefix,
20790Sstevel@tonic-gate svcrec_req.ServiceGID.gid_guid);
20800Sstevel@tonic-gate }
20810Sstevel@tonic-gate
20820Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: "
20830Sstevel@tonic-gate "Perform SA Access: Mask: 0x%X", component_mask);
20840Sstevel@tonic-gate
20850Sstevel@tonic-gate /*
20860Sstevel@tonic-gate * Call in SA Access retrieve routine to get Service Records.
20870Sstevel@tonic-gate *
20880Sstevel@tonic-gate * SA Access framework allocated memory for the "results_p".
20890Sstevel@tonic-gate * Make sure to deallocate once we are done with the results_p.
20900Sstevel@tonic-gate * The size of the buffer allocated will be as returned in
20910Sstevel@tonic-gate * "length" field.
20920Sstevel@tonic-gate */
20930Sstevel@tonic-gate access_args.sq_attr_id = SA_SERVICERECORD_ATTRID;
20940Sstevel@tonic-gate access_args.sq_access_type = IBMF_SAA_RETRIEVE;
20950Sstevel@tonic-gate access_args.sq_component_mask = component_mask;
20960Sstevel@tonic-gate access_args.sq_template = &svcrec_req;
20970Sstevel@tonic-gate access_args.sq_template_length = sizeof (sa_service_record_t);
20980Sstevel@tonic-gate access_args.sq_callback = NULL;
20990Sstevel@tonic-gate access_args.sq_callback_arg = NULL;
21000Sstevel@tonic-gate
2101401Shiremath for (s = 0; s < sl->p_count; s++) {
2102401Shiremath retval = ibcm_contact_sa_access(sl[s].p_saa_hdl, &access_args,
2103401Shiremath &length, &results_p);
2104401Shiremath if (retval != IBT_SUCCESS)
2105401Shiremath if (sl[s].p_multi & IBTL_CM_MULTI_SM)
2106401Shiremath continue;
2107401Shiremath else
2108401Shiremath return (retval);
2109401Shiremath
2110401Shiremath if ((results_p == NULL) || (length == 0)) {
2111401Shiremath IBTF_DPRINTF_L2(cmlog, "ibcm_saa_service_rec: SvcRec "
2112401Shiremath "Not Found: res_p %p, len %d", results_p, length);
2113401Shiremath if (sl[s].p_multi & IBTL_CM_MULTI_SM) {
2114401Shiremath retval = IBT_SERVICE_RECORDS_NOT_FOUND;
2115401Shiremath continue;
2116401Shiremath } else
2117401Shiremath return (IBT_SERVICE_RECORDS_NOT_FOUND);
2118401Shiremath }
2119401Shiremath
2120401Shiremath /* if we are here, we got some records. so break. */
2121401Shiremath break;
2122401Shiremath }
2123401Shiremath
21240Sstevel@tonic-gate if (retval != IBT_SUCCESS)
21250Sstevel@tonic-gate return (retval);
21260Sstevel@tonic-gate
21270Sstevel@tonic-gate num_req = length / sizeof (sa_service_record_t);
21280Sstevel@tonic-gate
21290Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: Got %d Service Records.",
21300Sstevel@tonic-gate num_req);
21310Sstevel@tonic-gate
21320Sstevel@tonic-gate svcrec_resp = (sa_service_record_t *)results_p;
21330Sstevel@tonic-gate rec_found = 0;
21340Sstevel@tonic-gate
21350Sstevel@tonic-gate /* Update the return values. */
21360Sstevel@tonic-gate if (dinfo->num_dest) {
21370Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: Get ServiceRec "
21380Sstevel@tonic-gate "for Specified DGID: %d", dinfo->num_dest);
21390Sstevel@tonic-gate
21400Sstevel@tonic-gate for (i = 0; i < num_req; i++, svcrec_resp++) {
21410Sstevel@tonic-gate /* Limited P_Key is NOT supported as of now!. */
21420Sstevel@tonic-gate if ((svcrec_resp->ServiceP_Key & 0x8000) == 0) {
21430Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: "
21440Sstevel@tonic-gate "SvcPkey 0x%X limited, reject the record.",
21450Sstevel@tonic-gate svcrec_resp->ServiceP_Key);
21460Sstevel@tonic-gate continue;
21470Sstevel@tonic-gate }
21480Sstevel@tonic-gate
21490Sstevel@tonic-gate for (j = 0; j < dinfo->num_dest; j++) {
21500Sstevel@tonic-gate if (dinfo->dest[j].d_gid.gid_guid ==
21510Sstevel@tonic-gate svcrec_resp->ServiceGID.gid_guid) {
21520Sstevel@tonic-gate ibcm_fill_svcinfo(svcrec_resp,
21530Sstevel@tonic-gate &dinfo->dest[j]);
21540Sstevel@tonic-gate rec_found++;
21550Sstevel@tonic-gate }
21560Sstevel@tonic-gate if (rec_found == dinfo->num_dest)
21570Sstevel@tonic-gate break;
21580Sstevel@tonic-gate }
21590Sstevel@tonic-gate if (rec_found == dinfo->num_dest)
21600Sstevel@tonic-gate break;
21610Sstevel@tonic-gate }
21620Sstevel@tonic-gate if (rec_found != dinfo->num_dest) {
21630Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: Did NOT "
21640Sstevel@tonic-gate "find ServiceRec for all DGIDs: (%d/%d)", rec_found,
21650Sstevel@tonic-gate dinfo->num_dest);
21660Sstevel@tonic-gate retval = IBT_INSUFF_DATA;
21670Sstevel@tonic-gate }
21680Sstevel@tonic-gate } else if (p_arg->flags & IBT_PATH_APM) {
21690Sstevel@tonic-gate ib_gid_t p_gid, a_gid, last_p_gid;
21700Sstevel@tonic-gate ib_gid_t *gidp = NULL;
21710Sstevel@tonic-gate uint_t n_gids;
21720Sstevel@tonic-gate sa_service_record_t *stmp;
21730Sstevel@tonic-gate boolean_t pri_fill_done = B_FALSE;
21740Sstevel@tonic-gate boolean_t alt_fill_done = B_FALSE;
21750Sstevel@tonic-gate ib_pkey_t p_pkey = 0, a_pkey = 0;
21760Sstevel@tonic-gate
21770Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: Need to "
21780Sstevel@tonic-gate "find ServiceRec that can satisfy APM");
21790Sstevel@tonic-gate
21800Sstevel@tonic-gate p_gid.gid_prefix = p_gid.gid_guid = 0;
21810Sstevel@tonic-gate a_gid.gid_prefix = a_gid.gid_guid = 0;
21820Sstevel@tonic-gate last_p_gid.gid_prefix = last_p_gid.gid_guid = 0;
21830Sstevel@tonic-gate
21840Sstevel@tonic-gate for (i = 0; i < num_req; i++, svcrec_resp++) {
21850Sstevel@tonic-gate ibt_status_t ret;
21863826Shiremath boolean_t is_this_on_local_node = B_FALSE;
21870Sstevel@tonic-gate
21880Sstevel@tonic-gate /* Limited P_Key is NOT supported as of now!. */
21890Sstevel@tonic-gate if ((svcrec_resp->ServiceP_Key & 0x8000) == 0) {
21900Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: "
21910Sstevel@tonic-gate "SvcPkey 0x%X limited, reject the record.",
21920Sstevel@tonic-gate svcrec_resp->ServiceP_Key);
21930Sstevel@tonic-gate continue;
21940Sstevel@tonic-gate }
21950Sstevel@tonic-gate
21960Sstevel@tonic-gate p_gid = svcrec_resp->ServiceGID;
21970Sstevel@tonic-gate
21980Sstevel@tonic-gate /* Let's avoid LoopBack Nodes. */
21993826Shiremath for (j = 0; j < sl->p_count; j++) {
22003826Shiremath if (p_gid.gid_guid == sl[j].p_sgid.gid_guid) {
22013826Shiremath is_this_on_local_node = B_TRUE;
22023826Shiremath
22033826Shiremath IBTF_DPRINTF_L3(cmlog,
22043826Shiremath "ibcm_saa_service_rec: ServiceGID "
22053826Shiremath "%llX:%llX is on Local Node, "
22063826Shiremath "search for remote.",
22073826Shiremath p_gid.gid_prefix, p_gid.gid_guid);
22083826Shiremath }
22090Sstevel@tonic-gate }
22100Sstevel@tonic-gate
22119349SShantkumar.Hiremath@Sun.COM if (is_this_on_local_node) {
22120Sstevel@tonic-gate if ((i + 1) < num_req) {
22130Sstevel@tonic-gate p_gid.gid_prefix = 0;
22140Sstevel@tonic-gate p_gid.gid_guid = 0;
22150Sstevel@tonic-gate continue;
22160Sstevel@tonic-gate } else if (last_p_gid.gid_prefix != 0) {
22170Sstevel@tonic-gate p_gid = last_p_gid;
22180Sstevel@tonic-gate break;
22190Sstevel@tonic-gate }
22200Sstevel@tonic-gate }
22210Sstevel@tonic-gate
22220Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: "
22230Sstevel@tonic-gate "Finally let Primary DGID = %llX:%llX",
22240Sstevel@tonic-gate p_gid.gid_prefix, p_gid.gid_guid);
22250Sstevel@tonic-gate
22260Sstevel@tonic-gate ret = ibt_get_companion_port_gids(p_gid, 0, 0,
22270Sstevel@tonic-gate &gidp, &n_gids);
22280Sstevel@tonic-gate if (ret == IBT_SUCCESS) {
22290Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog,
22300Sstevel@tonic-gate "ibcm_saa_service_rec: Found %d "
22310Sstevel@tonic-gate "CompGID for %llX:%llX", n_gids,
22320Sstevel@tonic-gate p_gid.gid_prefix, p_gid.gid_guid);
22330Sstevel@tonic-gate
22340Sstevel@tonic-gate stmp = (sa_service_record_t *)results_p;
22350Sstevel@tonic-gate a_gid.gid_prefix = a_gid.gid_guid = 0;
22360Sstevel@tonic-gate
2237401Shiremath if (sl->p_multi & IBTL_CM_MULTI_SM) {
22380Sstevel@tonic-gate /* validate sn_pfx */
22390Sstevel@tonic-gate a_gid = ibcm_saa_get_agid(sl,
22400Sstevel@tonic-gate gidp, n_gids);
22410Sstevel@tonic-gate } else {
22420Sstevel@tonic-gate for (k = 0; k < num_req; k++) {
22430Sstevel@tonic-gate ib_gid_t sg = stmp->ServiceGID;
22440Sstevel@tonic-gate
22450Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog,
22460Sstevel@tonic-gate "ibcm_saa_service_rec: "
22470Sstevel@tonic-gate "SvcGID[%d] = %llX:%llX", k,
22480Sstevel@tonic-gate sg.gid_prefix, sg.gid_guid);
22490Sstevel@tonic-gate
22500Sstevel@tonic-gate for (j = 0; j < n_gids; j++) {
22510Sstevel@tonic-gate if (gidp[j].gid_guid ==
22520Sstevel@tonic-gate sg.gid_guid) {
22530Sstevel@tonic-gate a_gid = gidp[j];
22540Sstevel@tonic-gate break;
22550Sstevel@tonic-gate }
22560Sstevel@tonic-gate }
22570Sstevel@tonic-gate if (a_gid.gid_guid)
22580Sstevel@tonic-gate break;
22590Sstevel@tonic-gate stmp++;
22600Sstevel@tonic-gate }
22610Sstevel@tonic-gate if (a_gid.gid_guid == 0) {
22620Sstevel@tonic-gate /* Rec not found for Alt. */
22630Sstevel@tonic-gate for (j = 0; j < n_gids; j++) {
22640Sstevel@tonic-gate if (gidp[j].gid_prefix
22654703Shiremath == p_gid.
22664703Shiremath gid_prefix) {
22670Sstevel@tonic-gate a_gid = gidp[j];
22680Sstevel@tonic-gate break;
22690Sstevel@tonic-gate }
22700Sstevel@tonic-gate }
22710Sstevel@tonic-gate }
22720Sstevel@tonic-gate }
22730Sstevel@tonic-gate kmem_free(gidp,
22740Sstevel@tonic-gate n_gids * sizeof (ib_gid_t));
22750Sstevel@tonic-gate
22760Sstevel@tonic-gate if (a_gid.gid_guid)
22770Sstevel@tonic-gate break;
22780Sstevel@tonic-gate } else if (ret == IBT_GIDS_NOT_FOUND) {
22790Sstevel@tonic-gate last_p_gid = p_gid;
22800Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog,
22810Sstevel@tonic-gate "ibcm_saa_service_rec: Didn't find "
22820Sstevel@tonic-gate "CompGID for %llX:%llX, ret=%d",
22830Sstevel@tonic-gate p_gid.gid_prefix, p_gid.gid_guid,
22840Sstevel@tonic-gate ret);
22850Sstevel@tonic-gate } else {
22860Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog,
22870Sstevel@tonic-gate "ibcm_saa_service_rec: Call to "
22880Sstevel@tonic-gate "ibt_get_companion_port_gids(%llX:"
22890Sstevel@tonic-gate "%llX) Failed = %d",
22900Sstevel@tonic-gate p_gid.gid_prefix, p_gid.gid_guid,
22910Sstevel@tonic-gate ret);
22920Sstevel@tonic-gate }
22930Sstevel@tonic-gate }
22940Sstevel@tonic-gate
22950Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: \n\t"
22960Sstevel@tonic-gate "Pri DGID(%llX:%llX), Alt DGID(%llX:%llX)",
22970Sstevel@tonic-gate p_gid.gid_prefix, p_gid.gid_guid, a_gid.gid_prefix,
22980Sstevel@tonic-gate a_gid.gid_guid);
22990Sstevel@tonic-gate
23000Sstevel@tonic-gate svcrec_resp = (sa_service_record_t *)results_p;
23010Sstevel@tonic-gate
23020Sstevel@tonic-gate for (i = 0, j = 0; i < num_req; i++, svcrec_resp++) {
23030Sstevel@tonic-gate /* Limited P_Key is NOT supported as of now!. */
23040Sstevel@tonic-gate if ((svcrec_resp->ServiceP_Key & 0x8000) == 0) {
23050Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: "
23060Sstevel@tonic-gate "SvcPkey 0x%X limited, reject the record.",
23070Sstevel@tonic-gate svcrec_resp->ServiceP_Key);
23080Sstevel@tonic-gate continue;
23090Sstevel@tonic-gate }
23100Sstevel@tonic-gate
23119349SShantkumar.Hiremath@Sun.COM if ((!pri_fill_done) && (p_gid.gid_guid ==
23120Sstevel@tonic-gate svcrec_resp->ServiceGID.gid_guid)) {
23130Sstevel@tonic-gate p_pkey = svcrec_resp->ServiceP_Key;
23140Sstevel@tonic-gate if ((a_pkey != 0) &&
23150Sstevel@tonic-gate (a_pkey != p_pkey)) {
23160Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog,
23170Sstevel@tonic-gate "ibcm_saa_service_rec: "
23180Sstevel@tonic-gate "Pri(0x%X) & Alt (0x%X) "
23190Sstevel@tonic-gate "PKey must match.",
23200Sstevel@tonic-gate p_pkey, a_pkey);
23210Sstevel@tonic-gate p_pkey = 0;
23220Sstevel@tonic-gate continue;
23230Sstevel@tonic-gate }
23240Sstevel@tonic-gate ibcm_fill_svcinfo(svcrec_resp,
23250Sstevel@tonic-gate &dinfo->dest[j++]);
23260Sstevel@tonic-gate rec_found++;
23270Sstevel@tonic-gate pri_fill_done = B_TRUE;
23289349SShantkumar.Hiremath@Sun.COM } else if ((!alt_fill_done) && (a_gid.gid_guid ==
23290Sstevel@tonic-gate svcrec_resp->ServiceGID.gid_guid)) {
23300Sstevel@tonic-gate a_pkey = svcrec_resp->ServiceP_Key;
23310Sstevel@tonic-gate if ((p_pkey != 0) &&
23320Sstevel@tonic-gate (a_pkey != p_pkey)) {
23330Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog,
23340Sstevel@tonic-gate "ibcm_saa_service_rec: "
23350Sstevel@tonic-gate "Pri(0x%X) & Alt (0x%X) "
23360Sstevel@tonic-gate "PKey must match.",
23370Sstevel@tonic-gate p_pkey, a_pkey);
23380Sstevel@tonic-gate a_pkey = 0;
23390Sstevel@tonic-gate continue;
23400Sstevel@tonic-gate }
23410Sstevel@tonic-gate ibcm_fill_svcinfo(svcrec_resp,
23420Sstevel@tonic-gate &dinfo->dest[j++]);
23430Sstevel@tonic-gate rec_found++;
23440Sstevel@tonic-gate alt_fill_done = B_TRUE;
23450Sstevel@tonic-gate }
23460Sstevel@tonic-gate
23470Sstevel@tonic-gate if (rec_found == 2)
23480Sstevel@tonic-gate break;
23490Sstevel@tonic-gate }
23509349SShantkumar.Hiremath@Sun.COM if ((!alt_fill_done) && (a_gid.gid_guid)) {
23510Sstevel@tonic-gate dinfo->dest[j].d_gid = a_gid;
23520Sstevel@tonic-gate dinfo->dest[j].d_pkey = p_pkey;
23530Sstevel@tonic-gate rec_found++;
23540Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: "
23550Sstevel@tonic-gate "Let Alt Pkey=%X, DGID=%llX:%llX", p_pkey,
23560Sstevel@tonic-gate a_gid.gid_prefix, a_gid.gid_guid);
23570Sstevel@tonic-gate }
23580Sstevel@tonic-gate
23590Sstevel@tonic-gate if (rec_found == 1)
23600Sstevel@tonic-gate retval = IBT_INSUFF_DATA;
23610Sstevel@tonic-gate } else if (p_arg->flags & IBT_PATH_MULTI_SVC_DEST) {
23620Sstevel@tonic-gate for (i = 0; i < num_req; i++, svcrec_resp++) {
23633826Shiremath ib_gid_t p_gid;
23643826Shiremath boolean_t is_this_on_local_node = B_FALSE;
23653826Shiremath
23660Sstevel@tonic-gate /* Limited P_Key is NOT supported as of now!. */
23670Sstevel@tonic-gate if ((svcrec_resp->ServiceP_Key & 0x8000) == 0) {
23680Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: "
23690Sstevel@tonic-gate "SvcPkey 0x%X limited, reject the record.",
23700Sstevel@tonic-gate svcrec_resp->ServiceP_Key);
23710Sstevel@tonic-gate continue;
23720Sstevel@tonic-gate }
23733826Shiremath
23743826Shiremath p_gid = svcrec_resp->ServiceGID;
23753826Shiremath
23763826Shiremath /* Let's avoid LoopBack Nodes. */
23773826Shiremath for (j = 0; j < sl->p_count; j++) {
23783826Shiremath if (p_gid.gid_guid == sl[j].p_sgid.gid_guid) {
23793826Shiremath is_this_on_local_node = B_TRUE;
23803826Shiremath IBTF_DPRINTF_L3(cmlog,
23813826Shiremath "ibcm_saa_service_rec: ServiceGID "
23823826Shiremath "%llX:%llX is on Local Node, "
23833826Shiremath "search for remote.",
23843826Shiremath p_gid.gid_prefix, p_gid.gid_guid);
23853826Shiremath }
23863826Shiremath }
23873826Shiremath
23889349SShantkumar.Hiremath@Sun.COM if (is_this_on_local_node)
23893826Shiremath if ((i + 1) < num_req)
23903826Shiremath continue;
23913826Shiremath
23923826Shiremath IBTF_DPRINTF_L4(cmlog, "ibcm_saa_service_rec: "
23933826Shiremath "Found ServiceGID = %llX:%llX",
23943826Shiremath p_gid.gid_prefix, p_gid.gid_guid);
23953826Shiremath
23960Sstevel@tonic-gate ibcm_fill_svcinfo(svcrec_resp,
23970Sstevel@tonic-gate &dinfo->dest[rec_found]);
23980Sstevel@tonic-gate rec_found++;
23990Sstevel@tonic-gate if (rec_found == p_arg->max_paths)
24000Sstevel@tonic-gate break;
24010Sstevel@tonic-gate }
24020Sstevel@tonic-gate
24030Sstevel@tonic-gate if (rec_found < p_arg->max_paths)
24040Sstevel@tonic-gate retval = IBT_INSUFF_DATA;
24050Sstevel@tonic-gate } else {
24060Sstevel@tonic-gate for (i = 0; i < num_req; i++) {
24070Sstevel@tonic-gate /* Limited P_Key is NOT supported as of now!. */
24080Sstevel@tonic-gate if ((svcrec_resp->ServiceP_Key & 0x8000) == 0) {
24090Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: "
24100Sstevel@tonic-gate "SvcPkey 0x%X limited, reject the record.",
24110Sstevel@tonic-gate svcrec_resp->ServiceP_Key);
24120Sstevel@tonic-gate svcrec_resp++;
24130Sstevel@tonic-gate continue;
24140Sstevel@tonic-gate }
24150Sstevel@tonic-gate
24160Sstevel@tonic-gate ibcm_fill_svcinfo(svcrec_resp, &dinfo->dest[0]);
24170Sstevel@tonic-gate rec_found = 1;
24180Sstevel@tonic-gate
24190Sstevel@tonic-gate /* Avoid having loopback node */
24200Sstevel@tonic-gate if (svcrec_resp->ServiceGID.gid_guid !=
24210Sstevel@tonic-gate sl->p_sgid.gid_guid) {
24220Sstevel@tonic-gate break;
24230Sstevel@tonic-gate } else {
24240Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: "
24250Sstevel@tonic-gate "avoid LoopBack node.");
24260Sstevel@tonic-gate svcrec_resp++;
24270Sstevel@tonic-gate }
24280Sstevel@tonic-gate }
24290Sstevel@tonic-gate }
24300Sstevel@tonic-gate
24310Sstevel@tonic-gate /* Deallocate the memory for results_p. */
24320Sstevel@tonic-gate kmem_free(results_p, length);
24330Sstevel@tonic-gate if (dinfo->num_dest == 0)
24340Sstevel@tonic-gate dinfo->num_dest = rec_found;
24350Sstevel@tonic-gate
24360Sstevel@tonic-gate /*
24370Sstevel@tonic-gate * Check out whether all Service Path we looking for are on the same
24380Sstevel@tonic-gate * P_key. If yes, then set the global p_key field with that value,
24390Sstevel@tonic-gate * to make it easy during SA Path Query.
24400Sstevel@tonic-gate */
24410Sstevel@tonic-gate if ((dinfo->num_dest) && (dinfo->p_key == 0)) {
24420Sstevel@tonic-gate ib_pkey_t pk = dinfo->dest[0].d_pkey;
24430Sstevel@tonic-gate
24440Sstevel@tonic-gate if (dinfo->num_dest == 1) {
24450Sstevel@tonic-gate dinfo->p_key = pk;
24460Sstevel@tonic-gate } else {
24470Sstevel@tonic-gate for (i = 1; i < (dinfo->num_dest - 1); i++) {
24480Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: "
24490Sstevel@tonic-gate "pk= 0x%X, pk[%d]= 0x%X", pk, i,
24500Sstevel@tonic-gate dinfo->dest[i].d_pkey);
24510Sstevel@tonic-gate if (pk != dinfo->dest[i].d_pkey) {
24520Sstevel@tonic-gate dinfo->p_key = 0;
24530Sstevel@tonic-gate break;
24540Sstevel@tonic-gate } else {
24550Sstevel@tonic-gate dinfo->p_key = pk;
24560Sstevel@tonic-gate }
24570Sstevel@tonic-gate }
24580Sstevel@tonic-gate }
24590Sstevel@tonic-gate }
24600Sstevel@tonic-gate
24610Sstevel@tonic-gate if (rec_found == 0) {
24620Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_saa_service_rec: "
24630Sstevel@tonic-gate "ServiceRec NOT Found");
24640Sstevel@tonic-gate retval = IBT_SERVICE_RECORDS_NOT_FOUND;
24650Sstevel@tonic-gate }
24660Sstevel@tonic-gate
24670Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_saa_service_rec: done. Status %d, "
24680Sstevel@tonic-gate "PKey 0x%X, Found %d SvcRec", retval, dinfo->p_key, rec_found);
24690Sstevel@tonic-gate
24700Sstevel@tonic-gate return (retval);
24710Sstevel@tonic-gate }
24720Sstevel@tonic-gate
24730Sstevel@tonic-gate
24740Sstevel@tonic-gate static boolean_t
ibcm_compare_paths(sa_path_record_t * pr_resp,ibt_cep_path_t * rc_path,ibtl_cm_hca_port_t * c_hp)24750Sstevel@tonic-gate ibcm_compare_paths(sa_path_record_t *pr_resp, ibt_cep_path_t *rc_path,
24760Sstevel@tonic-gate ibtl_cm_hca_port_t *c_hp)
24770Sstevel@tonic-gate {
24780Sstevel@tonic-gate if ((rc_path->cep_hca_port_num == c_hp->hp_port) &&
24790Sstevel@tonic-gate (rc_path->cep_adds_vect.av_src_path ==
24800Sstevel@tonic-gate (pr_resp->SLID - c_hp->hp_base_lid)) &&
24810Sstevel@tonic-gate (rc_path->cep_adds_vect.av_dlid == pr_resp->DLID) &&
24820Sstevel@tonic-gate (rc_path->cep_adds_vect.av_srate == pr_resp->Rate)) {
24830Sstevel@tonic-gate return (B_TRUE);
24840Sstevel@tonic-gate } else {
24850Sstevel@tonic-gate return (B_FALSE);
24860Sstevel@tonic-gate }
24870Sstevel@tonic-gate }
24880Sstevel@tonic-gate
24890Sstevel@tonic-gate /*
24900Sstevel@tonic-gate * ibcm_get_comp_pgids() routine gets the companion port for 'gid'.
24910Sstevel@tonic-gate *
24920Sstevel@tonic-gate * On success:
24930Sstevel@tonic-gate * If 'n_gid' is specified, then verify whether 'n_gid' is indeed a
24940Sstevel@tonic-gate * companion portgid of 'gid'. If matches return success or else error.
24950Sstevel@tonic-gate *
24960Sstevel@tonic-gate * If 'n_gid' is NOT specified, then return back SUCCESS along with
24970Sstevel@tonic-gate * obtained Companion PortGids 'gid_p', where 'num' indicated number
24980Sstevel@tonic-gate * of companion portgids returned in 'gid_p'.
24990Sstevel@tonic-gate */
25000Sstevel@tonic-gate
25010Sstevel@tonic-gate static ibt_status_t
ibcm_get_comp_pgids(ib_gid_t gid,ib_gid_t n_gid,ib_guid_t hca_guid,ib_gid_t ** gid_p,uint_t * num)25020Sstevel@tonic-gate ibcm_get_comp_pgids(ib_gid_t gid, ib_gid_t n_gid, ib_guid_t hca_guid,
25030Sstevel@tonic-gate ib_gid_t **gid_p, uint_t *num)
25040Sstevel@tonic-gate {
25050Sstevel@tonic-gate ibt_status_t ret;
25060Sstevel@tonic-gate int i;
25070Sstevel@tonic-gate
25080Sstevel@tonic-gate ret = ibt_get_companion_port_gids(gid, hca_guid, 0, gid_p, num);
25090Sstevel@tonic-gate if ((ret != IBT_SUCCESS) && (ret != IBT_GIDS_NOT_FOUND)) {
25100Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_get_comp_pgids: "
25110Sstevel@tonic-gate "ibt_get_companion_port_gids(%llX:%llX) Failed: %d",
25120Sstevel@tonic-gate gid.gid_prefix, gid.gid_guid, ret);
25130Sstevel@tonic-gate } else if ((ret == IBT_GIDS_NOT_FOUND) && (n_gid.gid_guid != 0)) {
25140Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_get_comp_pgids: Specified GID "
25150Sstevel@tonic-gate "(%llX:%llX) is NOT a Companion \n\t to current channel's "
25160Sstevel@tonic-gate "GID(%llX:%llX)", n_gid.gid_prefix, n_gid.gid_guid,
25170Sstevel@tonic-gate gid.gid_prefix, gid.gid_guid);
25180Sstevel@tonic-gate ret = IBT_INVALID_PARAM;
25190Sstevel@tonic-gate } else if (n_gid.gid_guid != 0) {
25200Sstevel@tonic-gate /*
25210Sstevel@tonic-gate * We found some Comp GIDs and n_gid is specified. Validate
25220Sstevel@tonic-gate * whether the 'n_gid' specified is indeed the companion port
25230Sstevel@tonic-gate * GID of 'gid'.
25240Sstevel@tonic-gate */
25250Sstevel@tonic-gate for (i = 0; i < *num; i++) {
25260Sstevel@tonic-gate if ((n_gid.gid_prefix == gid_p[i]->gid_prefix) &&
25270Sstevel@tonic-gate (n_gid.gid_guid == gid_p[i]->gid_guid)) {
25280Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_get_comp_pgids: "
25290Sstevel@tonic-gate "Matching Found!. Done.");
25300Sstevel@tonic-gate return (IBT_SUCCESS);
25310Sstevel@tonic-gate }
25320Sstevel@tonic-gate }
25330Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibcm_get_comp_pgids: GID (%llX:%llX)\n"
25340Sstevel@tonic-gate "\t and (%llX:%llX) are NOT Companion Port GIDS",
25350Sstevel@tonic-gate n_gid.gid_prefix, n_gid.gid_guid, gid.gid_prefix,
25360Sstevel@tonic-gate gid.gid_guid);
25370Sstevel@tonic-gate ret = IBT_INVALID_PARAM;
25380Sstevel@tonic-gate } else {
25390Sstevel@tonic-gate ret = IBT_SUCCESS;
25400Sstevel@tonic-gate }
25410Sstevel@tonic-gate
25420Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibcm_get_comp_pgids: done. Status = %d", ret);
25430Sstevel@tonic-gate return (ret);
25440Sstevel@tonic-gate }
25450Sstevel@tonic-gate
25460Sstevel@tonic-gate /*
25470Sstevel@tonic-gate * Function:
25480Sstevel@tonic-gate * ibt_get_alt_path
25490Sstevel@tonic-gate * Input:
25500Sstevel@tonic-gate * rc_chan An RC channel handle returned in a previous call
25510Sstevel@tonic-gate * ibt_alloc_rc_channel(9F), specifies the channel to open.
25520Sstevel@tonic-gate * flags Path flags.
25530Sstevel@tonic-gate * attrp A pointer to an ibt_alt_path_attr_t(9S) structure that
25540Sstevel@tonic-gate * specifies required attributes of the selected path(s).
25550Sstevel@tonic-gate * Output:
25560Sstevel@tonic-gate * api_p An ibt_alt_path_info_t(9S) struct filled in as output
25570Sstevel@tonic-gate * parameters.
25580Sstevel@tonic-gate * Returns:
25590Sstevel@tonic-gate * IBT_SUCCESS on Success else appropriate error.
25600Sstevel@tonic-gate * Description:
25610Sstevel@tonic-gate * Finds the best alternate path to a specified channel (as determined by
25620Sstevel@tonic-gate * the IBTL) that satisfies the requirements specified in an
25630Sstevel@tonic-gate * ibt_alt_path_attr_t struct. The specified channel must have been
25640Sstevel@tonic-gate * previously opened successfully using ibt_open_rc_channel.
25650Sstevel@tonic-gate * This function also ensures that the service being accessed by the
25660Sstevel@tonic-gate * channel is available at the selected alternate port.
25670Sstevel@tonic-gate *
25680Sstevel@tonic-gate * Note: The apa_dgid must be on the same destination channel adapter,
25690Sstevel@tonic-gate * if specified.
25700Sstevel@tonic-gate * This routine can not be called from interrupt context.
25710Sstevel@tonic-gate */
25720Sstevel@tonic-gate ibt_status_t
ibt_get_alt_path(ibt_channel_hdl_t rc_chan,ibt_path_flags_t flags,ibt_alt_path_attr_t * attrp,ibt_alt_path_info_t * api_p)25730Sstevel@tonic-gate ibt_get_alt_path(ibt_channel_hdl_t rc_chan, ibt_path_flags_t flags,
25740Sstevel@tonic-gate ibt_alt_path_attr_t *attrp, ibt_alt_path_info_t *api_p)
25750Sstevel@tonic-gate {
25760Sstevel@tonic-gate sa_multipath_record_t *mpr_req;
25770Sstevel@tonic-gate sa_path_record_t *pr_resp;
25780Sstevel@tonic-gate ibmf_saa_access_args_t access_args;
25790Sstevel@tonic-gate ibt_qp_query_attr_t qp_attr;
25800Sstevel@tonic-gate ibtl_cm_hca_port_t c_hp, n_hp;
25810Sstevel@tonic-gate ibcm_hca_info_t *hcap;
25820Sstevel@tonic-gate void *results_p;
25830Sstevel@tonic-gate uint64_t c_mask = 0;
25840Sstevel@tonic-gate ib_gid_t *gid_ptr = NULL;
25850Sstevel@tonic-gate ib_gid_t *sgids_p = NULL, *dgids_p = NULL;
25860Sstevel@tonic-gate ib_gid_t cur_dgid, cur_sgid;
25870Sstevel@tonic-gate ib_gid_t new_dgid, new_sgid;
25880Sstevel@tonic-gate ibmf_saa_handle_t saa_handle;
25890Sstevel@tonic-gate size_t length;
25900Sstevel@tonic-gate int i, j, template_len, rec_found;
25910Sstevel@tonic-gate uint_t snum = 0, dnum = 0, num_rec;
25920Sstevel@tonic-gate ibt_status_t retval;
25930Sstevel@tonic-gate ib_mtu_t prim_mtu;
25940Sstevel@tonic-gate
25950Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path(%p, %x, %p, %p)",
25960Sstevel@tonic-gate rc_chan, flags, attrp, api_p);
25970Sstevel@tonic-gate
25980Sstevel@tonic-gate /* validate channel */
25990Sstevel@tonic-gate if (IBCM_INVALID_CHANNEL(rc_chan)) {
26000Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: invalid channel");
26010Sstevel@tonic-gate return (IBT_CHAN_HDL_INVALID);
26020Sstevel@tonic-gate }
26030Sstevel@tonic-gate
26040Sstevel@tonic-gate if (api_p == NULL) {
26050Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: invalid attribute: "
26060Sstevel@tonic-gate " AltPathInfo can't be NULL");
26070Sstevel@tonic-gate return (IBT_INVALID_PARAM);
26080Sstevel@tonic-gate }
26090Sstevel@tonic-gate
26100Sstevel@tonic-gate retval = ibt_query_qp(rc_chan, &qp_attr);
26110Sstevel@tonic-gate if (retval != IBT_SUCCESS) {
26120Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: ibt_query_qp(%p) "
26130Sstevel@tonic-gate "failed %d", rc_chan, retval);
26140Sstevel@tonic-gate return (retval);
26150Sstevel@tonic-gate }
26160Sstevel@tonic-gate
26170Sstevel@tonic-gate if (qp_attr.qp_info.qp_trans != IBT_RC_SRV) {
26180Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: "
26190Sstevel@tonic-gate "Invalid Channel type: Applicable only to RC Channel");
26200Sstevel@tonic-gate return (IBT_CHAN_SRV_TYPE_INVALID);
26210Sstevel@tonic-gate }
26220Sstevel@tonic-gate
26230Sstevel@tonic-gate cur_dgid =
26240Sstevel@tonic-gate qp_attr.qp_info.qp_transport.rc.rc_path.cep_adds_vect.av_dgid;
26250Sstevel@tonic-gate cur_sgid =
26260Sstevel@tonic-gate qp_attr.qp_info.qp_transport.rc.rc_path.cep_adds_vect.av_sgid;
26270Sstevel@tonic-gate prim_mtu = qp_attr.qp_info.qp_transport.rc.rc_path_mtu;
26280Sstevel@tonic-gate
26290Sstevel@tonic-gate /* If optional attributes are specified, validate them. */
26300Sstevel@tonic-gate if (attrp) {
26310Sstevel@tonic-gate new_dgid = attrp->apa_dgid;
26320Sstevel@tonic-gate new_sgid = attrp->apa_sgid;
26330Sstevel@tonic-gate } else {
26340Sstevel@tonic-gate new_dgid.gid_prefix = 0;
26350Sstevel@tonic-gate new_dgid.gid_guid = 0;
26360Sstevel@tonic-gate new_sgid.gid_prefix = 0;
26370Sstevel@tonic-gate new_sgid.gid_guid = 0;
26380Sstevel@tonic-gate }
26390Sstevel@tonic-gate
26400Sstevel@tonic-gate if ((new_dgid.gid_prefix != 0) && (new_sgid.gid_prefix != 0) &&
26410Sstevel@tonic-gate (new_dgid.gid_prefix != new_sgid.gid_prefix)) {
26420Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: Specified SGID's "
26430Sstevel@tonic-gate "SNprefix (%llX) doesn't match with \n specified DGID's "
26440Sstevel@tonic-gate "SNprefix: %llX", new_sgid.gid_prefix, new_dgid.gid_prefix);
26450Sstevel@tonic-gate return (IBT_INVALID_PARAM);
26460Sstevel@tonic-gate }
26470Sstevel@tonic-gate
26480Sstevel@tonic-gate /* For the specified SGID, get HCA information. */
26490Sstevel@tonic-gate retval = ibtl_cm_get_hca_port(cur_sgid, 0, &c_hp);
26500Sstevel@tonic-gate if (retval != IBT_SUCCESS) {
26510Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: "
26520Sstevel@tonic-gate "Get HCA Port Failed: %d", retval);
26530Sstevel@tonic-gate return (retval);
26540Sstevel@tonic-gate }
26550Sstevel@tonic-gate
26560Sstevel@tonic-gate hcap = ibcm_find_hca_entry(c_hp.hp_hca_guid);
26570Sstevel@tonic-gate if (hcap == NULL) {
26580Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: NO HCA found");
26590Sstevel@tonic-gate return (IBT_HCA_BUSY_DETACHING);
26600Sstevel@tonic-gate }
26610Sstevel@tonic-gate
26620Sstevel@tonic-gate /* Validate whether this HCA support APM */
26630Sstevel@tonic-gate if (!(hcap->hca_caps & IBT_HCA_AUTO_PATH_MIG)) {
26640Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: "
26650Sstevel@tonic-gate "HCA (%llX) - APM NOT SUPPORTED ", c_hp.hp_hca_guid);
26660Sstevel@tonic-gate retval = IBT_APM_NOT_SUPPORTED;
26670Sstevel@tonic-gate goto get_alt_path_done;
26680Sstevel@tonic-gate }
26690Sstevel@tonic-gate
26700Sstevel@tonic-gate /* Get Companion Port GID of the current Channel's SGID */
26710Sstevel@tonic-gate if ((new_sgid.gid_guid == 0) || ((new_sgid.gid_guid != 0) &&
26720Sstevel@tonic-gate (new_sgid.gid_guid != cur_sgid.gid_guid))) {
26730Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path: SRC: "
26740Sstevel@tonic-gate "Get Companion PortGids for - %llX:%llX",
26750Sstevel@tonic-gate cur_sgid.gid_prefix, cur_sgid.gid_guid);
26760Sstevel@tonic-gate
26770Sstevel@tonic-gate retval = ibcm_get_comp_pgids(cur_sgid, new_sgid,
26780Sstevel@tonic-gate c_hp.hp_hca_guid, &sgids_p, &snum);
26790Sstevel@tonic-gate if (retval != IBT_SUCCESS)
26800Sstevel@tonic-gate goto get_alt_path_done;
26810Sstevel@tonic-gate }
26820Sstevel@tonic-gate
26830Sstevel@tonic-gate /* Get Companion Port GID of the current Channel's DGID */
26840Sstevel@tonic-gate if ((new_dgid.gid_guid == 0) || ((new_dgid.gid_guid != 0) &&
26850Sstevel@tonic-gate (new_dgid.gid_guid != cur_dgid.gid_guid))) {
26860Sstevel@tonic-gate
26870Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path: DEST: "
26880Sstevel@tonic-gate "Get Companion PortGids for - %llX:%llX",
26890Sstevel@tonic-gate cur_dgid.gid_prefix, cur_dgid.gid_guid);
26900Sstevel@tonic-gate
26910Sstevel@tonic-gate retval = ibcm_get_comp_pgids(cur_dgid, new_dgid, 0, &dgids_p,
26920Sstevel@tonic-gate &dnum);
26930Sstevel@tonic-gate if (retval != IBT_SUCCESS)
26940Sstevel@tonic-gate goto get_alt_path_done;
26950Sstevel@tonic-gate }
26960Sstevel@tonic-gate
26970Sstevel@tonic-gate if ((new_dgid.gid_guid == 0) || (new_sgid.gid_guid == 0)) {
26980Sstevel@tonic-gate if (new_sgid.gid_guid == 0) {
26990Sstevel@tonic-gate for (i = 0; i < snum; i++) {
27000Sstevel@tonic-gate if (new_dgid.gid_guid == 0) {
27010Sstevel@tonic-gate for (j = 0; j < dnum; j++) {
27020Sstevel@tonic-gate if (sgids_p[i].gid_prefix ==
27030Sstevel@tonic-gate dgids_p[j].gid_prefix) {
27040Sstevel@tonic-gate new_dgid = dgids_p[j];
27050Sstevel@tonic-gate new_sgid = sgids_p[i];
27060Sstevel@tonic-gate
27070Sstevel@tonic-gate goto get_alt_proceed;
27080Sstevel@tonic-gate }
27090Sstevel@tonic-gate }
27100Sstevel@tonic-gate /* Current DGID */
27110Sstevel@tonic-gate if (sgids_p[i].gid_prefix ==
27120Sstevel@tonic-gate cur_dgid.gid_prefix) {
27130Sstevel@tonic-gate new_sgid = sgids_p[i];
27140Sstevel@tonic-gate goto get_alt_proceed;
27150Sstevel@tonic-gate }
27160Sstevel@tonic-gate } else {
27170Sstevel@tonic-gate if (sgids_p[i].gid_prefix ==
27180Sstevel@tonic-gate new_dgid.gid_prefix) {
27190Sstevel@tonic-gate new_sgid = sgids_p[i];
27200Sstevel@tonic-gate goto get_alt_proceed;
27210Sstevel@tonic-gate }
27220Sstevel@tonic-gate }
27230Sstevel@tonic-gate }
27240Sstevel@tonic-gate /* Current SGID */
27250Sstevel@tonic-gate if (new_dgid.gid_guid == 0) {
27260Sstevel@tonic-gate for (j = 0; j < dnum; j++) {
27270Sstevel@tonic-gate if (cur_sgid.gid_prefix ==
27280Sstevel@tonic-gate dgids_p[j].gid_prefix) {
27290Sstevel@tonic-gate new_dgid = dgids_p[j];
27300Sstevel@tonic-gate
27310Sstevel@tonic-gate goto get_alt_proceed;
27320Sstevel@tonic-gate }
27330Sstevel@tonic-gate }
27340Sstevel@tonic-gate }
27350Sstevel@tonic-gate } else if (new_dgid.gid_guid == 0) {
27360Sstevel@tonic-gate for (i = 0; i < dnum; i++) {
27370Sstevel@tonic-gate if (dgids_p[i].gid_prefix ==
27380Sstevel@tonic-gate new_sgid.gid_prefix) {
27390Sstevel@tonic-gate new_dgid = dgids_p[i];
27400Sstevel@tonic-gate goto get_alt_proceed;
27410Sstevel@tonic-gate }
27420Sstevel@tonic-gate }
27430Sstevel@tonic-gate /* Current DGID */
27440Sstevel@tonic-gate if (cur_dgid.gid_prefix == new_sgid.gid_prefix) {
27450Sstevel@tonic-gate goto get_alt_proceed;
27460Sstevel@tonic-gate }
27470Sstevel@tonic-gate }
27480Sstevel@tonic-gate /*
27490Sstevel@tonic-gate * hmm... No Companion Ports available.
27500Sstevel@tonic-gate * so we will be using current or specified attributes only.
27510Sstevel@tonic-gate */
27520Sstevel@tonic-gate }
27530Sstevel@tonic-gate
27540Sstevel@tonic-gate get_alt_proceed:
27550Sstevel@tonic-gate
27560Sstevel@tonic-gate if (new_sgid.gid_guid != 0) {
27570Sstevel@tonic-gate retval = ibtl_cm_get_hca_port(new_sgid, 0, &n_hp);
27580Sstevel@tonic-gate if (retval != IBT_SUCCESS) {
27590Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: "
27600Sstevel@tonic-gate "Get HCA Port Failed: %d", retval);
27610Sstevel@tonic-gate goto get_alt_path_done;
27620Sstevel@tonic-gate }
27630Sstevel@tonic-gate }
27640Sstevel@tonic-gate
27650Sstevel@tonic-gate /* Calculate the size for multi-path records template */
27660Sstevel@tonic-gate template_len = (2 * sizeof (ib_gid_t)) + sizeof (sa_multipath_record_t);
27670Sstevel@tonic-gate
27680Sstevel@tonic-gate mpr_req = kmem_zalloc(template_len, KM_SLEEP);
27690Sstevel@tonic-gate
27700Sstevel@tonic-gate ASSERT(mpr_req != NULL);
27710Sstevel@tonic-gate
27720Sstevel@tonic-gate _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mpr_req))
27730Sstevel@tonic-gate
27740Sstevel@tonic-gate gid_ptr = (ib_gid_t *)(((uchar_t *)mpr_req) +
27750Sstevel@tonic-gate sizeof (sa_multipath_record_t));
27760Sstevel@tonic-gate
27770Sstevel@tonic-gate /* SGID */
27780Sstevel@tonic-gate if (new_sgid.gid_guid == 0)
27790Sstevel@tonic-gate *gid_ptr = cur_sgid;
27800Sstevel@tonic-gate else
27810Sstevel@tonic-gate *gid_ptr = new_sgid;
27820Sstevel@tonic-gate
27830Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path: Get Path Between "
27840Sstevel@tonic-gate " SGID : %llX:%llX", gid_ptr->gid_prefix, gid_ptr->gid_guid);
27850Sstevel@tonic-gate
27860Sstevel@tonic-gate gid_ptr++;
27870Sstevel@tonic-gate
27880Sstevel@tonic-gate /* DGID */
27890Sstevel@tonic-gate if (new_dgid.gid_guid == 0)
27900Sstevel@tonic-gate *gid_ptr = cur_dgid;
27910Sstevel@tonic-gate else
27920Sstevel@tonic-gate *gid_ptr = new_dgid;
27930Sstevel@tonic-gate
27940Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path:\t\t DGID : %llX:%llX",
27950Sstevel@tonic-gate gid_ptr->gid_prefix, gid_ptr->gid_guid);
27960Sstevel@tonic-gate
27970Sstevel@tonic-gate mpr_req->SGIDCount = 1;
27980Sstevel@tonic-gate c_mask = SA_MPR_COMPMASK_SGIDCOUNT;
27990Sstevel@tonic-gate
28000Sstevel@tonic-gate mpr_req->DGIDCount = 1;
28010Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_DGIDCOUNT;
28020Sstevel@tonic-gate
28030Sstevel@tonic-gate /* Is Flow Label Specified. */
28040Sstevel@tonic-gate if (attrp) {
28050Sstevel@tonic-gate if (attrp->apa_flow) {
28060Sstevel@tonic-gate mpr_req->FlowLabel = attrp->apa_flow;
28070Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_FLOWLABEL;
28080Sstevel@tonic-gate }
28090Sstevel@tonic-gate
28100Sstevel@tonic-gate /* Is HopLimit Specified. */
28110Sstevel@tonic-gate if (flags & IBT_PATH_HOP) {
28120Sstevel@tonic-gate mpr_req->HopLimit = attrp->apa_hop;
28130Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_HOPLIMIT;
28140Sstevel@tonic-gate }
28150Sstevel@tonic-gate
28160Sstevel@tonic-gate /* Is TClass Specified. */
28170Sstevel@tonic-gate if (attrp->apa_tclass) {
28180Sstevel@tonic-gate mpr_req->TClass = attrp->apa_tclass;
28190Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_TCLASS;
28200Sstevel@tonic-gate }
28210Sstevel@tonic-gate
28220Sstevel@tonic-gate /* Is SL specified. */
28230Sstevel@tonic-gate if (attrp->apa_sl) {
28240Sstevel@tonic-gate mpr_req->SL = attrp->apa_sl;
28250Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_SL;
28260Sstevel@tonic-gate }
28270Sstevel@tonic-gate
28280Sstevel@tonic-gate if (flags & IBT_PATH_PERF) {
28290Sstevel@tonic-gate mpr_req->PacketLifeTimeSelector = IBT_BEST;
28300Sstevel@tonic-gate mpr_req->RateSelector = IBT_BEST;
28310Sstevel@tonic-gate
28320Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_PKTLTSELECTOR |
28330Sstevel@tonic-gate SA_MPR_COMPMASK_RATESELECTOR;
28340Sstevel@tonic-gate } else {
28350Sstevel@tonic-gate if (attrp->apa_pkt_lt.p_selector == IBT_BEST) {
28360Sstevel@tonic-gate mpr_req->PacketLifeTimeSelector = IBT_BEST;
28370Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_PKTLTSELECTOR;
28380Sstevel@tonic-gate }
28390Sstevel@tonic-gate
28400Sstevel@tonic-gate if (attrp->apa_srate.r_selector == IBT_BEST) {
28410Sstevel@tonic-gate mpr_req->RateSelector = IBT_BEST;
28420Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_RATESELECTOR;
28430Sstevel@tonic-gate }
28440Sstevel@tonic-gate }
28450Sstevel@tonic-gate
28460Sstevel@tonic-gate /*
28470Sstevel@tonic-gate * Honor individual selection of these attributes,
28480Sstevel@tonic-gate * even if IBT_PATH_PERF is set.
28490Sstevel@tonic-gate */
28500Sstevel@tonic-gate /* Check out whether Packet Life Time is specified. */
28510Sstevel@tonic-gate if (attrp->apa_pkt_lt.p_pkt_lt) {
28520Sstevel@tonic-gate mpr_req->PacketLifeTime =
28530Sstevel@tonic-gate ibt_usec2ib(attrp->apa_pkt_lt.p_pkt_lt);
28540Sstevel@tonic-gate mpr_req->PacketLifeTimeSelector =
28550Sstevel@tonic-gate attrp->apa_pkt_lt.p_selector;
28560Sstevel@tonic-gate
28570Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_PKTLT |
28580Sstevel@tonic-gate SA_MPR_COMPMASK_PKTLTSELECTOR;
28590Sstevel@tonic-gate }
28600Sstevel@tonic-gate
28610Sstevel@tonic-gate /* Is SRATE specified. */
28620Sstevel@tonic-gate if (attrp->apa_srate.r_srate) {
28630Sstevel@tonic-gate mpr_req->Rate = attrp->apa_srate.r_srate;
28640Sstevel@tonic-gate mpr_req->RateSelector = attrp->apa_srate.r_selector;
28650Sstevel@tonic-gate
28660Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_RATE |
28670Sstevel@tonic-gate SA_MPR_COMPMASK_RATESELECTOR;
28680Sstevel@tonic-gate }
28690Sstevel@tonic-gate }
28700Sstevel@tonic-gate
28710Sstevel@tonic-gate /* Alt PathMTU can be GT or EQU to current channel's Pri PathMTU */
28720Sstevel@tonic-gate
28730Sstevel@tonic-gate /* P_Key must be same as that of primary path */
28740Sstevel@tonic-gate retval = ibt_index2pkey_byguid(c_hp.hp_hca_guid, c_hp.hp_port,
28750Sstevel@tonic-gate qp_attr.qp_info.qp_transport.rc.rc_path.cep_pkey_ix,
28760Sstevel@tonic-gate &mpr_req->P_Key);
28770Sstevel@tonic-gate if (retval != IBT_SUCCESS) {
28780Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: Idx2Pkey Failed: %d",
28790Sstevel@tonic-gate retval);
28800Sstevel@tonic-gate goto get_alt_path_done;
28810Sstevel@tonic-gate }
28820Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_PKEY;
28830Sstevel@tonic-gate
28840Sstevel@tonic-gate mpr_req->Reversible = 1; /* We always get REVERSIBLE paths. */
28850Sstevel@tonic-gate mpr_req->IndependenceSelector = 1;
28860Sstevel@tonic-gate c_mask |= SA_MPR_COMPMASK_REVERSIBLE | SA_MPR_COMPMASK_INDEPSEL;
28870Sstevel@tonic-gate
28880Sstevel@tonic-gate _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*mpr_req))
28890Sstevel@tonic-gate
28900Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path: CMask: 0x%llX", c_mask);
28910Sstevel@tonic-gate
28920Sstevel@tonic-gate /* NOTE: We will **NOT** specify how many records we want. */
28930Sstevel@tonic-gate
28940Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path: Primary: MTU %d, PKey[%d]="
28950Sstevel@tonic-gate "0x%X\n\tSGID = %llX:%llX, DGID = %llX:%llX", prim_mtu,
28960Sstevel@tonic-gate qp_attr.qp_info.qp_transport.rc.rc_path.cep_pkey_ix, mpr_req->P_Key,
28970Sstevel@tonic-gate cur_sgid.gid_prefix, cur_sgid.gid_guid, cur_dgid.gid_prefix,
28980Sstevel@tonic-gate cur_dgid.gid_guid);
28990Sstevel@tonic-gate
29000Sstevel@tonic-gate /* Get SA Access Handle. */
29010Sstevel@tonic-gate if (new_sgid.gid_guid != 0)
29020Sstevel@tonic-gate saa_handle = ibcm_get_saa_handle(hcap, n_hp.hp_port);
29030Sstevel@tonic-gate else
29040Sstevel@tonic-gate saa_handle = ibcm_get_saa_handle(hcap, c_hp.hp_port);
29050Sstevel@tonic-gate if (saa_handle == NULL) {
29060Sstevel@tonic-gate retval = IBT_HCA_PORT_NOT_ACTIVE;
29070Sstevel@tonic-gate goto get_alt_path_done;
29080Sstevel@tonic-gate }
29090Sstevel@tonic-gate
29100Sstevel@tonic-gate /* Contact SA Access to retrieve Path Records. */
29110Sstevel@tonic-gate access_args.sq_attr_id = SA_MULTIPATHRECORD_ATTRID;
29120Sstevel@tonic-gate access_args.sq_access_type = IBMF_SAA_RETRIEVE;
29130Sstevel@tonic-gate access_args.sq_component_mask = c_mask;
29140Sstevel@tonic-gate access_args.sq_template = mpr_req;
29150Sstevel@tonic-gate access_args.sq_template_length = sizeof (sa_multipath_record_t);
29160Sstevel@tonic-gate access_args.sq_callback = NULL;
29170Sstevel@tonic-gate access_args.sq_callback_arg = NULL;
29180Sstevel@tonic-gate
29190Sstevel@tonic-gate retval = ibcm_contact_sa_access(saa_handle, &access_args, &length,
29200Sstevel@tonic-gate &results_p);
29210Sstevel@tonic-gate if (retval != IBT_SUCCESS) {
29220Sstevel@tonic-gate goto get_alt_path_done;
29230Sstevel@tonic-gate }
29240Sstevel@tonic-gate
29250Sstevel@tonic-gate num_rec = length / sizeof (sa_path_record_t);
29260Sstevel@tonic-gate
29270Sstevel@tonic-gate kmem_free(mpr_req, template_len);
29280Sstevel@tonic-gate
29290Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path: Found %d Paths", num_rec);
29300Sstevel@tonic-gate
29310Sstevel@tonic-gate rec_found = 0;
29320Sstevel@tonic-gate if ((results_p != NULL) && (num_rec > 0)) {
29330Sstevel@tonic-gate /* Update the PathInfo with the response Path Records */
29340Sstevel@tonic-gate pr_resp = (sa_path_record_t *)results_p;
29350Sstevel@tonic-gate for (i = 0; i < num_rec; i++, pr_resp++) {
29360Sstevel@tonic-gate if (prim_mtu > pr_resp->Mtu) {
29370Sstevel@tonic-gate IBTF_DPRINTF_L2(cmlog, "ibt_get_alt_path: "
29380Sstevel@tonic-gate "Alt PathMTU(%d) must be GT or EQU to Pri "
29390Sstevel@tonic-gate "PathMTU(%d). Ignore this rec",
29400Sstevel@tonic-gate pr_resp->Mtu, prim_mtu);
29410Sstevel@tonic-gate continue;
29420Sstevel@tonic-gate }
29430Sstevel@tonic-gate
29440Sstevel@tonic-gate if ((new_sgid.gid_guid == 0) &&
29450Sstevel@tonic-gate (new_dgid.gid_guid == 0)) {
29460Sstevel@tonic-gate /* Reject PathRec if it same as Primary Path. */
29470Sstevel@tonic-gate if (ibcm_compare_paths(pr_resp,
29480Sstevel@tonic-gate &qp_attr.qp_info.qp_transport.rc.rc_path,
29499349SShantkumar.Hiremath@Sun.COM &c_hp)) {
29500Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog,
29510Sstevel@tonic-gate "ibt_get_alt_path: PathRec obtained"
29520Sstevel@tonic-gate " is similar to Prim Path, ignore "
29530Sstevel@tonic-gate "this record");
29540Sstevel@tonic-gate continue;
29550Sstevel@tonic-gate }
29560Sstevel@tonic-gate }
29570Sstevel@tonic-gate
29580Sstevel@tonic-gate if (new_sgid.gid_guid == 0) {
29590Sstevel@tonic-gate retval = ibcm_update_cep_info(pr_resp, NULL,
29600Sstevel@tonic-gate &c_hp, &api_p->ap_alt_cep_path);
29610Sstevel@tonic-gate } else {
29620Sstevel@tonic-gate retval = ibcm_update_cep_info(pr_resp, NULL,
29630Sstevel@tonic-gate &n_hp, &api_p->ap_alt_cep_path);
29640Sstevel@tonic-gate }
29650Sstevel@tonic-gate if (retval != IBT_SUCCESS)
29660Sstevel@tonic-gate continue;
29670Sstevel@tonic-gate
29680Sstevel@tonic-gate /* Update some leftovers */
29690Sstevel@tonic-gate _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*api_p))
29700Sstevel@tonic-gate
29710Sstevel@tonic-gate api_p->ap_alt_pkt_lt = pr_resp->PacketLifeTime;
29720Sstevel@tonic-gate
29730Sstevel@tonic-gate _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*api_p))
29740Sstevel@tonic-gate
29750Sstevel@tonic-gate rec_found = 1;
29760Sstevel@tonic-gate break;
29770Sstevel@tonic-gate }
29780Sstevel@tonic-gate kmem_free(results_p, length);
29790Sstevel@tonic-gate }
29800Sstevel@tonic-gate
29810Sstevel@tonic-gate if (rec_found == 0) {
29820Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path: Alternate Path cannot"
29830Sstevel@tonic-gate " be established");
29840Sstevel@tonic-gate retval = IBT_PATH_RECORDS_NOT_FOUND;
29850Sstevel@tonic-gate } else
29860Sstevel@tonic-gate retval = IBT_SUCCESS;
29870Sstevel@tonic-gate
29880Sstevel@tonic-gate get_alt_path_done:
29890Sstevel@tonic-gate if ((snum) && (sgids_p))
29900Sstevel@tonic-gate kmem_free(sgids_p, snum * sizeof (ib_gid_t));
29910Sstevel@tonic-gate
29920Sstevel@tonic-gate if ((dnum) && (dgids_p))
29930Sstevel@tonic-gate kmem_free(dgids_p, dnum * sizeof (ib_gid_t));
29940Sstevel@tonic-gate
29950Sstevel@tonic-gate ibcm_dec_hca_acc_cnt(hcap);
29960Sstevel@tonic-gate
29970Sstevel@tonic-gate IBTF_DPRINTF_L3(cmlog, "ibt_get_alt_path: Done (status %d).", retval);
29980Sstevel@tonic-gate
29990Sstevel@tonic-gate return (retval);
30000Sstevel@tonic-gate }
30010Sstevel@tonic-gate
30020Sstevel@tonic-gate
30034703Shiremath
30044703Shiremath /*
30054703Shiremath * IP Path API
30064703Shiremath */
30074703Shiremath
30084703Shiremath typedef struct ibcm_ip_path_tqargs_s {
30094703Shiremath ibt_ip_path_attr_t attr;
30104703Shiremath ibt_path_info_t *paths;
30114703Shiremath ibt_path_ip_src_t *src_ip_p;
30124703Shiremath uint8_t *num_paths_p;
30134703Shiremath ibt_ip_path_handler_t func;
30144703Shiremath void *arg;
30154703Shiremath ibt_path_flags_t flags;
30164703Shiremath ibt_clnt_hdl_t ibt_hdl;
30174703Shiremath kmutex_t ip_lock;
30184703Shiremath kcondvar_t ip_cv;
301912336SShantkumar.Hiremath@Sun.COM boolean_t ip_done;
30204703Shiremath ibt_status_t retval;
30214703Shiremath uint_t len;
30224703Shiremath } ibcm_ip_path_tqargs_t;
30234703Shiremath
30244703Shiremath /* Holds destination information needed to fill in ibt_path_info_t. */
30254703Shiremath typedef struct ibcm_ip_dinfo_s {
30264703Shiremath uint8_t num_dest;
302711951SShantkumar.Hiremath@Sun.COM ib_gid_t d_gid[1];
30284703Shiremath } ibcm_ip_dinfo_t;
30294703Shiremath
30304703Shiremath _NOTE(SCHEME_PROTECTS_DATA("Temporary path storage", ibcm_ip_dinfo_s))
30314703Shiremath
30324703Shiremath /* Prototype Declarations. */
30334703Shiremath static void ibcm_process_get_ip_paths(void *tq_arg);
30344703Shiremath static ibt_status_t ibcm_get_ip_spr(ibcm_ip_path_tqargs_t *,
30354703Shiremath ibtl_cm_port_list_t *, ibcm_ip_dinfo_t *, uint8_t *, ibt_path_info_t *);
30364703Shiremath static ibt_status_t ibcm_get_ip_mpr(ibcm_ip_path_tqargs_t *,
30374703Shiremath ibtl_cm_port_list_t *, ibcm_ip_dinfo_t *dinfo,
30384703Shiremath uint8_t *, ibt_path_info_t *);
30394703Shiremath
30404703Shiremath /*
30414703Shiremath * Perform SA Access to retrieve Path Records.
30424703Shiremath */
30434703Shiremath static ibt_status_t
ibcm_saa_ip_pr(ibcm_ip_path_tqargs_t * p_arg,ibtl_cm_port_list_t * sl,ibcm_ip_dinfo_t * dinfo,uint8_t * max_count)30444703Shiremath ibcm_saa_ip_pr(ibcm_ip_path_tqargs_t *p_arg, ibtl_cm_port_list_t *sl,
30454703Shiremath ibcm_ip_dinfo_t *dinfo, uint8_t *max_count)
30464703Shiremath {
30474703Shiremath uint8_t num_path = *max_count;
304811951SShantkumar.Hiremath@Sun.COM uint8_t rec_found = 0;
30494703Shiremath ibt_status_t retval = IBT_SUCCESS;
30504703Shiremath uint8_t i, j;
30514703Shiremath
30524703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_saa_ip_pr(%p, %p, %p, 0x%X, %d)",
30534703Shiremath p_arg, sl, dinfo, p_arg->flags, *max_count);
30544703Shiremath
30554703Shiremath if ((dinfo->num_dest == 0) || (num_path == 0) || (sl == NULL)) {
30564703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_saa_ip_pr: Invalid Counters");
30574703Shiremath return (IBT_INVALID_PARAM);
30584703Shiremath }
30594703Shiremath
30609645SShantkumar.Hiremath@Sun.COM IBTF_DPRINTF_L3(cmlog, "ibcm_saa_ip_pr: MultiSM=%X, #SRC=%d, "
30619645SShantkumar.Hiremath@Sun.COM "#Dest=%d, #Path %d", sl->p_multi, sl->p_count, dinfo->num_dest,
30629645SShantkumar.Hiremath@Sun.COM num_path);
30639645SShantkumar.Hiremath@Sun.COM
30649645SShantkumar.Hiremath@Sun.COM if ((sl->p_multi != IBTL_CM_SIMPLE_SETUP) ||
30659645SShantkumar.Hiremath@Sun.COM ((dinfo->num_dest == 1) && (sl->p_count == 1))) {
30664703Shiremath /*
30679645SShantkumar.Hiremath@Sun.COM * Use SinglePathRec if we are dealing w/ MultiSM or
30689645SShantkumar.Hiremath@Sun.COM * request is for one SGID to one DGID.
30694703Shiremath */
30709645SShantkumar.Hiremath@Sun.COM retval = ibcm_get_ip_spr(p_arg, sl, dinfo,
30719645SShantkumar.Hiremath@Sun.COM &num_path, &p_arg->paths[rec_found]);
30729645SShantkumar.Hiremath@Sun.COM } else {
30739645SShantkumar.Hiremath@Sun.COM /* MultiPathRec will be used for other queries. */
30749645SShantkumar.Hiremath@Sun.COM retval = ibcm_get_ip_mpr(p_arg, sl, dinfo,
30759645SShantkumar.Hiremath@Sun.COM &num_path, &p_arg->paths[rec_found]);
30764703Shiremath }
30779645SShantkumar.Hiremath@Sun.COM if ((retval != IBT_SUCCESS) && (retval != IBT_INSUFF_DATA))
30789645SShantkumar.Hiremath@Sun.COM IBTF_DPRINTF_L2(cmlog, "ibcm_saa_ip_pr: "
30799645SShantkumar.Hiremath@Sun.COM "Failed to get PathRec: Status %d", retval);
30809645SShantkumar.Hiremath@Sun.COM else
30819645SShantkumar.Hiremath@Sun.COM rec_found += num_path;
30824703Shiremath
30834703Shiremath if (rec_found == 0) {
30844703Shiremath if (retval == IBT_SUCCESS)
30854703Shiremath retval = IBT_PATH_RECORDS_NOT_FOUND;
30864703Shiremath } else if (rec_found != *max_count)
30874703Shiremath retval = IBT_INSUFF_DATA;
30884703Shiremath else if (rec_found != 0)
30894703Shiremath retval = IBT_SUCCESS;
30904703Shiremath
30914703Shiremath if ((p_arg->src_ip_p != NULL) && (rec_found != 0)) {
30924703Shiremath for (i = 0; i < rec_found; i++) {
30934703Shiremath for (j = 0; j < sl->p_count; j++) {
30944703Shiremath if (sl[j].p_sgid.gid_guid == p_arg->paths[i].
30954703Shiremath pi_prim_cep_path.cep_adds_vect.
30964703Shiremath av_sgid.gid_guid) {
30974703Shiremath bcopy(&sl[j].p_src_ip,
30984703Shiremath &p_arg->src_ip_p[i].ip_primary,
30994703Shiremath sizeof (ibt_ip_addr_t));
31004703Shiremath }
31014703Shiremath /* Is Alt Path present */
31024703Shiremath if (p_arg->paths[i].pi_alt_cep_path.
31034703Shiremath cep_hca_port_num) {
31044703Shiremath if (sl[j].p_sgid.gid_guid ==
31054703Shiremath p_arg->paths[i].pi_alt_cep_path.
31064703Shiremath cep_adds_vect.av_sgid.gid_guid) {
31074703Shiremath bcopy(&sl[j].p_src_ip,
31084703Shiremath &p_arg->src_ip_p[i].
31094703Shiremath ip_alternate,
31104703Shiremath sizeof (ibt_ip_addr_t));
31114703Shiremath }
31124703Shiremath }
31134703Shiremath }
31144703Shiremath }
31154703Shiremath }
31164703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_saa_ip_pr: done. Status = %d, "
31174703Shiremath "Found %d/%d Paths", retval, rec_found, *max_count);
31184703Shiremath
31194703Shiremath *max_count = rec_found; /* Update the return count. */
31204703Shiremath
31214703Shiremath return (retval);
31224703Shiremath }
31234703Shiremath
31244703Shiremath static ibt_status_t
ibcm_ip_update_pri(sa_path_record_t * pr_resp,ibtl_cm_port_list_t * sl,ibt_path_info_t * paths)31254703Shiremath ibcm_ip_update_pri(sa_path_record_t *pr_resp, ibtl_cm_port_list_t *sl,
31264703Shiremath ibt_path_info_t *paths)
31274703Shiremath {
31284703Shiremath ibt_status_t retval = IBT_SUCCESS;
31294703Shiremath int s;
31304703Shiremath
31314703Shiremath retval = ibcm_update_cep_info(pr_resp, sl, NULL,
31324703Shiremath &paths->pi_prim_cep_path);
31334703Shiremath if (retval != IBT_SUCCESS)
31344703Shiremath return (retval);
31354703Shiremath
31364703Shiremath /* Update some leftovers */
31374703Shiremath paths->pi_prim_pkt_lt = pr_resp->PacketLifeTime;
31384703Shiremath paths->pi_path_mtu = pr_resp->Mtu;
31394703Shiremath
31404703Shiremath for (s = 0; s < sl->p_count; s++) {
31414703Shiremath if (pr_resp->SGID.gid_guid == sl[s].p_sgid.gid_guid)
31424703Shiremath paths->pi_hca_guid = sl[s].p_hca_guid;
31434703Shiremath }
31444703Shiremath
31454703Shiremath /* Set Alternate Path to invalid state. */
31464703Shiremath paths->pi_alt_cep_path.cep_hca_port_num = 0;
31474703Shiremath paths->pi_alt_cep_path.cep_adds_vect.av_dlid = 0;
31484703Shiremath
31494703Shiremath IBTF_DPRINTF_L5(cmlog, "ibcm_ip_update_pri: Path HCA GUID 0x%llX",
31504703Shiremath paths->pi_hca_guid);
31514703Shiremath
31524703Shiremath return (retval);
31534703Shiremath }
31544703Shiremath
31554703Shiremath
31564703Shiremath static ibt_status_t
ibcm_get_ip_spr(ibcm_ip_path_tqargs_t * p_arg,ibtl_cm_port_list_t * sl,ibcm_ip_dinfo_t * dinfo,uint8_t * num_path,ibt_path_info_t * paths)31574703Shiremath ibcm_get_ip_spr(ibcm_ip_path_tqargs_t *p_arg, ibtl_cm_port_list_t *sl,
31584703Shiremath ibcm_ip_dinfo_t *dinfo, uint8_t *num_path, ibt_path_info_t *paths)
31594703Shiremath {
31604703Shiremath sa_path_record_t pathrec_req;
31614703Shiremath sa_path_record_t *pr_resp;
31624703Shiremath ibmf_saa_access_args_t access_args;
31634703Shiremath uint64_t c_mask = 0;
31644703Shiremath void *results_p;
31654703Shiremath uint8_t num_rec;
31664703Shiremath size_t length;
31674703Shiremath ibt_status_t retval;
31684703Shiremath int i, j, k;
316911951SShantkumar.Hiremath@Sun.COM uint8_t found, p_fnd;
31704703Shiremath ibt_ip_path_attr_t *attrp = &p_arg->attr;
31714703Shiremath ibmf_saa_handle_t saa_handle;
31724703Shiremath
31734703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_spr(%p, %p, %p, %d)",
31744703Shiremath p_arg, sl, dinfo, *num_path);
31754703Shiremath
31764703Shiremath bzero(&pathrec_req, sizeof (sa_path_record_t));
31774703Shiremath
31784703Shiremath /* Is Flow Label Specified. */
31794703Shiremath if (attrp->ipa_flow) {
31804703Shiremath pathrec_req.FlowLabel = attrp->ipa_flow;
31814703Shiremath c_mask |= SA_PR_COMPMASK_FLOWLABEL;
31824703Shiremath }
31834703Shiremath
31844703Shiremath /* Is HopLimit Specified. */
31854703Shiremath if (p_arg->flags & IBT_PATH_HOP) {
31864703Shiremath pathrec_req.HopLimit = attrp->ipa_hop;
31874703Shiremath c_mask |= SA_PR_COMPMASK_HOPLIMIT;
31884703Shiremath }
31894703Shiremath
31904703Shiremath /* Is TClass Specified. */
31914703Shiremath if (attrp->ipa_tclass) {
31924703Shiremath pathrec_req.TClass = attrp->ipa_tclass;
31934703Shiremath c_mask |= SA_PR_COMPMASK_TCLASS;
31944703Shiremath }
31954703Shiremath
31964703Shiremath /* Is SL specified. */
31974703Shiremath if (attrp->ipa_sl) {
31984703Shiremath pathrec_req.SL = attrp->ipa_sl;
31994703Shiremath c_mask |= SA_PR_COMPMASK_SL;
32004703Shiremath }
32014703Shiremath
32024703Shiremath /* If IBT_PATH_PERF is set, then mark all selectors to BEST. */
32034703Shiremath if (p_arg->flags & IBT_PATH_PERF) {
32044703Shiremath pathrec_req.PacketLifeTimeSelector = IBT_BEST;
32054703Shiremath pathrec_req.MtuSelector = IBT_BEST;
32064703Shiremath pathrec_req.RateSelector = IBT_BEST;
32074703Shiremath
32084703Shiremath c_mask |= SA_PR_COMPMASK_PKTLTSELECTOR |
32094703Shiremath SA_PR_COMPMASK_RATESELECTOR | SA_PR_COMPMASK_MTUSELECTOR;
32104703Shiremath } else {
32114703Shiremath if (attrp->ipa_pkt_lt.p_selector == IBT_BEST) {
32124703Shiremath pathrec_req.PacketLifeTimeSelector = IBT_BEST;
32134703Shiremath c_mask |= SA_PR_COMPMASK_PKTLTSELECTOR;
32144703Shiremath }
32154703Shiremath
32164703Shiremath if (attrp->ipa_srate.r_selector == IBT_BEST) {
32174703Shiremath pathrec_req.RateSelector = IBT_BEST;
32184703Shiremath c_mask |= SA_PR_COMPMASK_RATESELECTOR;
32194703Shiremath }
32204703Shiremath
32214703Shiremath if (attrp->ipa_mtu.r_selector == IBT_BEST) {
32224703Shiremath pathrec_req.MtuSelector = IBT_BEST;
32234703Shiremath c_mask |= SA_PR_COMPMASK_MTUSELECTOR;
32244703Shiremath }
32254703Shiremath }
32264703Shiremath
32274703Shiremath /*
32284703Shiremath * Honor individual selection of these attributes,
32294703Shiremath * even if IBT_PATH_PERF is set.
32304703Shiremath */
32314703Shiremath /* Check out whether Packet Life Time is specified. */
32324703Shiremath if (attrp->ipa_pkt_lt.p_pkt_lt) {
32334703Shiremath pathrec_req.PacketLifeTime =
32344703Shiremath ibt_usec2ib(attrp->ipa_pkt_lt.p_pkt_lt);
32354703Shiremath pathrec_req.PacketLifeTimeSelector =
32364703Shiremath attrp->ipa_pkt_lt.p_selector;
32374703Shiremath
32384703Shiremath c_mask |= SA_PR_COMPMASK_PKTLT | SA_PR_COMPMASK_PKTLTSELECTOR;
32394703Shiremath }
32404703Shiremath
32414703Shiremath /* Is SRATE specified. */
32424703Shiremath if (attrp->ipa_srate.r_srate) {
32434703Shiremath pathrec_req.Rate = attrp->ipa_srate.r_srate;
32444703Shiremath pathrec_req.RateSelector = attrp->ipa_srate.r_selector;
32454703Shiremath
32464703Shiremath c_mask |= SA_PR_COMPMASK_RATE | SA_PR_COMPMASK_RATESELECTOR;
32474703Shiremath }
32484703Shiremath
32494703Shiremath /* Is MTU specified. */
32504703Shiremath if (attrp->ipa_mtu.r_mtu) {
32514703Shiremath pathrec_req.Mtu = attrp->ipa_mtu.r_mtu;
32524703Shiremath pathrec_req.MtuSelector = attrp->ipa_mtu.r_selector;
32534703Shiremath
32544703Shiremath c_mask |= SA_PR_COMPMASK_MTU | SA_PR_COMPMASK_MTUSELECTOR;
32554703Shiremath }
32564703Shiremath
32574703Shiremath /* We always get REVERSIBLE paths. */
32584703Shiremath pathrec_req.Reversible = 1;
32594703Shiremath c_mask |= SA_PR_COMPMASK_REVERSIBLE;
32604703Shiremath
32614703Shiremath pathrec_req.NumbPath = *num_path;
32624703Shiremath c_mask |= SA_PR_COMPMASK_NUMBPATH;
32634703Shiremath
32644703Shiremath p_fnd = found = 0;
32654703Shiremath
32664703Shiremath for (i = 0; i < sl->p_count; i++) {
32674703Shiremath /* SGID */
32684703Shiremath pathrec_req.SGID = sl[i].p_sgid;
32694703Shiremath c_mask |= SA_PR_COMPMASK_SGID;
32704703Shiremath saa_handle = sl[i].p_saa_hdl;
32714703Shiremath
32724703Shiremath for (k = 0; k < dinfo->num_dest; k++) {
32734703Shiremath if (pathrec_req.SGID.gid_prefix !=
327411951SShantkumar.Hiremath@Sun.COM dinfo->d_gid[k].gid_prefix) {
32754703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_spr: "
32764703Shiremath "SGID_pfx=%llX DGID_pfx=%llX doesn't match",
32774703Shiremath pathrec_req.SGID.gid_prefix,
327811951SShantkumar.Hiremath@Sun.COM dinfo->d_gid[k].gid_prefix);
32794703Shiremath continue;
32804703Shiremath }
32814703Shiremath
328211951SShantkumar.Hiremath@Sun.COM pathrec_req.DGID = dinfo->d_gid[k];
32834703Shiremath c_mask |= SA_PR_COMPMASK_DGID;
32844703Shiremath
32854703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_spr: "
32864703Shiremath "Get %d Path(s) between\n SGID %llX:%llX "
32874703Shiremath "DGID %llX:%llX", pathrec_req.NumbPath,
32884703Shiremath pathrec_req.SGID.gid_prefix,
32894703Shiremath pathrec_req.SGID.gid_guid,
32904703Shiremath pathrec_req.DGID.gid_prefix,
32914703Shiremath pathrec_req.DGID.gid_guid);
32924703Shiremath
32934703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_spr: CMask=0x%llX, "
32944703Shiremath "PKey=0x%X", c_mask, pathrec_req.P_Key);
32954703Shiremath
32964703Shiremath /* Contact SA Access to retrieve Path Records. */
32974703Shiremath access_args.sq_attr_id = SA_PATHRECORD_ATTRID;
32984703Shiremath access_args.sq_template = &pathrec_req;
32994703Shiremath access_args.sq_access_type = IBMF_SAA_RETRIEVE;
33004703Shiremath access_args.sq_template_length =
33014703Shiremath sizeof (sa_path_record_t);
33024703Shiremath access_args.sq_component_mask = c_mask;
33034703Shiremath access_args.sq_callback = NULL;
33044703Shiremath access_args.sq_callback_arg = NULL;
33054703Shiremath
33064703Shiremath retval = ibcm_contact_sa_access(saa_handle,
33074703Shiremath &access_args, &length, &results_p);
33084703Shiremath if (retval != IBT_SUCCESS) {
33094703Shiremath *num_path = 0;
33104703Shiremath return (retval);
33114703Shiremath }
33124703Shiremath
33134703Shiremath num_rec = length / sizeof (sa_path_record_t);
33144703Shiremath
33154703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_spr: "
33164703Shiremath "FOUND %d/%d path requested", num_rec, *num_path);
33174703Shiremath
33184703Shiremath if ((results_p == NULL) || (num_rec == 0))
33194703Shiremath continue;
33204703Shiremath
33214703Shiremath /* Update the PathInfo from the response. */
33224703Shiremath pr_resp = (sa_path_record_t *)results_p;
33234703Shiremath for (j = 0; j < num_rec; j++, pr_resp++) {
33244703Shiremath if ((p_fnd != 0) &&
33254703Shiremath (p_arg->flags & IBT_PATH_APM)) {
33264703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_spr"
33274703Shiremath ": Fill Alternate Path");
33284703Shiremath retval = ibcm_update_cep_info(pr_resp,
33294703Shiremath sl, NULL,
33304703Shiremath &paths[found - 1].pi_alt_cep_path);
33314703Shiremath if (retval != IBT_SUCCESS)
33324703Shiremath continue;
33334703Shiremath
33344703Shiremath /* Update some leftovers */
33354703Shiremath paths[found - 1].pi_alt_pkt_lt =
33364703Shiremath pr_resp->PacketLifeTime;
33374703Shiremath p_fnd = 0;
33384703Shiremath } else {
33394703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_spr"
33404703Shiremath ": Fill Primary Path");
33414703Shiremath
33424703Shiremath if (found == *num_path)
33434703Shiremath break;
33444703Shiremath
33454703Shiremath retval = ibcm_ip_update_pri(pr_resp, sl,
33464703Shiremath &paths[found]);
33474703Shiremath if (retval != IBT_SUCCESS)
33484703Shiremath continue;
33494703Shiremath p_fnd = 1;
33504703Shiremath found++;
33514703Shiremath }
33524703Shiremath
33534703Shiremath }
33544703Shiremath /* Deallocate the memory for results_p. */
33554703Shiremath kmem_free(results_p, length);
33564703Shiremath }
33574703Shiremath }
33584703Shiremath
33594703Shiremath if (found == 0)
33604703Shiremath retval = IBT_PATH_RECORDS_NOT_FOUND;
33614703Shiremath else if (found != *num_path)
33624703Shiremath retval = IBT_INSUFF_DATA;
33634703Shiremath else
33644703Shiremath retval = IBT_SUCCESS;
33654703Shiremath
33664703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_spr: done. Status %d, "
33674703Shiremath "Found %d/%d Paths", retval, found, *num_path);
33684703Shiremath
33694703Shiremath *num_path = found;
33704703Shiremath
33714703Shiremath return (retval);
33724703Shiremath }
33734703Shiremath
33744703Shiremath
33754703Shiremath static ibt_status_t
ibcm_get_ip_mpr(ibcm_ip_path_tqargs_t * p_arg,ibtl_cm_port_list_t * sl,ibcm_ip_dinfo_t * dinfo,uint8_t * num_path,ibt_path_info_t * paths)33764703Shiremath ibcm_get_ip_mpr(ibcm_ip_path_tqargs_t *p_arg, ibtl_cm_port_list_t *sl,
33774703Shiremath ibcm_ip_dinfo_t *dinfo, uint8_t *num_path, ibt_path_info_t *paths)
33784703Shiremath {
33794703Shiremath sa_multipath_record_t *mpr_req;
33804703Shiremath sa_path_record_t *pr_resp;
33814703Shiremath ibmf_saa_access_args_t access_args;
33824703Shiremath void *results_p;
33834703Shiremath uint64_t c_mask = 0;
33844703Shiremath ib_gid_t *gid_ptr, *gid_s_ptr;
33854703Shiremath size_t length;
338611951SShantkumar.Hiremath@Sun.COM int template_len;
338711951SShantkumar.Hiremath@Sun.COM uint8_t found, num_rec;
33884703Shiremath int i;
33894703Shiremath ibt_status_t retval;
33904703Shiremath uint8_t sgid_cnt, dgid_cnt;
33914703Shiremath ibt_ip_path_attr_t *attrp = &p_arg->attr;
33924703Shiremath
33934703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr(%p, %p, %p, %d)",
33944703Shiremath attrp, sl, dinfo, *num_path);
33954703Shiremath
33969645SShantkumar.Hiremath@Sun.COM dgid_cnt = dinfo->num_dest;
33974703Shiremath sgid_cnt = sl->p_count;
33984703Shiremath
33994703Shiremath if ((sgid_cnt == 0) || (dgid_cnt == 0)) {
34004703Shiremath IBTF_DPRINTF_L2(cmlog, "ibcm_get_ip_mpr: sgid_cnt(%d) or"
34014703Shiremath " dgid_cnt(%d) is zero", sgid_cnt, dgid_cnt);
34024703Shiremath return (IBT_INVALID_PARAM);
34034703Shiremath }
34044703Shiremath
34054703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr: Get %d records between "
34064703Shiremath "%d Src(s) <=> %d Dest(s)", *num_path, sgid_cnt, dgid_cnt);
34074703Shiremath
34084703Shiremath /*
34094703Shiremath * Calculate the size for multi-path records template, which includes
34104703Shiremath * constant portion of the multipath record, plus variable size for
34114703Shiremath * SGID (sgid_cnt) and DGID (dgid_cnt).
34124703Shiremath */
34134703Shiremath template_len = ((dgid_cnt + sgid_cnt) * sizeof (ib_gid_t)) +
34144703Shiremath sizeof (sa_multipath_record_t);
34154703Shiremath
34164703Shiremath mpr_req = kmem_zalloc(template_len, KM_SLEEP);
34174703Shiremath
34184703Shiremath ASSERT(mpr_req != NULL);
34194703Shiremath
34204703Shiremath gid_ptr = (ib_gid_t *)(((uchar_t *)mpr_req) +
34214703Shiremath sizeof (sa_multipath_record_t));
34224703Shiremath
34234703Shiremath /* Get the starting pointer where GIDs are stored. */
34244703Shiremath gid_s_ptr = gid_ptr;
34254703Shiremath
34264703Shiremath /* SGID */
34279645SShantkumar.Hiremath@Sun.COM for (i = 0; i < sgid_cnt; i++) {
34284703Shiremath *gid_ptr = sl[i].p_sgid;
34294703Shiremath
34304703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr: SGID[%d] = %llX:%llX",
34314703Shiremath i, gid_ptr->gid_prefix, gid_ptr->gid_guid);
34324703Shiremath
34334703Shiremath gid_ptr++;
34344703Shiremath }
34354703Shiremath
34364703Shiremath _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mpr_req))
34374703Shiremath
34384703Shiremath mpr_req->SGIDCount = sgid_cnt;
34394703Shiremath c_mask = SA_MPR_COMPMASK_SGIDCOUNT;
34404703Shiremath
34414703Shiremath /* DGIDs */
34429645SShantkumar.Hiremath@Sun.COM for (i = 0; i < dgid_cnt; i++) {
344311951SShantkumar.Hiremath@Sun.COM *gid_ptr = dinfo->d_gid[i];
34449645SShantkumar.Hiremath@Sun.COM
34459645SShantkumar.Hiremath@Sun.COM IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr: DGID[%d] = "
34469645SShantkumar.Hiremath@Sun.COM "%llX:%llX", i, gid_ptr->gid_prefix, gid_ptr->gid_guid);
34479645SShantkumar.Hiremath@Sun.COM gid_ptr++;
34484703Shiremath }
34494703Shiremath
34504703Shiremath mpr_req->DGIDCount = dgid_cnt;
34514703Shiremath c_mask |= SA_MPR_COMPMASK_DGIDCOUNT;
34524703Shiremath
34534703Shiremath /* Is Flow Label Specified. */
34544703Shiremath if (attrp->ipa_flow) {
34554703Shiremath mpr_req->FlowLabel = attrp->ipa_flow;
34564703Shiremath c_mask |= SA_MPR_COMPMASK_FLOWLABEL;
34574703Shiremath }
34584703Shiremath
34594703Shiremath /* Is HopLimit Specified. */
34604703Shiremath if (p_arg->flags & IBT_PATH_HOP) {
34614703Shiremath mpr_req->HopLimit = attrp->ipa_hop;
34624703Shiremath c_mask |= SA_MPR_COMPMASK_HOPLIMIT;
34634703Shiremath }
34644703Shiremath
34654703Shiremath /* Is TClass Specified. */
34664703Shiremath if (attrp->ipa_tclass) {
34674703Shiremath mpr_req->TClass = attrp->ipa_tclass;
34684703Shiremath c_mask |= SA_MPR_COMPMASK_TCLASS;
34694703Shiremath }
34704703Shiremath
34714703Shiremath /* Is SL specified. */
34724703Shiremath if (attrp->ipa_sl) {
34734703Shiremath mpr_req->SL = attrp->ipa_sl;
34744703Shiremath c_mask |= SA_MPR_COMPMASK_SL;
34754703Shiremath }
34764703Shiremath
34774703Shiremath if (p_arg->flags & IBT_PATH_PERF) {
34784703Shiremath mpr_req->PacketLifeTimeSelector = IBT_BEST;
34794703Shiremath mpr_req->RateSelector = IBT_BEST;
34804703Shiremath mpr_req->MtuSelector = IBT_BEST;
34814703Shiremath
34824703Shiremath c_mask |= SA_MPR_COMPMASK_PKTLTSELECTOR |
34834703Shiremath SA_MPR_COMPMASK_RATESELECTOR | SA_MPR_COMPMASK_MTUSELECTOR;
34844703Shiremath } else {
34854703Shiremath if (attrp->ipa_pkt_lt.p_selector == IBT_BEST) {
34864703Shiremath mpr_req->PacketLifeTimeSelector = IBT_BEST;
34874703Shiremath c_mask |= SA_MPR_COMPMASK_PKTLTSELECTOR;
34884703Shiremath }
34894703Shiremath
34904703Shiremath if (attrp->ipa_srate.r_selector == IBT_BEST) {
34914703Shiremath mpr_req->RateSelector = IBT_BEST;
34924703Shiremath c_mask |= SA_MPR_COMPMASK_RATESELECTOR;
34934703Shiremath }
34944703Shiremath
34954703Shiremath if (attrp->ipa_mtu.r_selector == IBT_BEST) {
34964703Shiremath mpr_req->MtuSelector = IBT_BEST;
34974703Shiremath c_mask |= SA_MPR_COMPMASK_MTUSELECTOR;
34984703Shiremath }
34994703Shiremath }
35004703Shiremath
35014703Shiremath /*
35024703Shiremath * Honor individual selection of these attributes,
35034703Shiremath * even if IBT_PATH_PERF is set.
35044703Shiremath */
35054703Shiremath /* Check out whether Packet Life Time is specified. */
35064703Shiremath if (attrp->ipa_pkt_lt.p_pkt_lt) {
35074703Shiremath mpr_req->PacketLifeTime =
35084703Shiremath ibt_usec2ib(attrp->ipa_pkt_lt.p_pkt_lt);
35094703Shiremath mpr_req->PacketLifeTimeSelector =
35104703Shiremath attrp->ipa_pkt_lt.p_selector;
35114703Shiremath
35124703Shiremath c_mask |= SA_MPR_COMPMASK_PKTLT |
35134703Shiremath SA_MPR_COMPMASK_PKTLTSELECTOR;
35144703Shiremath }
35154703Shiremath
35164703Shiremath /* Is SRATE specified. */
35174703Shiremath if (attrp->ipa_srate.r_srate) {
35184703Shiremath mpr_req->Rate = attrp->ipa_srate.r_srate;
35194703Shiremath mpr_req->RateSelector = attrp->ipa_srate.r_selector;
35204703Shiremath
35214703Shiremath c_mask |= SA_MPR_COMPMASK_RATE |
35224703Shiremath SA_MPR_COMPMASK_RATESELECTOR;
35234703Shiremath }
35244703Shiremath
35254703Shiremath /* Is MTU specified. */
35264703Shiremath if (attrp->ipa_mtu.r_mtu) {
35274703Shiremath mpr_req->Mtu = attrp->ipa_mtu.r_mtu;
35284703Shiremath mpr_req->MtuSelector = attrp->ipa_mtu.r_selector;
35294703Shiremath
35304703Shiremath c_mask |= SA_MPR_COMPMASK_MTU |
35314703Shiremath SA_MPR_COMPMASK_MTUSELECTOR;
35324703Shiremath }
35334703Shiremath
35344703Shiremath /* We always get REVERSIBLE paths. */
35354703Shiremath mpr_req->Reversible = 1;
35364703Shiremath c_mask |= SA_MPR_COMPMASK_REVERSIBLE;
35374703Shiremath
35384703Shiremath if (p_arg->flags & IBT_PATH_AVAIL) {
35394703Shiremath mpr_req->IndependenceSelector = 1;
35404703Shiremath c_mask |= SA_MPR_COMPMASK_INDEPSEL;
35414703Shiremath }
35424703Shiremath
35434703Shiremath /* we will not specify how many records we want. */
35444703Shiremath
35454703Shiremath _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*mpr_req))
35464703Shiremath
35474703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr: CMask: %llX Pkey: %X",
35484703Shiremath c_mask, mpr_req->P_Key);
35494703Shiremath
35504703Shiremath /* Contact SA Access to retrieve Path Records. */
35514703Shiremath access_args.sq_attr_id = SA_MULTIPATHRECORD_ATTRID;
35524703Shiremath access_args.sq_access_type = IBMF_SAA_RETRIEVE;
35534703Shiremath access_args.sq_component_mask = c_mask;
35544703Shiremath access_args.sq_template = mpr_req;
35554703Shiremath access_args.sq_template_length = sizeof (sa_multipath_record_t);
35564703Shiremath access_args.sq_callback = NULL;
35574703Shiremath access_args.sq_callback_arg = NULL;
35584703Shiremath
35594703Shiremath retval = ibcm_contact_sa_access(sl->p_saa_hdl, &access_args, &length,
35604703Shiremath &results_p);
35614703Shiremath if (retval != IBT_SUCCESS) {
35624703Shiremath *num_path = 0; /* Update the return count. */
35634703Shiremath kmem_free(mpr_req, template_len);
35644703Shiremath return (retval);
35654703Shiremath }
35664703Shiremath
35674703Shiremath num_rec = length / sizeof (sa_path_record_t);
35684703Shiremath
35694703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr: Found %d Paths", num_rec);
35704703Shiremath
35714703Shiremath found = 0;
35724703Shiremath if ((results_p != NULL) && (num_rec > 0)) {
35734703Shiremath /* Update the PathInfo with the response Path Records */
35744703Shiremath pr_resp = (sa_path_record_t *)results_p;
35754703Shiremath
35764703Shiremath for (i = 0; i < num_rec; i++) {
35774703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr: "
35784703Shiremath "P[%d]: SG %llX, DG %llX", i,
35794703Shiremath pr_resp[i].SGID.gid_guid, pr_resp[i].DGID.gid_guid);
35804703Shiremath }
35814703Shiremath
35824703Shiremath if (p_arg->flags & IBT_PATH_APM) {
35834703Shiremath sa_path_record_t *p_resp = NULL, *a_resp = NULL;
35844703Shiremath int p_found = 0, a_found = 0;
35854703Shiremath ib_gid_t p_sg, a_sg, p_dg, a_dg;
35864703Shiremath int s_spec;
35874703Shiremath
35884703Shiremath s_spec =
35894703Shiremath p_arg->attr.ipa_src_ip.family != AF_UNSPEC ? 1 : 0;
35904703Shiremath
35914703Shiremath p_sg = gid_s_ptr[0];
35924703Shiremath if (sgid_cnt > 1)
35934703Shiremath a_sg = gid_s_ptr[1];
35944703Shiremath else
35954703Shiremath a_sg = p_sg;
35964703Shiremath
35974703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr: P_SG: %llX, "
35984703Shiremath "A_SG: %llX", p_sg.gid_guid, a_sg.gid_guid);
35994703Shiremath
36004703Shiremath p_dg = gid_s_ptr[sgid_cnt];
36014703Shiremath if (dgid_cnt > 1)
36024703Shiremath a_dg = gid_s_ptr[sgid_cnt + 1];
36034703Shiremath else
36044703Shiremath a_dg = p_dg;
36054703Shiremath
36064703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr: P_DG: %llX, "
36074703Shiremath "A_DG: %llX", p_dg.gid_guid, a_dg.gid_guid);
36084703Shiremath
36094703Shiremath /*
36104703Shiremath * If SGID and/or DGID is specified by user, make sure
36114703Shiremath * he gets his primary-path on those node points.
36124703Shiremath */
36134703Shiremath for (i = 0; i < num_rec; i++, pr_resp++) {
36144703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr: "
36154703Shiremath "PF %d, AF %d,\n\t\t P[%d] = SG: %llX, "
36164703Shiremath "DG: %llX", p_found, a_found, i,
36174703Shiremath pr_resp->SGID.gid_guid,
36184703Shiremath pr_resp->DGID.gid_guid);
36194703Shiremath
36204703Shiremath if ((!p_found) &&
36214703Shiremath (p_dg.gid_guid == pr_resp->DGID.gid_guid)) {
36224703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr"
36234703Shiremath ": Pri DGID Match.. ");
36244703Shiremath if ((s_spec == 0) || (p_sg.gid_guid ==
36254703Shiremath pr_resp->SGID.gid_guid)) {
36264703Shiremath p_found = 1;
36274703Shiremath p_resp = pr_resp;
36284703Shiremath IBTF_DPRINTF_L3(cmlog,
36294703Shiremath "ibcm_get_ip_mpr: "
36304703Shiremath "Primary Path Found");
36314703Shiremath
36324703Shiremath if (a_found)
36334703Shiremath break;
36344703Shiremath else
36354703Shiremath continue;
36364703Shiremath }
36374703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr"
36384703Shiremath ": Pri SGID Don't Match.. ");
36394703Shiremath }
36404703Shiremath
36414703Shiremath if ((!a_found) &&
36424703Shiremath (a_dg.gid_guid == pr_resp->DGID.gid_guid)) {
36434703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr"
36444703Shiremath ": Alt DGID Match.. ");
36454703Shiremath if ((s_spec == 0) || (a_sg.gid_guid ==
36464703Shiremath pr_resp->SGID.gid_guid)) {
36474703Shiremath a_found = 1;
36484703Shiremath a_resp = pr_resp;
36494703Shiremath
36504703Shiremath IBTF_DPRINTF_L3(cmlog,
36514703Shiremath "ibcm_get_ip_mpr:"
36524703Shiremath "Alternate Path Found ");
36534703Shiremath
36544703Shiremath if (p_found)
36554703Shiremath break;
36564703Shiremath else
36574703Shiremath continue;
36584703Shiremath }
36594703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr"
36604703Shiremath ": Alt SGID Don't Match.. ");
36614703Shiremath }
36624703Shiremath }
36634703Shiremath
36644703Shiremath if ((p_found == 0) && (a_found == 0)) {
36654703Shiremath IBTF_DPRINTF_L2(cmlog, "ibcm_get_ip_mpr: Path "
36664703Shiremath "to desired node points NOT Available.");
36674703Shiremath retval = IBT_PATH_RECORDS_NOT_FOUND;
36684703Shiremath goto get_ip_mpr_end;
36694703Shiremath }
36704703Shiremath
36714703Shiremath if ((p_resp == NULL) && (a_resp != NULL)) {
36724703Shiremath p_resp = a_resp;
36734703Shiremath a_resp = NULL;
36744703Shiremath }
36754703Shiremath
36764703Shiremath /* Fill in Primary Path */
36774703Shiremath retval = ibcm_ip_update_pri(p_resp, sl, &paths[found]);
36784703Shiremath if (retval != IBT_SUCCESS)
36794703Shiremath goto get_ip_mpr_end;
36804703Shiremath
36814703Shiremath /* Fill in Alternate Path */
36824703Shiremath if (a_resp != NULL) {
36834703Shiremath /* a_resp will point to AltPathInfo buffer. */
36844703Shiremath retval = ibcm_update_cep_info(a_resp, sl,
36854703Shiremath NULL, &paths[found].pi_alt_cep_path);
36864703Shiremath if (retval != IBT_SUCCESS)
36874703Shiremath goto get_ip_mpr_end;
36884703Shiremath
36894703Shiremath /* Update some leftovers */
36904703Shiremath paths[found].pi_alt_pkt_lt =
36914703Shiremath a_resp->PacketLifeTime;
36924703Shiremath } else {
36934703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr: "
36944703Shiremath "Alternate Path NOT Available.");
36954703Shiremath retval = IBT_INSUFF_DATA;
36964703Shiremath }
36974703Shiremath found++;
36984703Shiremath } else { /* If NOT APM */
36994703Shiremath for (i = 0; i < num_rec; i++, pr_resp++) {
37004703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr: "
37014703Shiremath "DGID(%llX)", pr_resp->DGID.gid_guid);
37024703Shiremath
37034703Shiremath /* Fill in Primary Path */
37044703Shiremath retval = ibcm_ip_update_pri(pr_resp, sl,
37054703Shiremath &paths[found]);
37064703Shiremath if (retval != IBT_SUCCESS)
37074703Shiremath continue;
37084703Shiremath
37094703Shiremath if (++found == *num_path)
37104703Shiremath break;
37114703Shiremath }
37124703Shiremath }
37134703Shiremath get_ip_mpr_end:
37144703Shiremath kmem_free(results_p, length);
37154703Shiremath }
37164703Shiremath kmem_free(mpr_req, template_len);
37174703Shiremath
37184703Shiremath if (found == 0)
37194703Shiremath retval = IBT_PATH_RECORDS_NOT_FOUND;
37204703Shiremath else if (found != *num_path)
37214703Shiremath retval = IBT_INSUFF_DATA;
37224703Shiremath else
37234703Shiremath retval = IBT_SUCCESS;
37244703Shiremath
37254703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_mpr: Done (status %d). "
37264703Shiremath "Found %d/%d Paths", retval, found, *num_path);
37274703Shiremath
37284703Shiremath *num_path = found; /* Update the return count. */
37294703Shiremath
37304703Shiremath return (retval);
37314703Shiremath }
37324703Shiremath
37334703Shiremath
37344703Shiremath static void
ibcm_process_get_ip_paths(void * tq_arg)37354703Shiremath ibcm_process_get_ip_paths(void *tq_arg)
37364703Shiremath {
37374703Shiremath ibcm_ip_path_tqargs_t *p_arg = (ibcm_ip_path_tqargs_t *)tq_arg;
37384703Shiremath ibcm_ip_dinfo_t *dinfo = NULL;
37394703Shiremath int len = 0;
37404703Shiremath uint8_t max_paths, num_path;
37414703Shiremath ib_gid_t *d_gids_p = NULL;
37424703Shiremath ib_gid_t sgid, dgid1, dgid2;
37434703Shiremath ibt_status_t retval = IBT_SUCCESS;
37444703Shiremath ibtl_cm_port_list_t *sl = NULL;
37454703Shiremath uint_t dnum = 0;
374611951SShantkumar.Hiremath@Sun.COM uint8_t i;
37474703Shiremath ibcm_hca_info_t *hcap;
37484703Shiremath ibmf_saa_handle_t saa_handle;
374911951SShantkumar.Hiremath@Sun.COM ibt_path_attr_t attr;
375011951SShantkumar.Hiremath@Sun.COM ibt_ip_addr_t src_ip_p;
37514703Shiremath
37524703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_ip_paths(%p, 0x%X) ",
37534703Shiremath p_arg, p_arg->flags);
37544703Shiremath
37554703Shiremath max_paths = num_path = p_arg->attr.ipa_max_paths;
37564703Shiremath
37574703Shiremath /*
37584703Shiremath * Prepare the Source and Destination GID list based on the input
37594703Shiremath * attributes. We contact ARP module to perform IP to MAC
37604703Shiremath * i.e. GID conversion. We use this GID for path look-up.
37614703Shiremath *
37624703Shiremath * If APM is requested and if multiple Dest IPs are specified, check
37634703Shiremath * out whether they are companion to each other. But, if only one
37644703Shiremath * Dest IP is specified, then it is beyond our scope to verify that
37654703Shiremath * the companion port GID obtained has IP-Service enabled.
37664703Shiremath */
37674703Shiremath dgid1.gid_prefix = dgid1.gid_guid = 0;
37684703Shiremath sgid.gid_prefix = sgid.gid_guid = 0;
376911951SShantkumar.Hiremath@Sun.COM
3770*12965SWilliam.Taylor@Oracle.COM retval = ibcm_arp_get_ibaddr(p_arg->attr.ipa_zoneid,
3771*12965SWilliam.Taylor@Oracle.COM p_arg->attr.ipa_src_ip, p_arg->attr.ipa_dst_ip[0], &sgid,
3772*12965SWilliam.Taylor@Oracle.COM &dgid1, &src_ip_p);
377311951SShantkumar.Hiremath@Sun.COM if (retval) {
377411951SShantkumar.Hiremath@Sun.COM IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_ip_paths: "
377511951SShantkumar.Hiremath@Sun.COM "ibcm_arp_get_ibaddr() failed: %d", retval);
377611951SShantkumar.Hiremath@Sun.COM goto ippath_error;
377711951SShantkumar.Hiremath@Sun.COM }
377811951SShantkumar.Hiremath@Sun.COM
377911951SShantkumar.Hiremath@Sun.COM bzero(&attr, sizeof (ibt_path_attr_t));
378011951SShantkumar.Hiremath@Sun.COM attr.pa_hca_guid = p_arg->attr.ipa_hca_guid;
378111951SShantkumar.Hiremath@Sun.COM attr.pa_hca_port_num = p_arg->attr.ipa_hca_port_num;
378211951SShantkumar.Hiremath@Sun.COM attr.pa_sgid = sgid;
378311951SShantkumar.Hiremath@Sun.COM bcopy(&p_arg->attr.ipa_mtu, &attr.pa_mtu, sizeof (ibt_mtu_req_t));
378411951SShantkumar.Hiremath@Sun.COM bcopy(&p_arg->attr.ipa_srate, &attr.pa_srate, sizeof (ibt_srate_req_t));
378511951SShantkumar.Hiremath@Sun.COM bcopy(&p_arg->attr.ipa_pkt_lt, &attr.pa_pkt_lt,
378611951SShantkumar.Hiremath@Sun.COM sizeof (ibt_pkt_lt_req_t));
378711951SShantkumar.Hiremath@Sun.COM retval = ibtl_cm_get_active_plist(&attr, p_arg->flags, &sl);
378811951SShantkumar.Hiremath@Sun.COM if (retval == IBT_SUCCESS) {
378911951SShantkumar.Hiremath@Sun.COM bcopy(&src_ip_p, &sl->p_src_ip, sizeof (ibt_ip_addr_t));
37904703Shiremath } else {
379111951SShantkumar.Hiremath@Sun.COM IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_ip_paths: "
379211951SShantkumar.Hiremath@Sun.COM "ibtl_cm_get_active_plist: Failed %d", retval);
379311951SShantkumar.Hiremath@Sun.COM goto ippath_error;
37944703Shiremath }
37954703Shiremath
37964703Shiremath IBTF_DPRINTF_L4(cmlog, "ibcm_process_get_ip_paths: SGID %llX:%llX, "
37974703Shiremath "DGID0: %llX:%llX", sl->p_sgid.gid_prefix, sl->p_sgid.gid_guid,
37984703Shiremath dgid1.gid_prefix, dgid1.gid_guid);
37994703Shiremath
380011951SShantkumar.Hiremath@Sun.COM len = p_arg->attr.ipa_ndst - 1;
380111951SShantkumar.Hiremath@Sun.COM len = (len * sizeof (ib_gid_t)) + sizeof (ibcm_ip_dinfo_t);
38024703Shiremath dinfo = kmem_zalloc(len, KM_SLEEP);
38034703Shiremath
380411951SShantkumar.Hiremath@Sun.COM dinfo->d_gid[0] = dgid1;
38054703Shiremath
38064703Shiremath i = 1;
38074703Shiremath if (p_arg->attr.ipa_ndst > 1) {
38084703Shiremath /* Get DGID for all specified Dest IP Addr */
38094703Shiremath for (; i < p_arg->attr.ipa_ndst; i++) {
3810*12965SWilliam.Taylor@Oracle.COM retval = ibcm_arp_get_ibaddr(p_arg->attr.ipa_zoneid,
381111951SShantkumar.Hiremath@Sun.COM p_arg->attr.ipa_src_ip, p_arg->attr.ipa_dst_ip[i],
381211951SShantkumar.Hiremath@Sun.COM NULL, &dgid2, NULL);
38134703Shiremath if (retval) {
38144703Shiremath IBTF_DPRINTF_L2(cmlog,
38154703Shiremath "ibcm_process_get_ip_paths: "
38164703Shiremath "ibcm_arp_get_ibaddr failed: %d", retval);
38174703Shiremath goto ippath_error2;
38184703Shiremath }
381911951SShantkumar.Hiremath@Sun.COM dinfo->d_gid[i] = dgid2;
38204703Shiremath
38214703Shiremath IBTF_DPRINTF_L4(cmlog, "ibcm_process_get_ip_paths: "
38224703Shiremath "DGID%d: %llX:%llX", i, dgid2.gid_prefix,
38234703Shiremath dgid2.gid_guid);
38244703Shiremath }
38254703Shiremath
38264703Shiremath if (p_arg->flags & IBT_PATH_APM) {
382711951SShantkumar.Hiremath@Sun.COM dgid2 = dinfo->d_gid[1];
38284703Shiremath
38294703Shiremath retval = ibcm_get_comp_pgids(dgid1, dgid2, 0,
38304703Shiremath &d_gids_p, &dnum);
38314703Shiremath if ((retval != IBT_SUCCESS) &&
38324703Shiremath (retval != IBT_GIDS_NOT_FOUND)) {
38334703Shiremath IBTF_DPRINTF_L2(cmlog,
38344703Shiremath "ibcm_process_get_ip_paths: "
38354703Shiremath "Invalid DGIDs specified w/ APM Flag");
38364703Shiremath goto ippath_error2;
38374703Shiremath }
38384703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_ip_paths: "
38394703Shiremath "Found %d Comp DGID", dnum);
38404703Shiremath
38414703Shiremath if (dnum) {
384211951SShantkumar.Hiremath@Sun.COM dinfo->d_gid[i] = d_gids_p[0];
38434703Shiremath i++;
38444703Shiremath }
38454703Shiremath }
38464703Shiremath }
38474703Shiremath
38484703Shiremath /* "i" will get us num_dest count. */
38494703Shiremath dinfo->num_dest = i;
38504703Shiremath
38514703Shiremath _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*p_arg))
38524703Shiremath
38534703Shiremath /*
38544703Shiremath * IBTF allocates memory for path_info & src_ip in case of
38554703Shiremath * Async Get IP Paths
38564703Shiremath */
38574703Shiremath if (p_arg->func) { /* Do these only for Async Get Paths */
38584703Shiremath p_arg->paths = kmem_zalloc(sizeof (ibt_path_info_t) * max_paths,
38594703Shiremath KM_SLEEP);
38604703Shiremath if (p_arg->src_ip_p == NULL)
38614703Shiremath p_arg->src_ip_p = kmem_zalloc(
38624703Shiremath sizeof (ibt_path_ip_src_t) * max_paths, KM_SLEEP);
38634703Shiremath }
38644703Shiremath
38654703Shiremath _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*p_arg))
38664703Shiremath
38674703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_process_get_ip_paths: HCA (%llX, %d)",
38684703Shiremath sl->p_hca_guid, sl->p_port_num);
38694703Shiremath
38704703Shiremath hcap = ibcm_find_hca_entry(sl->p_hca_guid);
38714703Shiremath if (hcap == NULL) {
38724703Shiremath IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_ip_paths: "
38734703Shiremath "NO HCA found");
38744703Shiremath retval = IBT_HCA_BUSY_DETACHING;
38754703Shiremath goto ippath_error2;
38764703Shiremath }
38774703Shiremath
38784703Shiremath /* Get SA Access Handle. */
38794703Shiremath for (i = 0; i < sl->p_count; i++) {
38804703Shiremath if (i == 0) {
38814703Shiremath /* Validate whether this HCA supports APM */
38824703Shiremath if ((p_arg->flags & IBT_PATH_APM) &&
38834703Shiremath (!(hcap->hca_caps & IBT_HCA_AUTO_PATH_MIG))) {
38844703Shiremath IBTF_DPRINTF_L2(cmlog,
38854703Shiremath "ibcm_process_get_ip_paths: HCA (%llX): "
38864703Shiremath "APM NOT SUPPORTED", sl[i].p_hca_guid);
38874703Shiremath retval = IBT_APM_NOT_SUPPORTED;
38884703Shiremath goto ippath_error3;
38894703Shiremath }
38904703Shiremath }
38914703Shiremath
38924703Shiremath saa_handle = ibcm_get_saa_handle(hcap, sl[i].p_port_num);
38934703Shiremath if (saa_handle == NULL) {
38944703Shiremath IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_ip_paths: "
38954703Shiremath "SAA HDL NULL, HCA (%llX:%d) NOT ACTIVE",
38964703Shiremath sl[i].p_hca_guid, sl[i].p_port_num);
38974703Shiremath retval = IBT_HCA_PORT_NOT_ACTIVE;
38984703Shiremath goto ippath_error3;
38994703Shiremath }
39004703Shiremath _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*sl))
39014703Shiremath sl[i].p_saa_hdl = saa_handle;
39024703Shiremath _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*sl))
39034703Shiremath }
39044703Shiremath
39054703Shiremath /* Get Path Records. */
39064703Shiremath retval = ibcm_saa_ip_pr(p_arg, sl, dinfo, &num_path);
39074703Shiremath
39084703Shiremath ippath_error3:
39094703Shiremath ibcm_dec_hca_acc_cnt(hcap);
39104703Shiremath
39114703Shiremath ippath_error2:
39124703Shiremath if (dinfo && len)
39134703Shiremath kmem_free(dinfo, len);
39144703Shiremath
39154703Shiremath ippath_error1:
39164703Shiremath if (sl)
39174703Shiremath ibtl_cm_free_active_plist(sl);
39184703Shiremath
39194703Shiremath ippath_error:
39204703Shiremath if ((retval != IBT_SUCCESS) && (retval != IBT_INSUFF_DATA))
39214703Shiremath num_path = 0;
39224703Shiremath
39234703Shiremath if (p_arg->num_paths_p != NULL)
39244703Shiremath *p_arg->num_paths_p = num_path;
39254703Shiremath
39264703Shiremath if (p_arg->func) { /* Do these only for Async Get Paths */
39274703Shiremath ibt_path_info_t *tmp_path_p;
392812251SJohnny.Cheung@Sun.COM ibt_path_ip_src_t *tmp_src_ip_p;
39294703Shiremath
39304703Shiremath _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*p_arg))
39314703Shiremath p_arg->retval = retval;
39324703Shiremath _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*p_arg))
39334703Shiremath
39344703Shiremath if (retval == IBT_INSUFF_DATA) {
39354703Shiremath /*
39364703Shiremath * We allocated earlier memory based on "max_paths",
39374703Shiremath * but we got lesser path-records, so re-adjust that
39384703Shiremath * buffer so that caller can free the correct memory.
39394703Shiremath */
39404703Shiremath tmp_path_p = kmem_alloc(
39414703Shiremath sizeof (ibt_path_info_t) * num_path, KM_SLEEP);
39424703Shiremath
39434703Shiremath bcopy(p_arg->paths, tmp_path_p,
39444703Shiremath num_path * sizeof (ibt_path_info_t));
39454703Shiremath
39464703Shiremath kmem_free(p_arg->paths,
39474703Shiremath sizeof (ibt_path_info_t) * max_paths);
394812251SJohnny.Cheung@Sun.COM
394912251SJohnny.Cheung@Sun.COM tmp_src_ip_p = kmem_alloc(
395012251SJohnny.Cheung@Sun.COM sizeof (ibt_path_ip_src_t) * num_path, KM_SLEEP);
395112251SJohnny.Cheung@Sun.COM
395212251SJohnny.Cheung@Sun.COM bcopy(p_arg->src_ip_p, tmp_src_ip_p,
395312251SJohnny.Cheung@Sun.COM num_path * sizeof (ibt_path_ip_src_t));
395412251SJohnny.Cheung@Sun.COM
395512251SJohnny.Cheung@Sun.COM kmem_free(p_arg->src_ip_p,
395612251SJohnny.Cheung@Sun.COM sizeof (ibt_path_ip_src_t) * max_paths);
39574703Shiremath } else if (retval != IBT_SUCCESS) {
39584703Shiremath if (p_arg->paths)
39594703Shiremath kmem_free(p_arg->paths,
39604703Shiremath sizeof (ibt_path_info_t) * max_paths);
39614703Shiremath if (p_arg->src_ip_p)
39624703Shiremath kmem_free(p_arg->src_ip_p,
39634703Shiremath sizeof (ibt_path_ip_src_t) * max_paths);
39644703Shiremath tmp_path_p = NULL;
396512251SJohnny.Cheung@Sun.COM tmp_src_ip_p = NULL;
39664703Shiremath } else {
39674703Shiremath tmp_path_p = p_arg->paths;
396812251SJohnny.Cheung@Sun.COM tmp_src_ip_p = p_arg->src_ip_p;
39694703Shiremath }
39704703Shiremath (*(p_arg->func))(p_arg->arg, retval, tmp_path_p, num_path,
397112251SJohnny.Cheung@Sun.COM tmp_src_ip_p);
39724703Shiremath
39734703Shiremath len = p_arg->len;
39744703Shiremath if (p_arg && len)
39754703Shiremath kmem_free(p_arg, len);
39764703Shiremath } else {
39774703Shiremath mutex_enter(&p_arg->ip_lock);
397812336SShantkumar.Hiremath@Sun.COM p_arg->ip_done = B_TRUE;
39794703Shiremath p_arg->retval = retval;
39804703Shiremath cv_signal(&p_arg->ip_cv);
39814703Shiremath mutex_exit(&p_arg->ip_lock);
39824703Shiremath }
39834703Shiremath
39844703Shiremath IBTF_DPRINTF_L2(cmlog, "ibcm_process_get_ip_paths: done: status %d, "
39854703Shiremath "Found %d/%d Path Records", retval, num_path, max_paths);
39864703Shiremath }
39874703Shiremath
39884703Shiremath
39894703Shiremath static ibt_status_t
ibcm_val_ipattr(ibt_ip_path_attr_t * attrp,ibt_path_flags_t flags)39904703Shiremath ibcm_val_ipattr(ibt_ip_path_attr_t *attrp, ibt_path_flags_t flags)
39914703Shiremath {
39924703Shiremath uint_t i;
39934703Shiremath
39944703Shiremath if (attrp == NULL) {
39954703Shiremath IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: IP Path Attr is NULL");
39964703Shiremath return (IBT_INVALID_PARAM);
39974703Shiremath }
39984703Shiremath
39994703Shiremath IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: Inputs are: HCA %llX:%d, "
40009349SShantkumar.Hiremath@Sun.COM "Maxpath= %d, \n Flags= 0x%X, #Dest %d", attrp->ipa_hca_guid,
40014703Shiremath attrp->ipa_hca_port_num, attrp->ipa_max_paths, flags,
40024703Shiremath attrp->ipa_ndst);
40034703Shiremath
40044703Shiremath /*
40054703Shiremath * Validate Path Flags.
40064703Shiremath * IBT_PATH_AVAIL & IBT_PATH_PERF are mutually exclusive.
40074703Shiremath */
40084703Shiremath if ((flags & IBT_PATH_AVAIL) && (flags & IBT_PATH_PERF)) {
40094703Shiremath IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: Invalid Flags: 0x%X,"
40104703Shiremath "\n\t AVAIL and PERF flags specified together", flags);
40114703Shiremath return (IBT_INVALID_PARAM);
40124703Shiremath }
40134703Shiremath
40144703Shiremath /*
40154703Shiremath * Validate number of records requested.
40164703Shiremath *
40174703Shiremath * Max_paths of "0" is invalid.
40184703Shiremath * Max_paths <= IBT_MAX_SPECIAL_PATHS, if AVAIL or PERF is set.
40194703Shiremath */
40204703Shiremath if (attrp->ipa_max_paths == 0) {
40214703Shiremath IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: Invalid max_paths %d",
40224703Shiremath attrp->ipa_max_paths);
40234703Shiremath return (IBT_INVALID_PARAM);
40244703Shiremath }
40254703Shiremath
40264703Shiremath if ((flags & (IBT_PATH_AVAIL | IBT_PATH_PERF)) &&
40274703Shiremath (attrp->ipa_max_paths > IBT_MAX_SPECIAL_PATHS)) {
40284703Shiremath IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: MaxPaths that can be "
40294703Shiremath "requested is <%d> \n when IBT_PATH_AVAIL or IBT_PATH_PERF"
40304703Shiremath " flag is specified.", IBT_MAX_SPECIAL_PATHS);
40314703Shiremath return (IBT_INVALID_PARAM);
40324703Shiremath }
40334703Shiremath
40344703Shiremath /* Only 2 destinations can be specified w/ APM flag. */
40354703Shiremath if ((flags & IBT_PATH_APM) && (attrp->ipa_ndst > 2)) {
40364703Shiremath IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: Max #Dest is 2, with "
40374703Shiremath "APM flag");
40384703Shiremath return (IBT_INVALID_PARAM);
40394703Shiremath }
40404703Shiremath
40414703Shiremath /* Validate the destination info */
40424703Shiremath if ((attrp->ipa_ndst == 0) || (attrp->ipa_ndst == NULL)) {
40434703Shiremath IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: DstIP Not provided "
40444703Shiremath "dst_ip %p, ndst %d", attrp->ipa_dst_ip, attrp->ipa_ndst);
40454703Shiremath return (IBT_INVALID_PARAM);
40464703Shiremath }
40474703Shiremath
40489349SShantkumar.Hiremath@Sun.COM /* Basic validation of Source IPADDR (if provided). */
40499349SShantkumar.Hiremath@Sun.COM IBCM_PRINT_IP("ibcm_val_ipattr SrcIP", &attrp->ipa_src_ip);
40509349SShantkumar.Hiremath@Sun.COM if ((attrp->ipa_src_ip.family == AF_INET) &&
40519349SShantkumar.Hiremath@Sun.COM (attrp->ipa_src_ip.un.ip4addr == htonl(INADDR_LOOPBACK) ||
40529349SShantkumar.Hiremath@Sun.COM attrp->ipa_src_ip.un.ip4addr == INADDR_ANY)) {
40539349SShantkumar.Hiremath@Sun.COM IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: SrcIP specified is "
40549349SShantkumar.Hiremath@Sun.COM "LOOPBACK/ZEROs: NOT SUPPORTED");
40559349SShantkumar.Hiremath@Sun.COM return (IBT_NOT_SUPPORTED);
40569349SShantkumar.Hiremath@Sun.COM } else if ((attrp->ipa_src_ip.family == AF_INET6) &&
40579349SShantkumar.Hiremath@Sun.COM (IN6_IS_ADDR_UNSPECIFIED(&attrp->ipa_src_ip.un.ip6addr) ||
40589349SShantkumar.Hiremath@Sun.COM IN6_IS_ADDR_LOOPBACK(&attrp->ipa_src_ip.un.ip6addr))) {
40599349SShantkumar.Hiremath@Sun.COM IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: SrcIP specified is "
40609349SShantkumar.Hiremath@Sun.COM "LOOPBACK/ZEROs: NOT SUPPORTED");
40619349SShantkumar.Hiremath@Sun.COM return (IBT_NOT_SUPPORTED);
40629349SShantkumar.Hiremath@Sun.COM }
40639349SShantkumar.Hiremath@Sun.COM
40649349SShantkumar.Hiremath@Sun.COM if (ibcm_ip6_linklocal_addr_ok &&
40659349SShantkumar.Hiremath@Sun.COM (attrp->ipa_src_ip.family == AF_INET6) &&
40669349SShantkumar.Hiremath@Sun.COM (IN6_IS_ADDR_LINKLOCAL(&attrp->ipa_src_ip.un.ip6addr))) {
40679349SShantkumar.Hiremath@Sun.COM IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: SrcIP specified is "
40689349SShantkumar.Hiremath@Sun.COM "Link Local Address: NOT SUPPORTED");
40699349SShantkumar.Hiremath@Sun.COM return (IBT_NOT_SUPPORTED);
40709349SShantkumar.Hiremath@Sun.COM }
40719349SShantkumar.Hiremath@Sun.COM
40729349SShantkumar.Hiremath@Sun.COM /* Basic validation of Dest IPADDR. */
40734703Shiremath for (i = 0; i < attrp->ipa_ndst; i++) {
40744703Shiremath ibt_ip_addr_t dst_ip = attrp->ipa_dst_ip[i];
40754703Shiremath
40769349SShantkumar.Hiremath@Sun.COM IBCM_PRINT_IP("ibcm_val_ipattr DstIP", &dst_ip);
40774703Shiremath
40784703Shiremath if (dst_ip.family == AF_UNSPEC) {
40794703Shiremath IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: ERROR: "
40804703Shiremath "Invalid DstIP specified");
40814703Shiremath return (IBT_INVALID_PARAM);
40829349SShantkumar.Hiremath@Sun.COM } else if ((dst_ip.family == AF_INET) &&
40839349SShantkumar.Hiremath@Sun.COM (dst_ip.un.ip4addr == htonl(INADDR_LOOPBACK) ||
40849349SShantkumar.Hiremath@Sun.COM dst_ip.un.ip4addr == INADDR_ANY)) {
40859349SShantkumar.Hiremath@Sun.COM IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: DstIP "
40869349SShantkumar.Hiremath@Sun.COM "specified is LOOPBACK/ZEROs: NOT SUPPORTED");
40879349SShantkumar.Hiremath@Sun.COM return (IBT_NOT_SUPPORTED);
40889349SShantkumar.Hiremath@Sun.COM } else if ((dst_ip.family == AF_INET6) &&
40899349SShantkumar.Hiremath@Sun.COM (IN6_IS_ADDR_UNSPECIFIED(&dst_ip.un.ip6addr) ||
40909349SShantkumar.Hiremath@Sun.COM IN6_IS_ADDR_LOOPBACK(&dst_ip.un.ip6addr))) {
40919349SShantkumar.Hiremath@Sun.COM IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: DstIP "
40929349SShantkumar.Hiremath@Sun.COM "specified is LOOPBACK/ZEROs: NOT SUPPORTED");
40939349SShantkumar.Hiremath@Sun.COM return (IBT_NOT_SUPPORTED);
40949349SShantkumar.Hiremath@Sun.COM }
40959349SShantkumar.Hiremath@Sun.COM
40969349SShantkumar.Hiremath@Sun.COM /*
40979349SShantkumar.Hiremath@Sun.COM * If SrcIP is specified, make sure that SrcIP and DstIP
40989349SShantkumar.Hiremath@Sun.COM * belong to same family.
40999349SShantkumar.Hiremath@Sun.COM */
41009349SShantkumar.Hiremath@Sun.COM if ((attrp->ipa_src_ip.family != AF_UNSPEC) &&
41019349SShantkumar.Hiremath@Sun.COM (attrp->ipa_src_ip.family != dst_ip.family)) {
41029349SShantkumar.Hiremath@Sun.COM IBTF_DPRINTF_L2(cmlog, "ibcm_val_ipattr: ERROR: "
41039349SShantkumar.Hiremath@Sun.COM "Specified SrcIP (%d) and DstIP(%d) family diffs.",
41049349SShantkumar.Hiremath@Sun.COM attrp->ipa_src_ip.family, dst_ip.family);
41059349SShantkumar.Hiremath@Sun.COM return (IBT_INVALID_PARAM);
41064703Shiremath }
41074703Shiremath }
41084703Shiremath
41094703Shiremath return (IBT_SUCCESS);
41104703Shiremath }
41114703Shiremath
41124703Shiremath
41134703Shiremath static ibt_status_t
ibcm_get_ip_path(ibt_clnt_hdl_t ibt_hdl,ibt_path_flags_t flags,ibt_ip_path_attr_t * attrp,ibt_path_info_t * paths,uint8_t * num_path_p,ibt_path_ip_src_t * src_ip_p,ibt_ip_path_handler_t func,void * arg)41144703Shiremath ibcm_get_ip_path(ibt_clnt_hdl_t ibt_hdl, ibt_path_flags_t flags,
41154703Shiremath ibt_ip_path_attr_t *attrp, ibt_path_info_t *paths, uint8_t *num_path_p,
41164703Shiremath ibt_path_ip_src_t *src_ip_p, ibt_ip_path_handler_t func, void *arg)
41174703Shiremath {
41184703Shiremath ibcm_ip_path_tqargs_t *path_tq;
41194703Shiremath int sleep_flag = ((func == NULL) ? KM_SLEEP : KM_NOSLEEP);
41204703Shiremath uint_t len, ret;
41214703Shiremath ibt_status_t retval;
41224703Shiremath
41234703Shiremath retval = ibcm_val_ipattr(attrp, flags);
41244703Shiremath if (retval != IBT_SUCCESS)
41254703Shiremath return (retval);
41264703Shiremath
41274703Shiremath len = (attrp->ipa_ndst * sizeof (ibt_ip_addr_t)) +
41284703Shiremath sizeof (ibcm_ip_path_tqargs_t);
41294703Shiremath path_tq = kmem_zalloc(len, sleep_flag);
41304703Shiremath if (path_tq == NULL) {
41314703Shiremath IBTF_DPRINTF_L2(cmlog, "ibcm_get_ip_path: "
41324703Shiremath "Unable to allocate memory for local usage.");
41334703Shiremath return (IBT_INSUFF_KERNEL_RESOURCE);
41344703Shiremath }
41354703Shiremath
41364703Shiremath _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*path_tq))
41374703Shiremath bcopy(attrp, &path_tq->attr, sizeof (ibt_ip_path_attr_t));
41384703Shiremath
41394703Shiremath path_tq->attr.ipa_dst_ip = (ibt_ip_addr_t *)(((uchar_t *)path_tq) +
41404703Shiremath sizeof (ibcm_ip_path_tqargs_t));
41414703Shiremath bcopy(attrp->ipa_dst_ip, path_tq->attr.ipa_dst_ip,
41424703Shiremath sizeof (ibt_ip_addr_t) * attrp->ipa_ndst);
41434703Shiremath
41444703Shiremath /* Ignore IBT_PATH_AVAIL flag, if only one path is requested. */
41454703Shiremath if ((flags & IBT_PATH_AVAIL) && (attrp->ipa_max_paths == 1)) {
41464703Shiremath flags &= ~IBT_PATH_AVAIL;
41474703Shiremath
41484703Shiremath IBTF_DPRINTF_L4(cmlog, "ibcm_get_ip_path: Ignoring "
41494703Shiremath "IBT_PATH_AVAIL flag, as only ONE path info is requested.");
41504703Shiremath }
41514703Shiremath
41524703Shiremath path_tq->flags = flags;
41534703Shiremath path_tq->ibt_hdl = ibt_hdl;
41544703Shiremath path_tq->paths = paths;
41554703Shiremath path_tq->src_ip_p = src_ip_p;
41564703Shiremath path_tq->num_paths_p = num_path_p;
41574703Shiremath path_tq->func = func;
41584703Shiremath path_tq->arg = arg;
41594703Shiremath path_tq->len = len;
416012336SShantkumar.Hiremath@Sun.COM path_tq->ip_done = B_FALSE;
416112336SShantkumar.Hiremath@Sun.COM if (func == NULL) { /* Blocking */
416212336SShantkumar.Hiremath@Sun.COM mutex_init(&path_tq->ip_lock, NULL, MUTEX_DEFAULT, NULL);
416312336SShantkumar.Hiremath@Sun.COM cv_init(&path_tq->ip_cv, NULL, CV_DRIVER, NULL);
416412336SShantkumar.Hiremath@Sun.COM }
41654703Shiremath
41664703Shiremath _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*path_tq))
41674703Shiremath
41684703Shiremath sleep_flag = ((func == NULL) ? TQ_SLEEP : TQ_NOSLEEP);
41694703Shiremath ret = taskq_dispatch(ibcm_taskq, ibcm_process_get_ip_paths, path_tq,
41704703Shiremath sleep_flag);
41714703Shiremath if (ret == 0) {
41724703Shiremath IBTF_DPRINTF_L2(cmlog, "ibcm_get_ip_path: Failed to dispatch "
41734703Shiremath "the TaskQ");
417412336SShantkumar.Hiremath@Sun.COM if (func == NULL) { /* Blocking */
417512336SShantkumar.Hiremath@Sun.COM cv_destroy(&path_tq->ip_cv);
417612336SShantkumar.Hiremath@Sun.COM mutex_destroy(&path_tq->ip_lock);
417712336SShantkumar.Hiremath@Sun.COM }
41784703Shiremath kmem_free(path_tq, len);
41794703Shiremath retval = IBT_INSUFF_KERNEL_RESOURCE;
41804703Shiremath } else {
41814703Shiremath if (func != NULL) { /* Non-Blocking */
41824703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_path: NonBlocking");
41834703Shiremath retval = IBT_SUCCESS;
41844703Shiremath } else { /* Blocking */
41854703Shiremath IBTF_DPRINTF_L3(cmlog, "ibcm_get_ip_path: Blocking");
418612336SShantkumar.Hiremath@Sun.COM mutex_enter(&path_tq->ip_lock);
418712336SShantkumar.Hiremath@Sun.COM while (path_tq->ip_done != B_TRUE)
418812336SShantkumar.Hiremath@Sun.COM cv_wait(&path_tq->ip_cv, &path_tq->ip_lock);
41894703Shiremath retval = path_tq->retval;
41904703Shiremath mutex_exit(&path_tq->ip_lock);
41914703Shiremath cv_destroy(&path_tq->ip_cv);
41924703Shiremath mutex_destroy(&path_tq->ip_lock);
41934703Shiremath kmem_free(path_tq, len);
41944703Shiremath }
41954703Shiremath }
41964703Shiremath
41974703Shiremath return (retval);
41984703Shiremath }
41994703Shiremath
42004703Shiremath
42014703Shiremath ibt_status_t
ibt_aget_ip_paths(ibt_clnt_hdl_t ibt_hdl,ibt_path_flags_t flags,ibt_ip_path_attr_t * attrp,ibt_ip_path_handler_t func,void * arg)42024703Shiremath ibt_aget_ip_paths(ibt_clnt_hdl_t ibt_hdl, ibt_path_flags_t flags,
42034703Shiremath ibt_ip_path_attr_t *attrp, ibt_ip_path_handler_t func, void *arg)
42044703Shiremath {
42059349SShantkumar.Hiremath@Sun.COM IBTF_DPRINTF_L3(cmlog, "ibt_aget_ip_paths(%p (%s), 0x%X, %p, %p, %p)",
42069349SShantkumar.Hiremath@Sun.COM ibt_hdl, ibtl_cm_get_clnt_name(ibt_hdl), flags, attrp, func, arg);
42074703Shiremath
42084703Shiremath if (func == NULL) {
42094703Shiremath IBTF_DPRINTF_L2(cmlog, "ibt_aget_ip_paths: Function Pointer is "
42104703Shiremath "NULL - ERROR ");
42114703Shiremath return (IBT_INVALID_PARAM);
42124703Shiremath }
42134703Shiremath
42144703Shiremath /* path info will be allocated in ibcm_process_get_ip_paths() */
42154703Shiremath return (ibcm_get_ip_path(ibt_hdl, flags, attrp, NULL, NULL,
42164703Shiremath NULL, func, arg));
42174703Shiremath }
42184703Shiremath
42194703Shiremath
42204703Shiremath ibt_status_t
ibt_get_ip_paths(ibt_clnt_hdl_t ibt_hdl,ibt_path_flags_t flags,ibt_ip_path_attr_t * attrp,ibt_path_info_t * paths,uint8_t * num_paths_p,ibt_path_ip_src_t * src_ip_p)42214703Shiremath ibt_get_ip_paths(ibt_clnt_hdl_t ibt_hdl, ibt_path_flags_t flags,
42224703Shiremath ibt_ip_path_attr_t *attrp, ibt_path_info_t *paths, uint8_t *num_paths_p,
42234703Shiremath ibt_path_ip_src_t *src_ip_p)
42244703Shiremath {
42259349SShantkumar.Hiremath@Sun.COM IBTF_DPRINTF_L3(cmlog, "ibt_get_ip_paths(%p(%s), 0x%X, %p, %p, %p, %p)",
42269349SShantkumar.Hiremath@Sun.COM ibt_hdl, ibtl_cm_get_clnt_name(ibt_hdl), flags, attrp, paths,
42279349SShantkumar.Hiremath@Sun.COM num_paths_p, src_ip_p);
42284703Shiremath
42294703Shiremath if (paths == NULL) {
42304703Shiremath IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_paths: Path Info Pointer is "
42314703Shiremath "NULL - ERROR ");
42324703Shiremath return (IBT_INVALID_PARAM);
42334703Shiremath }
42344703Shiremath
42354703Shiremath if (num_paths_p != NULL)
42364703Shiremath *num_paths_p = 0;
42374703Shiremath
42384703Shiremath return (ibcm_get_ip_path(ibt_hdl, flags, attrp, paths, num_paths_p,
42394703Shiremath src_ip_p, NULL, NULL));
42404703Shiremath }
42414703Shiremath
42424703Shiremath
42434703Shiremath ibt_status_t
ibt_get_ip_alt_path(ibt_channel_hdl_t rc_chan,ibt_path_flags_t flags,ibt_alt_ip_path_attr_t * attrp,ibt_alt_path_info_t * api_p)42444703Shiremath ibt_get_ip_alt_path(ibt_channel_hdl_t rc_chan, ibt_path_flags_t flags,
42454703Shiremath ibt_alt_ip_path_attr_t *attrp, ibt_alt_path_info_t *api_p)
42464703Shiremath {
42474703Shiremath sa_multipath_record_t *mpr_req;
42484703Shiremath sa_path_record_t *pr_resp;
42494703Shiremath ibmf_saa_access_args_t access_args;
42504703Shiremath ibt_qp_query_attr_t qp_attr;
42514703Shiremath ibtl_cm_hca_port_t c_hp, n_hp;
42524703Shiremath ibcm_hca_info_t *hcap;
42534703Shiremath void *results_p;
42544703Shiremath uint64_t c_mask = 0;
42554703Shiremath ib_gid_t *gid_ptr = NULL;
42564703Shiremath ib_gid_t *sgids_p = NULL, *dgids_p = NULL;
42574703Shiremath ib_gid_t cur_dgid, cur_sgid;
42584703Shiremath ib_gid_t new_dgid, new_sgid;
42594703Shiremath ibmf_saa_handle_t saa_handle;
42604703Shiremath size_t length;
42614703Shiremath int i, j, template_len, rec_found;
42624703Shiremath uint_t snum = 0, dnum = 0, num_rec;
42634703Shiremath ibt_status_t retval;
42644703Shiremath ib_mtu_t prim_mtu;
42654703Shiremath
42664703Shiremath IBTF_DPRINTF_L3(cmlog, "ibt_get_ip_alt_path(%p, %x, %p, %p)",
42674703Shiremath rc_chan, flags, attrp, api_p);
42684703Shiremath
42694703Shiremath /* validate channel */
42704703Shiremath if (IBCM_INVALID_CHANNEL(rc_chan)) {
42714703Shiremath IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_alt_path: invalid channel");
42724703Shiremath return (IBT_CHAN_HDL_INVALID);
42734703Shiremath }
42744703Shiremath
42754703Shiremath if (api_p == NULL) {
42764703Shiremath IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_alt_path: invalid attribute:"
42774703Shiremath " AltPathInfo can't be NULL");
42784703Shiremath return (IBT_INVALID_PARAM);
42794703Shiremath }
42804703Shiremath
42814703Shiremath retval = ibt_query_qp(rc_chan, &qp_attr);
42824703Shiremath if (retval != IBT_SUCCESS) {
42834703Shiremath IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_alt_path: ibt_query_qp(%p) "
42844703Shiremath "failed %d", rc_chan, retval);
42854703Shiremath return (retval);
42864703Shiremath }
42874703Shiremath
42884703Shiremath if (qp_attr.qp_info.qp_trans != IBT_RC_SRV) {
42894703Shiremath IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_alt_path: "
42904703Shiremath "Invalid Channel type: Applicable only to RC Channel");
42914703Shiremath return (IBT_CHAN_SRV_TYPE_INVALID);
42924703Shiremath }
42934703Shiremath
42944703Shiremath cur_dgid =
42954703Shiremath qp_attr.qp_info.qp_transport.rc.rc_path.cep_adds_vect.av_dgid;
42964703Shiremath cur_sgid =
42974703Shiremath qp_attr.qp_info.qp_transport.rc.rc_path.cep_adds_vect.av_sgid;
42984703Shiremath prim_mtu = qp_attr.qp_info.qp_transport.rc.rc_path_mtu;
42994703Shiremath
43004703Shiremath /* If optional attributes are specified, validate them. */
43014703Shiremath if (attrp) {
43024703Shiremath /* Get SGID and DGID for the specified input ip-addr */
4303*12965SWilliam.Taylor@Oracle.COM retval = ibcm_arp_get_ibaddr(attrp->apa_zoneid,
4304*12965SWilliam.Taylor@Oracle.COM attrp->apa_src_ip, attrp->apa_dst_ip, &new_sgid,
4305*12965SWilliam.Taylor@Oracle.COM &new_dgid, NULL);
43064703Shiremath if (retval) {
43074703Shiremath IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_alt_path: "
43084703Shiremath "ibcm_arp_get_ibaddr() failed: %d", retval);
43094703Shiremath return (retval);
43104703Shiremath }
43114703Shiremath } else {
43124703Shiremath new_dgid.gid_prefix = 0;
43134703Shiremath new_dgid.gid_guid = 0;
43144703Shiremath new_sgid.gid_prefix = 0;
43154703Shiremath new_sgid.gid_guid = 0;
43164703Shiremath }
43174703Shiremath
43184703Shiremath if ((new_dgid.gid_prefix != 0) && (new_sgid.gid_prefix != 0) &&
43194703Shiremath (new_dgid.gid_prefix != new_sgid.gid_prefix)) {
43204703Shiremath IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_alt_path: Specified SGID's "
43214703Shiremath "SNprefix (%llX) doesn't match with \n specified DGID's "
43224703Shiremath "SNprefix: %llX", new_sgid.gid_prefix, new_dgid.gid_prefix);
43234703Shiremath return (IBT_INVALID_PARAM);
43244703Shiremath }
43254703Shiremath
43264703Shiremath /* For the specified SGID, get HCA information. */
43274703Shiremath retval = ibtl_cm_get_hca_port(cur_sgid, 0, &c_hp);
43284703Shiremath if (retval != IBT_SUCCESS) {
43294703Shiremath IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_alt_path: "
43304703Shiremath "Get HCA Port Failed: %d", retval);
43314703Shiremath return (retval);
43324703Shiremath }
43334703Shiremath
43344703Shiremath hcap = ibcm_find_hca_entry(c_hp.hp_hca_guid);
43354703Shiremath if (hcap == NULL) {
43364703Shiremath IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_alt_path: NO HCA found");
43374703Shiremath return (IBT_HCA_BUSY_DETACHING);
43384703Shiremath }
43394703Shiremath
43404703Shiremath /* Validate whether this HCA support APM */
43414703Shiremath if (!(hcap->hca_caps & IBT_HCA_AUTO_PATH_MIG)) {
43424703Shiremath IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_alt_path: "
43434703Shiremath "HCA (%llX) - APM NOT SUPPORTED ", c_hp.hp_hca_guid);
43444703Shiremath retval = IBT_APM_NOT_SUPPORTED;
43454703Shiremath goto get_ip_alt_path_done;
43464703Shiremath }
43474703Shiremath
43484703Shiremath /* Get Companion Port GID of the current Channel's SGID */
43494703Shiremath if ((new_sgid.gid_guid == 0) || ((new_sgid.gid_guid != 0) &&
43504703Shiremath (new_sgid.gid_guid != cur_sgid.gid_guid))) {
43514703Shiremath IBTF_DPRINTF_L3(cmlog, "ibt_get_ip_alt_path: SRC: "
43524703Shiremath "Get Companion PortGids for - %llX:%llX",
43534703Shiremath cur_sgid.gid_prefix, cur_sgid.gid_guid);
43544703Shiremath
43554703Shiremath retval = ibcm_get_comp_pgids(cur_sgid, new_sgid,
43564703Shiremath c_hp.hp_hca_guid, &sgids_p, &snum);
43574703Shiremath if (retval != IBT_SUCCESS)
43584703Shiremath goto get_ip_alt_path_done;
43594703Shiremath }
43604703Shiremath
43614703Shiremath /* Get Companion Port GID of the current Channel's DGID */
43624703Shiremath if ((new_dgid.gid_guid == 0) || ((new_dgid.gid_guid != 0) &&
43634703Shiremath (new_dgid.gid_guid != cur_dgid.gid_guid))) {
43644703Shiremath
43654703Shiremath IBTF_DPRINTF_L3(cmlog, "ibt_get_ip_alt_path: DEST: "
43664703Shiremath "Get Companion PortGids for - %llX:%llX",
43674703Shiremath cur_dgid.gid_prefix, cur_dgid.gid_guid);
43684703Shiremath
43694703Shiremath retval = ibcm_get_comp_pgids(cur_dgid, new_dgid, 0, &dgids_p,
43704703Shiremath &dnum);
43714703Shiremath if (retval != IBT_SUCCESS)
43724703Shiremath goto get_ip_alt_path_done;
43734703Shiremath }
43744703Shiremath
43754703Shiremath if ((new_dgid.gid_guid == 0) || (new_sgid.gid_guid == 0)) {
43764703Shiremath if (new_sgid.gid_guid == 0) {
43774703Shiremath for (i = 0; i < snum; i++) {
43784703Shiremath if (new_dgid.gid_guid == 0) {
43794703Shiremath for (j = 0; j < dnum; j++) {
43804703Shiremath if (sgids_p[i].gid_prefix ==
43814703Shiremath dgids_p[j].gid_prefix) {
43824703Shiremath new_dgid = dgids_p[j];
43834703Shiremath new_sgid = sgids_p[i];
43844703Shiremath
43854703Shiremath goto get_ip_alt_proceed;
43864703Shiremath }
43874703Shiremath }
43884703Shiremath /* Current DGID */
43894703Shiremath if (sgids_p[i].gid_prefix ==
43904703Shiremath cur_dgid.gid_prefix) {
43914703Shiremath new_sgid = sgids_p[i];
43924703Shiremath goto get_ip_alt_proceed;
43934703Shiremath }
43944703Shiremath } else {
43954703Shiremath if (sgids_p[i].gid_prefix ==
43964703Shiremath new_dgid.gid_prefix) {
43974703Shiremath new_sgid = sgids_p[i];
43984703Shiremath goto get_ip_alt_proceed;
43994703Shiremath }
44004703Shiremath }
44014703Shiremath }
44024703Shiremath /* Current SGID */
44034703Shiremath if (new_dgid.gid_guid == 0) {
44044703Shiremath for (j = 0; j < dnum; j++) {
44054703Shiremath if (cur_sgid.gid_prefix ==
44064703Shiremath dgids_p[j].gid_prefix) {
44074703Shiremath new_dgid = dgids_p[j];
44084703Shiremath
44094703Shiremath goto get_ip_alt_proceed;
44104703Shiremath }
44114703Shiremath }
44124703Shiremath }
44134703Shiremath } else if (new_dgid.gid_guid == 0) {
44144703Shiremath for (i = 0; i < dnum; i++) {
44154703Shiremath if (dgids_p[i].gid_prefix ==
44164703Shiremath new_sgid.gid_prefix) {
44174703Shiremath new_dgid = dgids_p[i];
44184703Shiremath goto get_ip_alt_proceed;
44194703Shiremath }
44204703Shiremath }
44214703Shiremath /* Current DGID */
44224703Shiremath if (cur_dgid.gid_prefix == new_sgid.gid_prefix) {
44234703Shiremath goto get_ip_alt_proceed;
44244703Shiremath }
44254703Shiremath }
44264703Shiremath /*
44274703Shiremath * hmm... No Companion Ports available.
44284703Shiremath * so we will be using current or specified attributes only.
44294703Shiremath */
44304703Shiremath }
44314703Shiremath
44324703Shiremath get_ip_alt_proceed:
44334703Shiremath if (new_sgid.gid_guid != 0) {
44344703Shiremath retval = ibtl_cm_get_hca_port(new_sgid, 0, &n_hp);
44354703Shiremath if (retval != IBT_SUCCESS) {
44364703Shiremath IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_alt_path: "
44374703Shiremath "Get HCA Port Failed: %d", retval);
44384703Shiremath goto get_ip_alt_path_done;
44394703Shiremath }
44404703Shiremath }
44414703Shiremath
44424703Shiremath /* Calculate the size for multi-path records template */
44434703Shiremath template_len = (2 * sizeof (ib_gid_t)) + sizeof (sa_multipath_record_t);
44444703Shiremath
44454703Shiremath mpr_req = kmem_zalloc(template_len, KM_SLEEP);
44464703Shiremath
44474703Shiremath ASSERT(mpr_req != NULL);
44484703Shiremath
44494703Shiremath _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mpr_req))
44504703Shiremath
44514703Shiremath gid_ptr = (ib_gid_t *)(((uchar_t *)mpr_req) +
44524703Shiremath sizeof (sa_multipath_record_t));
44534703Shiremath
44544703Shiremath /* SGID */
44554703Shiremath if (new_sgid.gid_guid == 0)
44564703Shiremath *gid_ptr = cur_sgid;
44574703Shiremath else
44584703Shiremath *gid_ptr = new_sgid;
44594703Shiremath
44604703Shiremath IBTF_DPRINTF_L3(cmlog, "ibt_get_ip_alt_path: Get Path Between "
44614703Shiremath " SGID : %llX:%llX", gid_ptr->gid_prefix, gid_ptr->gid_guid);
44624703Shiremath
44634703Shiremath gid_ptr++;
44644703Shiremath
44654703Shiremath /* DGID */
44664703Shiremath if (new_dgid.gid_guid == 0)
44674703Shiremath *gid_ptr = cur_dgid;
44684703Shiremath else
44694703Shiremath *gid_ptr = new_dgid;
44704703Shiremath
44714703Shiremath IBTF_DPRINTF_L3(cmlog, "ibt_get_ip_alt_path:\t\t DGID : %llX:%llX",
44724703Shiremath gid_ptr->gid_prefix, gid_ptr->gid_guid);
44734703Shiremath
44744703Shiremath mpr_req->SGIDCount = 1;
44754703Shiremath c_mask = SA_MPR_COMPMASK_SGIDCOUNT;
44764703Shiremath
44774703Shiremath mpr_req->DGIDCount = 1;
44784703Shiremath c_mask |= SA_MPR_COMPMASK_DGIDCOUNT;
44794703Shiremath
44804703Shiremath /* Is Flow Label Specified. */
44814703Shiremath if (attrp) {
44824703Shiremath if (attrp->apa_flow) {
44834703Shiremath mpr_req->FlowLabel = attrp->apa_flow;
44844703Shiremath c_mask |= SA_MPR_COMPMASK_FLOWLABEL;
44854703Shiremath }
44864703Shiremath
44874703Shiremath /* Is HopLimit Specified. */
44884703Shiremath if (flags & IBT_PATH_HOP) {
44894703Shiremath mpr_req->HopLimit = attrp->apa_hop;
44904703Shiremath c_mask |= SA_MPR_COMPMASK_HOPLIMIT;
44914703Shiremath }
44924703Shiremath
44934703Shiremath /* Is TClass Specified. */
44944703Shiremath if (attrp->apa_tclass) {
44954703Shiremath mpr_req->TClass = attrp->apa_tclass;
44964703Shiremath c_mask |= SA_MPR_COMPMASK_TCLASS;
44974703Shiremath }
44984703Shiremath
44994703Shiremath /* Is SL specified. */
45004703Shiremath if (attrp->apa_sl) {
45014703Shiremath mpr_req->SL = attrp->apa_sl;
45024703Shiremath c_mask |= SA_MPR_COMPMASK_SL;
45034703Shiremath }
45044703Shiremath
45054703Shiremath if (flags & IBT_PATH_PERF) {
45064703Shiremath mpr_req->PacketLifeTimeSelector = IBT_BEST;
45074703Shiremath mpr_req->RateSelector = IBT_BEST;
45084703Shiremath
45094703Shiremath c_mask |= SA_MPR_COMPMASK_PKTLTSELECTOR |
45104703Shiremath SA_MPR_COMPMASK_RATESELECTOR;
45114703Shiremath } else {
45124703Shiremath if (attrp->apa_pkt_lt.p_selector == IBT_BEST) {
45134703Shiremath mpr_req->PacketLifeTimeSelector = IBT_BEST;
45144703Shiremath c_mask |= SA_MPR_COMPMASK_PKTLTSELECTOR;
45154703Shiremath }
45164703Shiremath
45174703Shiremath if (attrp->apa_srate.r_selector == IBT_BEST) {
45184703Shiremath mpr_req->RateSelector = IBT_BEST;
45194703Shiremath c_mask |= SA_MPR_COMPMASK_RATESELECTOR;
45204703Shiremath }
45214703Shiremath }
45224703Shiremath
45234703Shiremath /*
45244703Shiremath * Honor individual selection of these attributes,
45254703Shiremath * even if IBT_PATH_PERF is set.
45264703Shiremath */
45274703Shiremath /* Check out whether Packet Life Time is specified. */
45284703Shiremath if (attrp->apa_pkt_lt.p_pkt_lt) {
45294703Shiremath mpr_req->PacketLifeTime =
45304703Shiremath ibt_usec2ib(attrp->apa_pkt_lt.p_pkt_lt);
45314703Shiremath mpr_req->PacketLifeTimeSelector =
45324703Shiremath attrp->apa_pkt_lt.p_selector;
45334703Shiremath
45344703Shiremath c_mask |= SA_MPR_COMPMASK_PKTLT |
45354703Shiremath SA_MPR_COMPMASK_PKTLTSELECTOR;
45364703Shiremath }
45374703Shiremath
45384703Shiremath /* Is SRATE specified. */
45394703Shiremath if (attrp->apa_srate.r_srate) {
45404703Shiremath mpr_req->Rate = attrp->apa_srate.r_srate;
45414703Shiremath mpr_req->RateSelector = attrp->apa_srate.r_selector;
45424703Shiremath
45434703Shiremath c_mask |= SA_MPR_COMPMASK_RATE |
45444703Shiremath SA_MPR_COMPMASK_RATESELECTOR;
45454703Shiremath }
45464703Shiremath }
45474703Shiremath
45484703Shiremath /* Alt PathMTU can be GT or EQU to current channel's Pri PathMTU */
45494703Shiremath
45504703Shiremath /* P_Key must be same as that of primary path */
45514703Shiremath retval = ibt_index2pkey_byguid(c_hp.hp_hca_guid, c_hp.hp_port,
45524703Shiremath qp_attr.qp_info.qp_transport.rc.rc_path.cep_pkey_ix,
45534703Shiremath &mpr_req->P_Key);
45544703Shiremath if (retval != IBT_SUCCESS) {
45554703Shiremath IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_alt_path: PKeyIdx2Pkey "
45564703Shiremath "Failed: %d", retval);
45574703Shiremath goto get_ip_alt_path_done;
45584703Shiremath }
45594703Shiremath c_mask |= SA_MPR_COMPMASK_PKEY;
45604703Shiremath
45614703Shiremath mpr_req->Reversible = 1; /* We always get REVERSIBLE paths. */
45624703Shiremath mpr_req->IndependenceSelector = 1;
45634703Shiremath c_mask |= SA_MPR_COMPMASK_REVERSIBLE | SA_MPR_COMPMASK_INDEPSEL;
45644703Shiremath
45654703Shiremath _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*mpr_req))
45664703Shiremath
45674703Shiremath IBTF_DPRINTF_L3(cmlog, "ibt_get_ip_alt_path: CMask: 0x%llX", c_mask);
45684703Shiremath
45694703Shiremath /* NOTE: We will **NOT** specify how many records we want. */
45704703Shiremath
45714703Shiremath IBTF_DPRINTF_L3(cmlog, "ibt_get_ip_alt_path: Primary: MTU %d, PKey[%d]="
45724703Shiremath "0x%X\n\tSGID = %llX:%llX, DGID = %llX:%llX", prim_mtu,
45734703Shiremath qp_attr.qp_info.qp_transport.rc.rc_path.cep_pkey_ix, mpr_req->P_Key,
45744703Shiremath cur_sgid.gid_prefix, cur_sgid.gid_guid, cur_dgid.gid_prefix,
45754703Shiremath cur_dgid.gid_guid);
45764703Shiremath
45774703Shiremath /* Get SA Access Handle. */
45784703Shiremath if (new_sgid.gid_guid != 0)
45794703Shiremath saa_handle = ibcm_get_saa_handle(hcap, n_hp.hp_port);
45804703Shiremath else
45814703Shiremath saa_handle = ibcm_get_saa_handle(hcap, c_hp.hp_port);
45824703Shiremath if (saa_handle == NULL) {
45834703Shiremath retval = IBT_HCA_PORT_NOT_ACTIVE;
45844703Shiremath goto get_ip_alt_path_done;
45854703Shiremath }
45864703Shiremath
45874703Shiremath /* Contact SA Access to retrieve Path Records. */
45884703Shiremath access_args.sq_attr_id = SA_MULTIPATHRECORD_ATTRID;
45894703Shiremath access_args.sq_access_type = IBMF_SAA_RETRIEVE;
45904703Shiremath access_args.sq_component_mask = c_mask;
45914703Shiremath access_args.sq_template = mpr_req;
45924703Shiremath access_args.sq_template_length = sizeof (sa_multipath_record_t);
45934703Shiremath access_args.sq_callback = NULL;
45944703Shiremath access_args.sq_callback_arg = NULL;
45954703Shiremath
45964703Shiremath retval = ibcm_contact_sa_access(saa_handle, &access_args, &length,
45974703Shiremath &results_p);
45984703Shiremath if (retval != IBT_SUCCESS) {
45994703Shiremath goto get_ip_alt_path_done;
46004703Shiremath }
46014703Shiremath
46024703Shiremath num_rec = length / sizeof (sa_path_record_t);
46034703Shiremath
46044703Shiremath kmem_free(mpr_req, template_len);
46054703Shiremath
46064703Shiremath IBTF_DPRINTF_L3(cmlog, "ibt_get_ip_alt_path: Found %d Paths", num_rec);
46074703Shiremath
46084703Shiremath rec_found = 0;
46094703Shiremath if ((results_p != NULL) && (num_rec > 0)) {
46104703Shiremath /* Update the PathInfo with the response Path Records */
46114703Shiremath pr_resp = (sa_path_record_t *)results_p;
46124703Shiremath for (i = 0; i < num_rec; i++, pr_resp++) {
46134703Shiremath if (prim_mtu > pr_resp->Mtu) {
46144703Shiremath IBTF_DPRINTF_L2(cmlog, "ibt_get_ip_alt_path: "
46154703Shiremath "Alt PathMTU(%d) must be GT or EQU to Pri "
46164703Shiremath "PathMTU(%d). Ignore this rec",
46174703Shiremath pr_resp->Mtu, prim_mtu);
46184703Shiremath continue;
46194703Shiremath }
46204703Shiremath
46214703Shiremath if ((new_sgid.gid_guid == 0) &&
46224703Shiremath (new_dgid.gid_guid == 0)) {
46234703Shiremath /* Reject PathRec if it same as Primary Path. */
46244703Shiremath if (ibcm_compare_paths(pr_resp,
46254703Shiremath &qp_attr.qp_info.qp_transport.rc.rc_path,
46269349SShantkumar.Hiremath@Sun.COM &c_hp)) {
46274703Shiremath IBTF_DPRINTF_L3(cmlog,
46284703Shiremath "ibt_get_ip_alt_path: PathRec "
46294703Shiremath "obtained is similar to Prim Path, "
46304703Shiremath "ignore this record");
46314703Shiremath continue;
46324703Shiremath }
46334703Shiremath }
46344703Shiremath
46354703Shiremath if (new_sgid.gid_guid == 0) {
46364703Shiremath retval = ibcm_update_cep_info(pr_resp, NULL,
46374703Shiremath &c_hp, &api_p->ap_alt_cep_path);
46384703Shiremath } else {
46394703Shiremath retval = ibcm_update_cep_info(pr_resp, NULL,
46404703Shiremath &n_hp, &api_p->ap_alt_cep_path);
46414703Shiremath }
46424703Shiremath if (retval != IBT_SUCCESS)
46434703Shiremath continue;
46444703Shiremath
46454703Shiremath /* Update some leftovers */
46464703Shiremath _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*api_p))
46474703Shiremath
46484703Shiremath api_p->ap_alt_pkt_lt = pr_resp->PacketLifeTime;
46494703Shiremath
46504703Shiremath _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*api_p))
46514703Shiremath
46524703Shiremath rec_found = 1;
46534703Shiremath break;
46544703Shiremath }
46554703Shiremath kmem_free(results_p, length);
46564703Shiremath }
46574703Shiremath
46584703Shiremath if (rec_found == 0) {
46594703Shiremath IBTF_DPRINTF_L3(cmlog, "ibt_get_ip_alt_path: AltPath cannot"
46604703Shiremath " be established");
46614703Shiremath retval = IBT_PATH_RECORDS_NOT_FOUND;
46624703Shiremath } else
46634703Shiremath retval = IBT_SUCCESS;
46644703Shiremath
46654703Shiremath get_ip_alt_path_done:
46664703Shiremath if ((snum) && (sgids_p))
46674703Shiremath kmem_free(sgids_p, snum * sizeof (ib_gid_t));
46684703Shiremath
46694703Shiremath if ((dnum) && (dgids_p))
46704703Shiremath kmem_free(dgids_p, dnum * sizeof (ib_gid_t));
46714703Shiremath
46724703Shiremath ibcm_dec_hca_acc_cnt(hcap);
46734703Shiremath
46744703Shiremath IBTF_DPRINTF_L3(cmlog, "ibt_get_ip_alt_path: Done (status %d)", retval);
46754703Shiremath
46764703Shiremath return (retval);
46774703Shiremath }
46784703Shiremath
46794703Shiremath
46800Sstevel@tonic-gate /* Routines for warlock */
46810Sstevel@tonic-gate
46820Sstevel@tonic-gate /* ARGSUSED */
46830Sstevel@tonic-gate static void
ibcm_dummy_path_handler(void * arg,ibt_status_t retval,ibt_path_info_t * paths,uint8_t num_path)46840Sstevel@tonic-gate ibcm_dummy_path_handler(void *arg, ibt_status_t retval, ibt_path_info_t *paths,
46850Sstevel@tonic-gate uint8_t num_path)
46860Sstevel@tonic-gate {
46870Sstevel@tonic-gate ibcm_path_tqargs_t dummy_path;
46880Sstevel@tonic-gate
46890Sstevel@tonic-gate dummy_path.func = ibcm_dummy_path_handler;
46900Sstevel@tonic-gate
46910Sstevel@tonic-gate IBTF_DPRINTF_L5(cmlog, "ibcm_dummy_path_handler: "
46920Sstevel@tonic-gate "dummy_path.func %p", dummy_path.func);
46930Sstevel@tonic-gate }
46944703Shiremath
46954703Shiremath /* ARGSUSED */
46964703Shiremath static void
ibcm_dummy_ip_path_handler(void * arg,ibt_status_t retval,ibt_path_info_t * paths,uint8_t num_path,ibt_path_ip_src_t * src_ip)46974703Shiremath ibcm_dummy_ip_path_handler(void *arg, ibt_status_t retval,
46984703Shiremath ibt_path_info_t *paths, uint8_t num_path, ibt_path_ip_src_t *src_ip)
46994703Shiremath {
47004703Shiremath ibcm_ip_path_tqargs_t dummy_path;
47014703Shiremath
47024703Shiremath dummy_path.func = ibcm_dummy_ip_path_handler;
47034703Shiremath
47044703Shiremath IBTF_DPRINTF_L5(cmlog, "ibcm_dummy_ip_path_handler: "
47054703Shiremath "dummy_path.func %p", dummy_path.func);
47064703Shiremath }
4707