2 * Copyright (c) 2006-2009 Voltaire, Inc. All rights reserved.
3 * Copyright (c) 2002-2012 Mellanox Technologies LTD. All rights reserved.
4 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5 * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
11 * OpenIB.org BSD license below:
13 * Redistribution and use in source and binary forms, with or
14 * without modification, are permitted provided that the following
17 * - Redistributions of source code must retain the above
18 * copyright notice, this list of conditions and the following
21 * - Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials
24 * provided with the distribution.
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 * Implementation of osm_gir_rcv_t.
40 * This object represents the GUIDInfoRecord Receiver object.
41 * This object is part of the opensm family of objects.
46 #endif /* HAVE_CONFIG_H */
49 #include <iba/ib_types.h>
50 #include <complib/cl_qmap.h>
51 #include <complib/cl_passivelock.h>
52 #include <complib/cl_debug.h>
53 #include <complib/cl_qlist.h>
54 #include <opensm/osm_file_ids.h>
55 #define FILE_ID OSM_FILE_SA_GUIDINFO_RECORD_C
56 #include <vendor/osm_vendor_api.h>
57 #include <opensm/osm_port.h>
58 #include <opensm/osm_node.h>
59 #include <opensm/osm_guid.h>
60 #include <opensm/osm_helper.h>
61 #include <opensm/osm_pkey.h>
62 #include <opensm/osm_sa.h>
64 #define SA_GIR_RESP_SIZE SA_ITEM_RESP_SIZE(guid_rec)
66 #define MOD_GIR_COMP_MASK (IB_GIR_COMPMASK_LID | IB_GIR_COMPMASK_BLOCKNUM)
68 typedef struct osm_gir_item {
69 cl_list_item_t list_item;
70 ib_guidinfo_record_t rec;
73 typedef struct osm_gir_search_ctxt {
74 const ib_guidinfo_record_t *p_rcvd_rec;
78 const osm_physp_t *p_req_physp;
79 } osm_gir_search_ctxt_t;
81 static ib_api_status_t gir_rcv_new_gir(IN osm_sa_t * sa,
82 IN const osm_node_t * p_node,
83 IN cl_qlist_t * p_list,
84 IN ib_net64_t const match_port_guid,
85 IN ib_net16_t const match_lid,
86 IN const osm_physp_t * p_physp,
87 IN uint8_t const block_num)
89 osm_sa_item_t *p_rec_item;
90 ib_api_status_t status = IB_SUCCESS;
92 OSM_LOG_ENTER(sa->p_log);
94 p_rec_item = malloc(SA_GIR_RESP_SIZE);
95 if (p_rec_item == NULL) {
96 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 5102: "
97 "rec_item alloc failed\n");
98 status = IB_INSUFFICIENT_RESOURCES;
102 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
103 "New GUIDInfoRecord: lid %u, block num %d\n",
104 cl_ntoh16(match_lid), block_num);
106 memset(p_rec_item, 0, SA_GIR_RESP_SIZE);
108 p_rec_item->resp.guid_rec.lid = match_lid;
109 p_rec_item->resp.guid_rec.block_num = block_num;
110 if (p_physp->p_guids)
111 memcpy(&p_rec_item->resp.guid_rec.guid_info,
112 *p_physp->p_guids + block_num * GUID_TABLE_MAX_ENTRIES,
113 sizeof(ib_guid_info_t));
115 p_rec_item->resp.guid_rec.guid_info.guid[0] = osm_physp_get_port_guid(p_physp);
117 cl_qlist_insert_tail(p_list, &p_rec_item->list_item);
120 OSM_LOG_EXIT(sa->p_log);
124 static void sa_gir_create_gir(IN osm_sa_t * sa, IN osm_node_t * p_node,
125 IN cl_qlist_t * p_list,
126 IN ib_net64_t const match_port_guid,
127 IN ib_net16_t const match_lid,
128 IN const osm_physp_t * p_req_physp,
129 IN uint8_t const match_block_num)
131 const osm_physp_t *p_physp;
134 uint16_t match_lid_ho;
135 ib_net16_t base_lid_ho;
136 ib_net16_t max_lid_ho;
138 ib_net64_t port_guid;
139 uint8_t block_num, start_block_num, end_block_num, num_blocks;
141 OSM_LOG_ENTER(sa->p_log);
143 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
144 "Looking for GUIDRecord with LID: %u GUID:0x%016"
145 PRIx64 "\n", cl_ntoh16(match_lid), cl_ntoh64(match_port_guid));
148 For switches, do not return the GUIDInfo record(s)
149 for each port on the switch, just for port 0.
151 if (osm_node_get_type(p_node) == IB_NODE_TYPE_SWITCH)
154 num_ports = osm_node_get_num_physp(p_node);
156 for (port_num = 0; port_num < num_ports; port_num++) {
157 p_physp = osm_node_get_physp_ptr(p_node, port_num);
161 /* Check to see if the found p_physp and the requester physp
162 share a pkey. If not, continue */
163 if (!osm_physp_share_pkey(sa->p_log, p_physp, p_req_physp,
164 sa->p_subn->opt.allow_both_pkeys))
167 port_guid = osm_physp_get_port_guid(p_physp);
169 if (match_port_guid && (port_guid != match_port_guid))
173 Note: the following check is a temporary workaround
174 Since 1. GUIDCap should never be 0 on ports where this applies
175 and 2. GUIDCap should not be used on ports where it doesn't apply
176 So this should really be a check for whether the port is a
177 switch external port or not!
179 if (p_physp->port_info.guid_cap == 0)
182 num_blocks = p_physp->port_info.guid_cap / 8;
183 if (p_physp->port_info.guid_cap % 8)
185 if (match_block_num == 255) {
187 end_block_num = num_blocks - 1;
189 if (match_block_num >= num_blocks)
191 end_block_num = start_block_num = match_block_num;
194 base_lid_ho = cl_ntoh16(osm_physp_get_base_lid(p_physp));
195 match_lid_ho = cl_ntoh16(match_lid);
197 lmc = osm_physp_get_lmc(p_physp);
198 max_lid_ho = (uint16_t) (base_lid_ho + (1 << lmc) - 1);
201 We validate that the lid belongs to this node.
203 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
204 "Comparing LID: %u <= %u <= %u\n",
205 base_lid_ho, match_lid_ho, max_lid_ho);
207 if (match_lid_ho < base_lid_ho
208 || match_lid_ho > max_lid_ho)
212 for (block_num = start_block_num; block_num <= end_block_num;
214 gir_rcv_new_gir(sa, p_node, p_list, port_guid,
215 cl_ntoh16(base_lid_ho), p_physp,
219 OSM_LOG_EXIT(sa->p_log);
222 static void sa_gir_by_comp_mask_cb(IN cl_map_item_t * p_map_item, IN void *cxt)
224 const osm_gir_search_ctxt_t *p_ctxt = cxt;
225 osm_node_t *const p_node = (osm_node_t *) p_map_item;
226 const ib_guidinfo_record_t *const p_rcvd_rec = p_ctxt->p_rcvd_rec;
227 const osm_physp_t *const p_req_physp = p_ctxt->p_req_physp;
228 osm_sa_t *sa = p_ctxt->sa;
229 const ib_guid_info_t *p_comp_gi;
230 ib_net64_t const comp_mask = p_ctxt->comp_mask;
231 ib_net64_t match_port_guid = 0;
232 ib_net16_t match_lid = 0;
233 uint8_t match_block_num = 255;
235 OSM_LOG_ENTER(p_ctxt->sa->p_log);
237 if (comp_mask & IB_GIR_COMPMASK_LID)
238 match_lid = p_rcvd_rec->lid;
240 if (comp_mask & IB_GIR_COMPMASK_BLOCKNUM)
241 match_block_num = p_rcvd_rec->block_num;
243 p_comp_gi = &p_rcvd_rec->guid_info;
244 /* Different rule for block 0 v. other blocks */
245 if (comp_mask & IB_GIR_COMPMASK_GID0) {
246 if (!p_rcvd_rec->block_num)
247 match_port_guid = osm_physp_get_port_guid(p_req_physp);
248 if (p_comp_gi->guid[0] != match_port_guid)
252 if (comp_mask & IB_GIR_COMPMASK_GID1) {
253 if (p_comp_gi->guid[1] != 0)
257 if (comp_mask & IB_GIR_COMPMASK_GID2) {
258 if (p_comp_gi->guid[2] != 0)
262 if (comp_mask & IB_GIR_COMPMASK_GID3) {
263 if (p_comp_gi->guid[3] != 0)
267 if (comp_mask & IB_GIR_COMPMASK_GID4) {
268 if (p_comp_gi->guid[4] != 0)
272 if (comp_mask & IB_GIR_COMPMASK_GID5) {
273 if (p_comp_gi->guid[5] != 0)
277 if (comp_mask & IB_GIR_COMPMASK_GID6) {
278 if (p_comp_gi->guid[6] != 0)
282 if (comp_mask & IB_GIR_COMPMASK_GID7) {
283 if (p_comp_gi->guid[7] != 0)
287 sa_gir_create_gir(sa, p_node, p_ctxt->p_list, match_port_guid,
288 match_lid, p_req_physp, match_block_num);
291 OSM_LOG_EXIT(p_ctxt->sa->p_log);
294 static inline boolean_t check_mod_comp_mask(ib_net64_t comp_mask)
296 return ((comp_mask & MOD_GIR_COMP_MASK) == MOD_GIR_COMP_MASK);
299 static uint8_t coalesce_comp_mask(IN osm_madw_t *p_madw)
301 uint8_t comp_mask = 0;
302 ib_sa_mad_t *p_sa_mad;
304 p_sa_mad = osm_madw_get_sa_mad_ptr(p_madw);
305 if (p_sa_mad->comp_mask & IB_GIR_COMPMASK_GID0)
307 if (p_sa_mad->comp_mask & IB_GIR_COMPMASK_GID1)
309 if (p_sa_mad->comp_mask & IB_GIR_COMPMASK_GID2)
311 if (p_sa_mad->comp_mask & IB_GIR_COMPMASK_GID3)
313 if (p_sa_mad->comp_mask & IB_GIR_COMPMASK_GID4)
315 if (p_sa_mad->comp_mask & IB_GIR_COMPMASK_GID5)
317 if (p_sa_mad->comp_mask & IB_GIR_COMPMASK_GID6)
319 if (p_sa_mad->comp_mask & IB_GIR_COMPMASK_GID7)
324 static void guidinfo_respond(IN osm_sa_t *sa, IN osm_madw_t *p_madw,
325 IN ib_guidinfo_record_t * p_guidinfo_rec)
330 OSM_LOG_ENTER(sa->p_log);
332 item = malloc(SA_GIR_RESP_SIZE);
334 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 5101: "
335 "rec_item alloc failed\n");
339 item->resp.guid_rec = *p_guidinfo_rec;
341 cl_qlist_init(&rec_list);
342 cl_qlist_insert_tail(&rec_list, &item->list_item);
344 osm_sa_respond(sa, p_madw, sizeof(ib_guidinfo_record_t), &rec_list);
347 OSM_LOG_EXIT(sa->p_log);
350 static void gir_respond(IN osm_sa_t *sa, IN osm_madw_t *p_madw)
352 ib_sa_mad_t *p_sa_mad;
353 ib_guidinfo_record_t *p_rcvd_rec;
354 ib_guidinfo_record_t guidinfo_rec;
356 p_sa_mad = osm_madw_get_sa_mad_ptr(p_madw);
357 p_rcvd_rec = (ib_guidinfo_record_t *) ib_sa_mad_get_payload_ptr(p_sa_mad);
358 if (OSM_LOG_IS_ACTIVE_V2(sa->p_log, OSM_LOG_DEBUG))
359 osm_dump_guidinfo_record_v2(sa->p_log, p_rcvd_rec, FILE_ID, OSM_LOG_DEBUG);
361 guidinfo_rec = *p_rcvd_rec;
362 guidinfo_respond(sa, p_madw, &guidinfo_rec);
365 static ib_net64_t sm_assigned_guid(uint8_t assigned_byte)
367 static uint32_t uniq_count;
369 if (++uniq_count == 0) {
373 return cl_hton64(((uint64_t) uniq_count) |
374 (((uint64_t) assigned_byte) << 32) |
375 (((uint64_t) OSM_VENDOR_ID_OPENIB) << 40));
378 static void del_guidinfo(IN osm_sa_t *sa, IN osm_madw_t *p_madw,
379 IN osm_port_t *p_port, IN uint8_t block_num)
383 ib_sa_mad_t *p_sa_mad;
384 ib_guidinfo_record_t *p_rcvd_rec;
385 ib_net64_t del_alias_guid;
386 osm_alias_guid_t *p_alias_guid;
387 cl_list_item_t *p_list_item;
388 osm_mcm_port_t *p_mcm_port;
389 osm_mcm_alias_guid_t *p_mcm_alias_guid;
393 if (!p_port->p_physp->p_guids)
396 max_block = (p_port->p_physp->port_info.guid_cap + GUID_TABLE_MAX_ENTRIES - 1) /
397 GUID_TABLE_MAX_ENTRIES;
399 if (block_num >= max_block) {
400 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 5116: "
401 "block_num %d is higher than Max GUID Cap block %d "
402 "for port GUID 0x%" PRIx64 "\n",
403 block_num, max_block, cl_ntoh64(p_port->p_physp->port_guid));
404 CL_PLOCK_RELEASE(sa->p_lock);
405 osm_sa_send_error(sa, p_madw,
406 IB_SA_MAD_STATUS_NO_RECORDS);
410 p_sa_mad = osm_madw_get_sa_mad_ptr(p_madw);
412 (ib_guidinfo_record_t *) ib_sa_mad_get_payload_ptr(p_sa_mad);
414 del_mask = coalesce_comp_mask(p_madw);
416 for (i = block_num * GUID_TABLE_MAX_ENTRIES;
417 (block_num + 1) * GUID_TABLE_MAX_ENTRIES < p_port->p_physp->port_info.guid_cap ? i < (block_num + 1) * GUID_TABLE_MAX_ENTRIES : i < p_port->p_physp->port_info.guid_cap;
419 /* can't delete block 0 index 0 (base guid is RO) for alias guid table */
420 if (i == 0 && p_sa_mad->comp_mask & IB_GIR_COMPMASK_GID0) {
421 CL_PLOCK_RELEASE(sa->p_lock);
422 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
423 "Not allowed to delete RO GID 0\n");
424 osm_sa_send_error(sa, p_madw,
425 IB_SA_MAD_STATUS_REQ_INVALID);
428 if (!(del_mask & 1<<(i % 8)))
431 del_alias_guid = (*p_port->p_physp->p_guids)[i];
432 if (del_alias_guid) {
433 /* Search all of port's multicast groups for alias */
434 p_list_item = cl_qlist_head(&p_port->mcm_list);
435 while (p_list_item != cl_qlist_end(&p_port->mcm_list)) {
436 p_mcm_port = cl_item_obj(p_list_item,
437 p_mcm_port, list_item);
438 p_list_item = cl_qlist_next(p_list_item);
439 p_mcm_alias_guid = osm_mgrp_get_mcm_alias_guid(p_mcm_port->mgrp, del_alias_guid);
440 if (p_mcm_alias_guid) {
441 CL_PLOCK_RELEASE(sa->p_lock);
442 osm_sa_send_error(sa, p_madw,
443 IB_SA_MAD_STATUS_DENIED);
450 for (i = block_num * GUID_TABLE_MAX_ENTRIES;
451 (block_num + 1) * GUID_TABLE_MAX_ENTRIES < p_port->p_physp->port_info.guid_cap ? i < (block_num + 1) * GUID_TABLE_MAX_ENTRIES : i < p_port->p_physp->port_info.guid_cap;
453 if (!(del_mask & 1<<(i % 8)))
456 del_alias_guid = (*p_port->p_physp->p_guids)[i];
457 if (del_alias_guid) {
458 /* remove original from alias guid table */
459 p_alias_guid = (osm_alias_guid_t *)
460 cl_qmap_remove(&sa->p_subn->alias_port_guid_tbl,
462 if (p_alias_guid != (osm_alias_guid_t *)
463 cl_qmap_end(&sa->p_subn->alias_port_guid_tbl))
464 osm_alias_guid_delete(&p_alias_guid);
466 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 510B: "
467 "Original alias GUID 0x%" PRIx64
468 " at index %u not found\n",
469 cl_ntoh64(del_alias_guid), i);
470 /* clear guid at index */
471 (*p_port->p_physp->p_guids)[i] = 0;
477 if (osm_queue_guidinfo(sa, p_port, block_num))
478 osm_sm_signal(sa->sm, OSM_SIGNAL_GUID_PROCESS_REQUEST);
482 memcpy(&p_rcvd_rec->guid_info,
483 &((*p_port->p_physp->p_guids)[block_num * GUID_TABLE_MAX_ENTRIES]),
484 sizeof(ib_guid_info_t));
487 CL_PLOCK_RELEASE(sa->p_lock);
488 gir_respond(sa, p_madw);
491 static void set_guidinfo(IN osm_sa_t *sa, IN osm_madw_t *p_madw,
492 IN osm_port_t *p_port, IN uint8_t block_num)
496 ib_sa_mad_t *p_sa_mad;
497 ib_guidinfo_record_t *p_rcvd_rec;
498 osm_assigned_guids_t *p_assigned_guids = 0;
499 osm_alias_guid_t *p_alias_guid, *p_alias_guid_check;
500 cl_map_item_t *p_item;
501 ib_net64_t set_alias_guid, del_alias_guid, assigned_guid;
504 max_block = (p_port->p_physp->port_info.guid_cap + GUID_TABLE_MAX_ENTRIES - 1) /
505 GUID_TABLE_MAX_ENTRIES;
506 if (block_num >= max_block) {
507 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 5118: "
508 "block_num %d is higher than Max GUID Cap block %d "
509 "for port GUID 0x%" PRIx64 "\n",
510 block_num, max_block, cl_ntoh64(p_port->p_physp->port_guid));
511 CL_PLOCK_RELEASE(sa->p_lock);
512 osm_sa_send_error(sa, p_madw,
513 IB_SA_MAD_STATUS_NO_RECORDS);
516 if (!p_port->p_physp->p_guids) {
517 p_port->p_physp->p_guids = calloc(max_block * GUID_TABLE_MAX_ENTRIES,
519 if (!p_port->p_physp->p_guids) {
520 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 5103: "
521 "GUID table memory allocation failed for port "
522 "GUID 0x%" PRIx64 "\n",
523 cl_ntoh64(p_port->p_physp->port_guid));
524 CL_PLOCK_RELEASE(sa->p_lock);
525 osm_sa_send_error(sa, p_madw,
526 IB_SA_MAD_STATUS_NO_RESOURCES);
529 /* setup base port guid in index 0 */
530 (*p_port->p_physp->p_guids)[0] = p_port->p_physp->port_guid;
533 p_sa_mad = osm_madw_get_sa_mad_ptr(p_madw);
534 p_rcvd_rec = (ib_guidinfo_record_t *) ib_sa_mad_get_payload_ptr(p_sa_mad);
536 if (OSM_LOG_IS_ACTIVE_V2(sa->p_log, OSM_LOG_DEBUG)) {
537 OSM_LOG(sa->p_log, OSM_LOG_DEBUG, "Dump of incoming record\n");
538 osm_dump_guidinfo_record_v2(sa->p_log, p_rcvd_rec, FILE_ID, OSM_LOG_DEBUG);
541 set_mask = coalesce_comp_mask(p_madw);
543 for (i = block_num * GUID_TABLE_MAX_ENTRIES;
544 (block_num + 1) * GUID_TABLE_MAX_ENTRIES < p_port->p_physp->port_info.guid_cap ? i < (block_num + 1) * GUID_TABLE_MAX_ENTRIES : i < p_port->p_physp->port_info.guid_cap;
546 /* can't set block 0 index 0 (base guid is RO) for alias guid table */
547 if (i == 0 && p_sa_mad->comp_mask & IB_GIR_COMPMASK_GID0) {
548 CL_PLOCK_RELEASE(sa->p_lock);
549 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
550 "Not allowed to set RO GID 0\n");
551 osm_sa_send_error(sa, p_madw,
552 IB_SA_MAD_STATUS_REQ_INVALID);
556 if (!(set_mask & 1<<(i % 8)))
559 set_alias_guid = p_rcvd_rec->guid_info.guid[i % 8];
560 if (!set_alias_guid) {
561 /* was a GUID previously assigned for this index ? */
562 set_alias_guid = (*p_port->p_physp->p_guids)[i];
563 if (set_alias_guid) {
564 p_rcvd_rec->guid_info.guid[i % 8] = set_alias_guid;
567 /* Is there a persistent SA assigned guid for this index ? */
568 if (!p_assigned_guids)
570 osm_get_assigned_guids_by_guid(sa->p_subn,
571 p_port->p_physp->port_guid);
572 if (p_assigned_guids) {
573 set_alias_guid = p_assigned_guids->assigned_guid[i];
574 if (set_alias_guid) {
575 p_rcvd_rec->guid_info.guid[i % 8] = set_alias_guid;
576 p_item = cl_qmap_get(&sa->sm->p_subn->alias_port_guid_tbl,
578 if (p_item == cl_qmap_end(&sa->sm->p_subn->alias_port_guid_tbl))
581 p_alias_guid = (osm_alias_guid_t *) p_item;
582 if (p_alias_guid->p_base_port != p_port) {
586 " Assigned alias port GUID 0x%" PRIx64
587 " index %d base port GUID 0x%" PRIx64
588 " now attempted on port GUID 0x%" PRIx64
590 cl_ntoh64(p_alias_guid->alias_guid), i,
591 cl_ntoh64(p_alias_guid->p_base_port->guid),
592 cl_ntoh64(p_port->guid));
593 /* clear response guid at index to indicate duplicate */
594 p_rcvd_rec->guid_info.guid[i % 8] = 0;
601 if (!set_alias_guid) {
602 for (j = 0; j < 1000; j++) {
603 assigned_guid = sm_assigned_guid(sa->p_subn->opt.sm_assigned_guid);
604 if (!assigned_guid) {
605 CL_PLOCK_RELEASE(sa->p_lock);
606 OSM_LOG(sa->p_log, OSM_LOG_ERROR,
607 "ERR 510E: No more assigned guids available\n");
608 osm_sa_send_error(sa, p_madw,
609 IB_SA_MAD_STATUS_NO_RESOURCES);
612 p_item = cl_qmap_get(&sa->sm->p_subn->alias_port_guid_tbl,
614 if (p_item == cl_qmap_end(&sa->sm->p_subn->alias_port_guid_tbl)) {
615 set_alias_guid = assigned_guid;
616 p_rcvd_rec->guid_info.guid[i % 8] = assigned_guid;
617 if (!p_assigned_guids) {
618 p_assigned_guids = osm_assigned_guids_new(p_port->p_physp->port_guid,
619 max_block * GUID_TABLE_MAX_ENTRIES);
620 if (p_assigned_guids) {
621 cl_qmap_insert(&(sa->p_subn->assigned_guids_tbl),
622 p_assigned_guids->port_guid,
623 &p_assigned_guids->map_item);
627 "ERR 510D: osm_assigned_guids_new failed port GUID 0x%" PRIx64 " index %d\n",
628 cl_ntoh64(p_port->p_physp->port_guid), i);
629 CL_PLOCK_RELEASE(sa->p_lock);
630 osm_sa_send_error(sa, p_madw,
631 IB_SA_MAD_STATUS_NO_RESOURCES);
635 if (p_assigned_guids)
636 p_assigned_guids->assigned_guid[i] = assigned_guid;
640 if (!set_alias_guid) {
641 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 510A: "
642 "SA assigned GUID %d failed for "
643 "port GUID 0x%" PRIx64 "\n", i,
644 cl_ntoh64(p_port->p_physp->port_guid));
650 /* allocate alias guid and add to alias guid table */
651 p_alias_guid = osm_alias_guid_new(set_alias_guid, p_port);
653 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 5107: "
654 "Alias guid %d memory allocation failed"
655 " for port GUID 0x%" PRIx64 "\n",
656 i, cl_ntoh64(p_port->p_physp->port_guid));
657 CL_PLOCK_RELEASE(sa->p_lock);
662 (osm_alias_guid_t *) cl_qmap_insert(&sa->sm->p_subn->alias_port_guid_tbl,
663 p_alias_guid->alias_guid,
664 &p_alias_guid->map_item);
665 if (p_alias_guid_check != p_alias_guid) {
666 /* alias GUID is a duplicate if it exists on another port or on the same port but at another index */
667 if (p_alias_guid_check->p_base_port != p_port ||
668 (*p_port->p_physp->p_guids)[i] != set_alias_guid) {
669 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 5108: "
670 "Duplicate alias port GUID 0x%" PRIx64
671 " index %d base port GUID 0x%" PRIx64
672 ", alias GUID already assigned to "
673 "base port GUID 0x%" PRIx64 "\n",
674 cl_ntoh64(p_alias_guid->alias_guid), i,
675 cl_ntoh64(p_alias_guid->p_base_port->guid),
676 cl_ntoh64(p_alias_guid_check->p_base_port->guid));
677 /* clear response guid at index to indicate duplicate */
678 p_rcvd_rec->guid_info.guid[i % 8] = 0;
680 osm_alias_guid_delete(&p_alias_guid);
682 del_alias_guid = (*p_port->p_physp->p_guids)[i];
683 if (del_alias_guid) {
684 /* remove original from alias guid table */
685 p_alias_guid_check = (osm_alias_guid_t *)
686 cl_qmap_remove(&sa->p_subn->alias_port_guid_tbl,
688 if (p_alias_guid_check)
689 osm_alias_guid_delete(&p_alias_guid_check);
691 OSM_LOG(sa->p_log, OSM_LOG_ERROR,
692 "ERR 510C: Original alias GUID "
693 "0x%" PRIx64 "at index %u "
695 cl_ntoh64(del_alias_guid),
699 /* insert or replace guid at index */
700 (*p_port->p_physp->p_guids)[i] = set_alias_guid;
706 if (osm_queue_guidinfo(sa, p_port, block_num))
707 osm_sm_signal(sa->sm, OSM_SIGNAL_GUID_PROCESS_REQUEST);
711 memcpy(&p_rcvd_rec->guid_info,
712 &((*p_port->p_physp->p_guids)[block_num * GUID_TABLE_MAX_ENTRIES]),
713 sizeof(ib_guid_info_t));
715 CL_PLOCK_RELEASE(sa->p_lock);
716 gir_respond(sa, p_madw);
719 static void get_guidinfo(IN osm_sa_t *sa, IN osm_madw_t *p_madw,
720 IN osm_physp_t *p_req_physp)
722 const ib_sa_mad_t *p_rcvd_mad;
723 const ib_guidinfo_record_t *p_rcvd_rec;
725 osm_gir_search_ctxt_t context;
727 p_rcvd_mad = osm_madw_get_sa_mad_ptr(p_madw);
729 (ib_guidinfo_record_t *) ib_sa_mad_get_payload_ptr(p_rcvd_mad);
731 cl_qlist_init(&rec_list);
733 context.p_rcvd_rec = p_rcvd_rec;
734 context.p_list = &rec_list;
735 context.comp_mask = p_rcvd_mad->comp_mask;
737 context.p_req_physp = p_req_physp;
740 cl_qmap_apply_func(&sa->p_subn->node_guid_tbl, sa_gir_by_comp_mask_cb,
743 CL_PLOCK_RELEASE(sa->p_lock);
745 osm_sa_respond(sa, p_madw, sizeof(ib_guidinfo_record_t), &rec_list);
748 void osm_gir_rcv_process(IN void *ctx, IN void *data)
751 osm_madw_t *p_madw = data;
752 const ib_sa_mad_t *p_rcvd_mad;
753 osm_physp_t *p_req_physp;
755 const ib_guidinfo_record_t *p_rcvd_rec;
759 OSM_LOG_ENTER(sa->p_log);
763 p_rcvd_mad = osm_madw_get_sa_mad_ptr(p_madw);
765 CL_ASSERT(p_rcvd_mad->attr_id == IB_MAD_ATTR_GUIDINFO_RECORD);
767 switch(p_rcvd_mad->method) {
768 case IB_MAD_METHOD_GET:
769 case IB_MAD_METHOD_GETTABLE:
770 /* update the requester physical port */
771 CL_PLOCK_ACQUIRE(sa->p_lock);
772 p_req_physp = osm_get_physp_by_mad_addr(sa->p_log, sa->p_subn,
773 osm_madw_get_mad_addr_ptr(p_madw));
774 if (p_req_physp == NULL) {
775 CL_PLOCK_RELEASE(sa->p_lock);
776 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 5104: "
777 "Cannot find requester physical port\n");
780 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
781 "Requester port GUID 0x%" PRIx64 "\n",
782 cl_ntoh64(osm_physp_get_port_guid(p_req_physp)));
784 get_guidinfo(sa, p_madw, p_req_physp);
786 case IB_MAD_METHOD_SET:
787 case IB_MAD_METHOD_DELETE:
788 if (!check_mod_comp_mask(p_rcvd_mad->comp_mask)) {
789 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 5106: "
790 "component mask = 0x%016" PRIx64 ", "
791 "expected comp mask = 0x%016" PRIx64 "\n",
792 cl_ntoh64(p_rcvd_mad->comp_mask),
793 CL_NTOH64(MOD_GIR_COMP_MASK));
794 osm_sa_send_error(sa, p_madw,
795 IB_SA_MAD_STATUS_INSUF_COMPS);
798 p_rcvd_rec = (ib_guidinfo_record_t *) ib_sa_mad_get_payload_ptr(p_rcvd_mad);
800 /* update the requester physical port */
801 CL_PLOCK_EXCL_ACQUIRE(sa->p_lock);
802 p_req_physp = osm_get_physp_by_mad_addr(sa->p_log, sa->p_subn,
803 osm_madw_get_mad_addr_ptr(p_madw));
804 if (p_req_physp == NULL) {
805 CL_PLOCK_RELEASE(sa->p_lock);
806 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 5104: "
807 "Cannot find requester physical port\n");
810 OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
811 "Requester port GUID 0x%" PRIx64 "\n",
812 cl_ntoh64(osm_physp_get_port_guid(p_req_physp)));
814 p_port = osm_get_port_by_lid(sa->p_subn, p_rcvd_rec->lid);
816 CL_PLOCK_RELEASE(sa->p_lock);
817 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 5117: "
818 "Port with LID %u not found\n",
819 cl_ntoh16(p_rcvd_rec->lid));
820 osm_sa_send_error(sa, p_madw, IB_SA_MAD_STATUS_NO_RECORDS);
823 if (!osm_physp_share_pkey(sa->p_log, p_req_physp, p_port->p_physp,
824 sa->p_subn->opt.allow_both_pkeys)) {
825 CL_PLOCK_RELEASE(sa->p_lock);
829 if (p_rcvd_mad->method == IB_MAD_METHOD_SET)
830 set_guidinfo(sa, p_madw, p_port, p_rcvd_rec->block_num);
832 del_guidinfo(sa, p_madw, p_port, p_rcvd_rec->block_num);
835 OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 5105: "
836 "Unsupported Method (%s) for GUIDInfoRecord request\n",
837 ib_get_sa_method_str(p_rcvd_mad->method));
838 osm_sa_send_error(sa, p_madw, IB_MAD_STATUS_UNSUP_METHOD_ATTR);
843 OSM_LOG_EXIT(sa->p_log);