2 * Copyright (c) 2004-2007 Voltaire, Inc. All rights reserved.
3 * Copyright (c) 2002-2006 Mellanox Technologies LTD. All rights reserved.
4 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38 #endif /* HAVE_CONFIG_H */
41 #include <complib/cl_debug.h>
42 #include <opensm/osm_db_pack.h>
44 static inline void __osm_pack_guid(uint64_t guid, char *p_guid_str)
46 sprintf(p_guid_str, "0x%016" PRIx64, guid);
49 static inline uint64_t __osm_unpack_guid(char *p_guid_str)
51 return strtoull(p_guid_str, NULL, 0);
55 __osm_pack_lids(uint16_t min_lid, uint16_t max_lid, char *p_lid_str)
57 sprintf(p_lid_str, "0x%04x 0x%04x", min_lid, max_lid);
61 __osm_unpack_lids(IN char *p_lid_str,
62 OUT uint16_t * p_min_lid, OUT uint16_t * p_max_lid)
69 strncpy(lids_str, p_lid_str, 23);
71 p_num = strtok_r(lids_str, " \t", &p_next);
74 tmp = strtoul(p_num, NULL, 0);
75 CL_ASSERT(tmp < 0x10000);
76 *p_min_lid = (uint16_t) tmp;
78 p_num = strtok_r(NULL, " \t", &p_next);
81 tmp = strtoul(p_num, NULL, 0);
82 CL_ASSERT(tmp < 0x10000);
83 *p_max_lid = (uint16_t) tmp;
89 osm_db_guid2lid_guids(IN osm_db_domain_t * const p_g2l,
90 OUT cl_qlist_t * p_guid_list)
94 osm_db_guid_elem_t *p_guid_elem;
96 cl_list_construct(&keys);
97 cl_list_init(&keys, 10);
99 if (osm_db_keys(p_g2l, &keys))
102 while ((p_key = cl_list_remove_head(&keys)) != NULL) {
104 (osm_db_guid_elem_t *) malloc(sizeof(osm_db_guid_elem_t));
105 CL_ASSERT(p_guid_elem != NULL);
107 p_guid_elem->guid = __osm_unpack_guid(p_key);
108 cl_qlist_insert_head(p_guid_list, &p_guid_elem->item);
111 cl_list_destroy(&keys);
116 osm_db_guid2lid_get(IN osm_db_domain_t * const p_g2l,
118 OUT uint16_t * p_min_lid, OUT uint16_t * p_max_lid)
122 uint16_t min_lid, max_lid;
124 __osm_pack_guid(guid, guid_str);
125 p_lid_str = osm_db_lookup(p_g2l, guid_str);
128 if (__osm_unpack_lids(p_lid_str, &min_lid, &max_lid))
132 *p_min_lid = min_lid;
134 *p_max_lid = max_lid;
140 osm_db_guid2lid_set(IN osm_db_domain_t * const p_g2l,
141 IN uint64_t guid, IN uint16_t min_lid, IN uint16_t max_lid)
146 __osm_pack_guid(guid, guid_str);
147 __osm_pack_lids(min_lid, max_lid, lid_str);
149 return (osm_db_update(p_g2l, guid_str, lid_str));
152 int osm_db_guid2lid_delete(IN osm_db_domain_t * const p_g2l, IN uint64_t guid)
155 __osm_pack_guid(guid, guid_str);
156 return (osm_db_delete(p_g2l, guid_str));