1 /*
2 * Copyright (c) 2004-2009 Voltaire, Inc. All rights reserved.
3 * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
4 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5 *
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:
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
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.
24 *
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
32 * SOFTWARE.
33 *
34 */
35
36 /****h* OpenSM/DB-Pack
37 * NAME
38 * Database Types
39 *
40 * DESCRIPTION
41 * This module provides packing and unpacking of the database
42 * storage into specific types.
43 *
44 * The following domains/conversions are supported:
45 * guid2lid - key is a guid and data is a lid.
46 *
47 * AUTHOR
48 * Eitan Zahavi, Mellanox Technologies LTD
49 *
50 *********/
51
52 #ifndef _OSM_DB_PACK_H_
53 #define _OSM_DB_PACK_H_
54
55 #include <opensm/osm_db.h>
56
57 #ifdef __cplusplus
58 # define BEGIN_C_DECLS extern "C" {
59 # define END_C_DECLS }
60 #else /* !__cplusplus */
61 # define BEGIN_C_DECLS
62 # define END_C_DECLS
63 #endif /* __cplusplus */
64
65 BEGIN_C_DECLS
66 /****f* OpenSM: DB-Pack/osm_db_guid2lid_init
67 * NAME
68 * osm_db_guid2lid_init
69 *
70 * DESCRIPTION
71 * Initialize a domain for the guid2lid table
72 *
73 * SYNOPSIS
74 */
osm_db_guid2lid_init(IN osm_db_t * p_db)75 static inline osm_db_domain_t *osm_db_guid2lid_init(IN osm_db_t * p_db)
76 {
77 return (osm_db_domain_init(p_db, "guid2lid"));
78 }
79
80 /*
81 * PARAMETERS
82 * p_db
83 * [in] Pointer to the database object to construct
84 *
85 * RETURN VALUES
86 * The pointer to the new allocated domain object or NULL.
87 *
88 * NOTE: DB domains are destroyed by the osm_db_destroy
89 *
90 * SEE ALSO
91 * Database, osm_db_init, osm_db_destroy
92 *********/
93
94 /****f* OpenSM: DB-Pack/osm_db_guid2lid_init
95 * NAME
96 * osm_db_guid2lid_init
97 *
98 * DESCRIPTION
99 * Initialize a domain for the guid2lid table
100 *
101 * SYNOPSIS
102 */
103 typedef struct osm_db_guid_elem {
104 cl_list_item_t item;
105 uint64_t guid;
106 } osm_db_guid_elem_t;
107 /*
108 * FIELDS
109 * item
110 * required for list manipulations
111 *
112 * guid
113 *
114 ************/
115
116 /****f* OpenSM: DB-Pack/osm_db_guid2lid_guids
117 * NAME
118 * osm_db_guid2lid_guids
119 *
120 * DESCRIPTION
121 * Provides back a list of guid elements.
122 *
123 * SYNOPSIS
124 */
125 int osm_db_guid2lid_guids(IN osm_db_domain_t * p_g2l,
126 OUT cl_qlist_t * p_guid_list);
127 /*
128 * PARAMETERS
129 * p_g2l
130 * [in] Pointer to the guid2lid domain
131 *
132 * p_guid_list
133 * [out] A quick list of guid elements of type osm_db_guid_elem_t
134 *
135 * RETURN VALUES
136 * 0 if successful
137 *
138 * NOTE: the output qlist should be initialized and each item freed
139 * by the caller, then destroyed.
140 *
141 * SEE ALSO
142 * osm_db_guid2lid_init, osm_db_guid2lid_guids, osm_db_guid2lid_get
143 * osm_db_guid2lid_set, osm_db_guid2lid_delete
144 *********/
145
146 /****f* OpenSM: DB-Pack/osm_db_guid2lid_get
147 * NAME
148 * osm_db_guid2lid_get
149 *
150 * DESCRIPTION
151 * Get a lid range by given guid.
152 *
153 * SYNOPSIS
154 */
155 int osm_db_guid2lid_get(IN osm_db_domain_t * p_g2l, IN uint64_t guid,
156 OUT uint16_t * p_min_lid, OUT uint16_t * p_max_lid);
157 /*
158 * PARAMETERS
159 * p_g2l
160 * [in] Pointer to the guid2lid domain
161 *
162 * guid
163 * [in] The guid to look for
164 *
165 * p_min_lid
166 * [out] Pointer to the resulting min lid in host order.
167 *
168 * p_max_lid
169 * [out] Pointer to the resulting max lid in host order.
170 *
171 * RETURN VALUES
172 * 0 if successful. The lid will be set to 0 if not found.
173 *
174 * SEE ALSO
175 * osm_db_guid2lid_init, osm_db_guid2lid_guids
176 * osm_db_guid2lid_set, osm_db_guid2lid_delete
177 *********/
178
179 /****f* OpenSM: DB-Pack/osm_db_guid2lid_set
180 * NAME
181 * osm_db_guid2lid_set
182 *
183 * DESCRIPTION
184 * Set a lid range for the given guid.
185 *
186 * SYNOPSIS
187 */
188 int osm_db_guid2lid_set(IN osm_db_domain_t * p_g2l, IN uint64_t guid,
189 IN uint16_t min_lid, IN uint16_t max_lid);
190 /*
191 * PARAMETERS
192 * p_g2l
193 * [in] Pointer to the guid2lid domain
194 *
195 * guid
196 * [in] The guid to look for
197 *
198 * min_lid
199 * [in] The min lid value to set
200 *
201 * max_lid
202 * [in] The max lid value to set
203 *
204 * RETURN VALUES
205 * 0 if successful
206 *
207 * SEE ALSO
208 * osm_db_guid2lid_init, osm_db_guid2lid_guids
209 * osm_db_guid2lid_get, osm_db_guid2lid_delete
210 *********/
211
212 /****f* OpenSM: DB-Pack/osm_db_guid2lid_delete
213 * NAME
214 * osm_db_guid2lid_delete
215 *
216 * DESCRIPTION
217 * Delete the entry by the given guid
218 *
219 * SYNOPSIS
220 */
221 int osm_db_guid2lid_delete(IN osm_db_domain_t * p_g2l, IN uint64_t guid);
222 /*
223 * PARAMETERS
224 * p_g2l
225 * [in] Pointer to the guid2lid domain
226 *
227 * guid
228 * [in] The guid to look for
229 *
230 * RETURN VALUES
231 * 0 if successful otherwise 1
232 *
233 * SEE ALSO
234 * osm_db_guid2lid_init, osm_db_guid2lid_guids
235 * osm_db_guid2lid_get, osm_db_guid2lid_set
236 *********/
237
238 /****f* OpenSM: DB-Pack/osm_db_guid2mkey_init
239 * NAME
240 * osm_db_guid2mkey_init
241 *
242 * DESCRIPTION
243 * Initialize a domain for the guid2mkey table
244 *
245 * SYNOPSIS
246 */
osm_db_guid2mkey_init(IN osm_db_t * p_db)247 static inline osm_db_domain_t *osm_db_guid2mkey_init(IN osm_db_t * p_db)
248 {
249 return osm_db_domain_init(p_db, "guid2mkey");
250 }
251
252 /*
253 * PARAMETERS
254 * p_db
255 * [in] Pointer to the database object to construct
256 *
257 * RETURN VALUES
258 * The pointer to the new allocated domain object or NULL.
259 *
260 * NOTE: DB domains are destroyed by the osm_db_destroy
261 *
262 * SEE ALSO
263 * Database, osm_db_init, osm_db_destroy
264 *********/
265
266 /****f* OpenSM: DB-Pack/osm_db_guid2mkey_guids
267 * NAME
268 * osm_db_guid2mkey_guids
269 *
270 * DESCRIPTION
271 * Provides back a list of guid elements.
272 *
273 * SYNOPSIS
274 */
275 int osm_db_guid2mkey_guids(IN osm_db_domain_t * p_g2m,
276 OUT cl_qlist_t * p_guid_list);
277 /*
278 * PARAMETERS
279 * p_g2l
280 * [in] Pointer to the guid2mkey domain
281 *
282 * p_guid_list
283 * [out] A quick list of guid elements of type osm_db_guid_elem_t
284 *
285 * RETURN VALUES
286 * 0 if successful
287 *
288 * NOTE: the output qlist should be initialized and each item freed
289 * by the caller, then destroyed.
290 *
291 * SEE ALSO
292 * osm_db_guid2mkey_init, osm_db_guid2mkey_guids, osm_db_guid2mkey_get
293 * osm_db_guid2mkey_set, osm_db_guid2mkey_delete
294 *********/
295
296 /****f* OpenSM: DB-Pack/osm_db_guid2mkey_get
297 * NAME
298 * osm_db_guid2mkey_get
299 *
300 * DESCRIPTION
301 * Get the mkey for the given guid.
302 *
303 * SYNOPSIS
304 */
305 int osm_db_guid2mkey_get(IN osm_db_domain_t * p_g2m, IN uint64_t guid,
306 OUT uint64_t * p_mkey);
307 /*
308 * PARAMETERS
309 * p_g2m
310 * [in] Pointer to the guid2mkey domain
311 *
312 * guid
313 * [in] The guid to look for
314 *
315 * p_mkey
316 * [out] Pointer to the resulting mkey in host order.
317 *
318 * RETURN VALUES
319 * 0 if successful. The lid will be set to 0 if not found.
320 *
321 * SEE ALSO
322 * osm_db_guid2mkey_init, osm_db_guid2mkey_guids
323 * osm_db_guid2mkey_set, osm_db_guid2mkey_delete
324 *********/
325
326 /****f* OpenSM: DB-Pack/osm_db_guid2mkey_set
327 * NAME
328 * osm_db_guid2mkey_set
329 *
330 * DESCRIPTION
331 * Set the mkey for the given guid.
332 *
333 * SYNOPSIS
334 */
335 int osm_db_guid2mkey_set(IN osm_db_domain_t * p_g2m, IN uint64_t guid,
336 IN uint64_t mkey);
337 /*
338 * PARAMETERS
339 * p_g2m
340 * [in] Pointer to the guid2mkey domain
341 *
342 * guid
343 * [in] The guid to look for
344 *
345 * mkey
346 * [in] The mkey value to set, in host order
347 *
348 * RETURN VALUES
349 * 0 if successful
350 *
351 * SEE ALSO
352 * osm_db_guid2mkey_init, osm_db_guid2mkey_guids
353 * osm_db_guid2mkey_get, osm_db_guid2mkey_delete
354 *********/
355
356 /****f* OpenSM: DB-Pack/osm_db_guid2mkey_delete
357 * NAME
358 * osm_db_guid2mkey_delete
359 *
360 * DESCRIPTION
361 * Delete the entry by the given guid
362 *
363 * SYNOPSIS
364 */
365 int osm_db_guid2mkey_delete(IN osm_db_domain_t * p_g2m, IN uint64_t guid);
366 /*
367 * PARAMETERS
368 * p_g2m
369 * [in] Pointer to the guid2mkey domain
370 *
371 * guid
372 * [in] The guid to look for
373 *
374 * RETURN VALUES
375 * 0 if successful otherwise 1
376 *
377 * SEE ALSO
378 * osm_db_guid2mkey_init, osm_db_guid2mkey_guids
379 * osm_db_guid2mkey_get, osm_db_guid2mkey_set
380 *********/
381
382 /****f* OpenSM: DB-Pack/osm_db_neighbor_init
383 * NAME
384 * osm_db_neighbor_init
385 *
386 * DESCRIPTION
387 * Initialize a domain for the neighbors table
388 *
389 * SYNOPSIS
390 */
osm_db_neighbor_init(IN osm_db_t * p_db)391 static inline osm_db_domain_t *osm_db_neighbor_init(IN osm_db_t * p_db)
392 {
393 return osm_db_domain_init(p_db, "neighbors");
394 }
395
396 /*
397 * PARAMETERS
398 * p_db
399 * [in] Pointer to the database object to construct
400 *
401 * RETURN VALUES
402 * The pointer to the new allocated domain object or NULL.
403 *
404 * NOTE: DB domains are destroyed by the osm_db_destroy
405 *
406 * SEE ALSO
407 * Database, osm_db_init, osm_db_destroy
408 *********/
409
410 /****f* OpenSM: DB-Pack/osm_db_neighbor_elem
411 * NAME
412 * osm_db_neighbor_elem
413 *
414 * DESCRIPTION
415 * Initialize a domain for the neighbor table
416 *
417 * SYNOPSIS
418 */
419 typedef struct osm_db_neighbor_elem {
420 cl_list_item_t item;
421 uint64_t guid;
422 uint8_t portnum;
423 } osm_db_neighbor_elem_t;
424 /*
425 * FIELDS
426 * item
427 * required for list manipulations
428 *
429 * guid
430 * portnum
431 *
432 ************/
433
434 /****f* OpenSM: DB-Pack/osm_db_neighbor_guids
435 * NAME
436 * osm_db_neighbor_guids
437 *
438 * DESCRIPTION
439 * Provides back a list of neighbor elements.
440 *
441 * SYNOPSIS
442 */
443 int osm_db_neighbor_guids(IN osm_db_domain_t * p_neighbor,
444 OUT cl_qlist_t * p_guid_list);
445 /*
446 * PARAMETERS
447 * p_neighbor
448 * [in] Pointer to the neighbor domain
449 *
450 * p_guid_list
451 * [out] A quick list of neighbor elements of type osm_db_neighbor_elem_t
452 *
453 * RETURN VALUES
454 * 0 if successful
455 *
456 * NOTE: the output qlist should be initialized and each item freed
457 * by the caller, then destroyed.
458 *
459 * SEE ALSO
460 * osm_db_neighbor_init, osm_db_neighbor_guids, osm_db_neighbor_get
461 * osm_db_neighbor_set, osm_db_neighbor_delete
462 *********/
463
464 /****f* OpenSM: DB-Pack/osm_db_neighbor_get
465 * NAME
466 * osm_db_neighbor_get
467 *
468 * DESCRIPTION
469 * Get a neighbor's guid by given guid/port.
470 *
471 * SYNOPSIS
472 */
473 int osm_db_neighbor_get(IN osm_db_domain_t * p_neighbor, IN uint64_t guid1,
474 IN uint8_t port1, OUT uint64_t * p_guid2,
475 OUT uint8_t * p_port2);
476 /*
477 * PARAMETERS
478 * p_neighbor
479 * [in] Pointer to the neighbor domain
480 *
481 * guid1
482 * [in] The guid to look for
483 *
484 * port1
485 * [in] The port to look for
486 *
487 * p_guid2
488 * [out] Pointer to the resulting guid of the neighboring port.
489 *
490 * p_port2
491 * [out] Pointer to the resulting port of the neighboring port.
492 *
493 * RETURN VALUES
494 * 0 if successful. The lid will be set to 0 if not found.
495 *
496 * SEE ALSO
497 * osm_db_neighbor_init, osm_db_neighbor_guids
498 * osm_db_neighbor_set, osm_db_neighbor_delete
499 *********/
500
501 /****f* OpenSM: DB-Pack/osm_db_neighbor_set
502 * NAME
503 * osm_db_neighbor_set
504 *
505 * DESCRIPTION
506 * Set up a relationship between two ports
507 *
508 * SYNOPSIS
509 */
510 int osm_db_neighbor_set(IN osm_db_domain_t * p_neighbor, IN uint64_t guid1,
511 IN uint8_t port1, IN uint64_t guid2, IN uint8_t port2);
512 /*
513 * PARAMETERS
514 * p_neighbor
515 * [in] Pointer to the neighbor domain
516 *
517 * guid1
518 * [in] The first guid in the relationship
519 *
520 * port1
521 * [in] The first port in the relationship
522 *
523 * guid2
524 * [in] The second guid in the relationship
525 *
526 * port2
527 * [in] The second port in the relationship
528 *
529 * RETURN VALUES
530 * 0 if successful
531 *
532 * SEE ALSO
533 * osm_db_neighbor_init, osm_db_neighbor_guids
534 * osm_db_neighbor_get, osm_db_neighbor_delete
535 *********/
536
537 /****f* OpenSM: DB-Pack/osm_db_neighbor_delete
538 * NAME
539 * osm_db_neighbor_delete
540 *
541 * DESCRIPTION
542 * Delete the relationship between two ports
543 *
544 * SYNOPSIS
545 */
546 int osm_db_neighbor_delete(IN osm_db_domain_t * p_neighbor,
547 IN uint64_t guid, IN uint8_t port);
548 /*
549 * PARAMETERS
550 * p_neighbor
551 * [in] Pointer to the neighbor domain
552 *
553 * guid
554 * [in] The guid to look for
555 *
556 * port
557 * [in] The port to look for
558 *
559 * RETURN VALUES
560 * 0 if successful otherwise 1
561 *
562 * SEE ALSO
563 * osm_db_neighbor_init, osm_db_neighbor_guids
564 * osm_db_neighbor_get, osm_db_neighbor_set
565 *********/
566
567 END_C_DECLS
568 #endif /* _OSM_DB_PACK_H_ */
569