2 * Copyright (c) 2004-2008 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.
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 * Declaration of osm_node_t.
39 * This object represents an IBA node.
40 * This object is part of the OpenSM family of objects.
46 #include <complib/cl_qmap.h>
47 #include <iba/ib_types.h>
48 #include <opensm/osm_base.h>
49 #include <opensm/osm_port.h>
50 #include <opensm/osm_path.h>
51 #include <opensm/osm_madw.h>
54 # define BEGIN_C_DECLS extern "C" {
55 # define END_C_DECLS }
56 #else /* !__cplusplus */
57 # define BEGIN_C_DECLS
59 #endif /* __cplusplus */
70 * The Node object encapsulates the information needed by the
71 * OpenSM to manage nodes. The OpenSM allocates one Node object
72 * per node in the IBA subnet.
74 * The Node object is not thread safe, thus callers must provide
77 * This object should be treated as opaque and should be
78 * manipulated only through the provided functions.
85 /****s* OpenSM: Node/osm_node_t
92 * This object should be treated as opaque and should
93 * be manipulated only through the provided functions.
97 typedef struct osm_node {
98 cl_map_item_t map_item;
99 struct osm_switch *sw;
100 ib_node_info_t node_info;
101 ib_node_desc_t node_desc;
102 uint32_t discovery_count;
103 uint32_t physp_tbl_size;
105 osm_physp_t physp_table[1];
110 * Linkage structure for cl_qmap. MUST BE FIRST MEMBER!
113 * For switch node contains pointer to appropriate osm_switch
114 * structure. NULL for non-switch nodes. Can be used for fast
115 * access to switch object and for simple node type detection
118 * The IBA defined NodeInfo data for this node.
121 * The IBA defined NodeDescription data for this node.
124 * The number of times this node has been discovered
125 * during the current fabric sweep. This number is reset
126 * to zero at the start of a sweep.
129 * The size of the physp_table array. This value is one greater
130 * than the number of ports in the node, since port numbers
131 * start with 1 for some bizzare reason.
134 * A printable version of the node description.
137 * Array of physical port objects belonging to this node.
138 * Index is contiguous by local port number.
139 * For switches, port 0 is the always the management port (14.2.5.6).
140 * MUST BE LAST MEMBER! - Since it grows !!!!
146 /****f* OpenSM: Node/osm_node_delete
151 * The osm_node_delete function destroys a node, releasing
156 void osm_node_delete(IN OUT osm_node_t ** const p_node);
160 * [in][out] Pointer to a Pointer a Node object to destroy.
161 * On return, the pointer to set to NULL.
164 * This function does not return a value.
167 * Performs any necessary cleanup of the specified Node object.
168 * This function should only be called after a call to osm_node_new.
171 * Node object, osm_node_new
174 /****f* OpenSM: Node/osm_node_new
179 * The osm_node_new function initializes a Node object for use.
183 osm_node_t *osm_node_new(IN const osm_madw_t * const p_madw);
187 * [in] Pointer to a osm_madw_t object containing a mad with
188 * the node's NodeInfo attribute. The caller may discard the
189 * osm_madw_t structure after calling osm_node_new.
192 * On success, a pointer to the new initialized osm_node_t structure.
201 /****f* OpenSM: Node/osm_node_get_physp_ptr
203 * osm_node_get_physp_ptr
206 * Returns a pointer to the physical port object at the
207 * specified local port number.
211 static inline osm_physp_t *osm_node_get_physp_ptr(IN osm_node_t * const p_node,
212 IN const uint32_t port_num)
215 CL_ASSERT(port_num < p_node->physp_tbl_size);
216 return osm_physp_is_valid(&p_node->physp_table[port_num]) ?
217 &p_node->physp_table[port_num] : NULL;
223 * [in] Pointer to an osm_node_t object.
226 * [in] Local port number.
229 * Returns a pointer to the physical port object at the
230 * specified local port number.
231 * A return value of zero means the port number was out of range.
239 /****f* OpenSM: Node/osm_node_get_type
244 * Returns the type of this node.
248 static inline uint8_t osm_node_get_type(IN const osm_node_t * const p_node)
250 return (p_node->node_info.node_type);
256 * [in] Pointer to an osm_node_t object.
259 * Returns the IBA defined type of this node.
267 /****f* OpenSM: Node/osm_node_get_num_physp
269 * osm_node_get_num_physp
272 * Returns the type of this node.
276 static inline uint8_t osm_node_get_num_physp(IN const osm_node_t * const p_node)
278 return ((uint8_t) p_node->physp_tbl_size);
284 * [in] Pointer to an osm_node_t object.
287 * Returns the IBA defined type of this node.
295 /****f* OpenSM: Node/osm_node_get_remote_node
297 * osm_node_get_remote_node
300 * Returns a pointer to the node on the other end of the
302 * Returns NULL if no remote node exists.
306 osm_node_t *osm_node_get_remote_node(IN osm_node_t * const p_node,
307 IN const uint8_t port_num,
308 OUT uint8_t * p_remote_port_num);
312 * [in] Pointer to an osm_node_t object.
315 * [in] Port number in p_node through which to get the remote node.
318 * [out] Port number in the remote's node through which this
319 * link exists. The caller may specify NULL for this pointer
320 * if the port number isn't needed.
323 * Returns a pointer to the node on the other end of the
325 * Returns NULL if no remote node exists.
333 /****f* OpenSM: Node/osm_node_get_base_lid
335 * osm_node_get_base_lid
338 * Returns the LID value of the specified port on this node.
342 static inline ib_net16_t
343 osm_node_get_base_lid(IN const osm_node_t * const p_node,
344 IN const uint32_t port_num)
346 CL_ASSERT(port_num < p_node->physp_tbl_size);
347 return (osm_physp_get_base_lid(&p_node->physp_table[port_num]));
353 * [in] Pointer to an osm_node_t object.
356 * [in] Local port number.
359 * Returns a pointer to the physical port object at the
360 * specified local port number.
361 * A return value of zero means the port number was out of range.
369 /****f* OpenSM: Node/osm_node_get_remote_base_lid
371 * osm_node_get_remote_base_lid
374 * Returns the base LID value of the port on the other side
375 * of the wire from the specified port on this node.
380 osm_node_get_remote_base_lid(IN osm_node_t * const p_node,
381 IN const uint32_t port_num);
385 * [in] Pointer to an osm_node_t object.
388 * [in] Local port number.
391 * Returns a pointer to the physical port object at the
392 * specified local port number.
393 * A return value of zero means the port number was out of range.
401 /****f* OpenSM: Node/osm_node_get_lmc
406 * Returns the LMC value of the specified port on this node.
410 static inline uint8_t
411 osm_node_get_lmc(IN const osm_node_t * const p_node, IN const uint32_t port_num)
413 CL_ASSERT(port_num < p_node->physp_tbl_size);
414 return (osm_physp_get_lmc(&p_node->physp_table[port_num]));
420 * [in] Pointer to an osm_node_t object.
423 * [in] Local port number.
426 * Returns the LMC value of the specified port on this node.
434 /****f* OpenSM: Node/osm_node_init_physp
436 * osm_node_init_physp
439 * Initializes a physical port for the given node.
444 osm_node_init_physp(IN osm_node_t * const p_node,
445 IN const osm_madw_t * const p_madw);
449 * [in] Pointer to an osm_node_t object.
452 * [in] Pointer to a osm_madw_t object containing a mad with
453 * the node's NodeInfo attribute as discovered through the
454 * Physical Port to add to the node. The caller may discard the
455 * osm_madw_t structure after calling osm_node_new.
463 * Node object, Physical Port object.
466 /****f* OpenSM: Node/osm_node_get_node_guid
468 * osm_node_get_node_guid
471 * Returns the node GUID of this node.
475 static inline ib_net64_t
476 osm_node_get_node_guid(IN const osm_node_t * const p_node)
478 return (p_node->node_info.node_guid);
484 * [in] Pointer to an osm_node_t object.
487 * Returns the node GUID of this node.
495 /****f* OpenSM: Node/osm_node_link
500 * Logically connects a node to another node through the specified port.
505 osm_node_link(IN osm_node_t * const p_node,
506 IN const uint8_t port_num,
507 IN osm_node_t * const p_remote_node,
508 IN const uint8_t remote_port_num);
512 * [in] Pointer to an osm_node_t object.
515 * [in] Port number in p_node through which to create the link.
518 * [in] Pointer to the remote port object.
521 * [in] Port number in the remote's node through which to
533 /****f* OpenSM: Node/osm_node_unlink
538 * Logically disconnects a node from another node through
539 * the specified port.
544 osm_node_unlink(IN osm_node_t * const p_node,
545 IN const uint8_t port_num,
546 IN osm_node_t * const p_remote_node,
547 IN const uint8_t remote_port_num);
551 * [in] Pointer to an osm_node_t object.
554 * [in] Port number in p_node through which to unlink.
557 * [in] Pointer to the remote port object.
560 * [in] Port number in the remote's node through which to unlink.
571 /****f* OpenSM: Node/osm_node_link_exists
573 * osm_node_link_exists
576 * Return TRUE if a link exists between the specified nodes on
577 * the specified ports.
578 * Returns FALSE otherwise.
583 osm_node_link_exists(IN osm_node_t * const p_node,
584 IN const uint8_t port_num,
585 IN osm_node_t * const p_remote_node,
586 IN const uint8_t remote_port_num);
590 * [in] Pointer to an osm_node_t object.
593 * [in] Port number in p_node through which to check the link.
596 * [in] Pointer to the remote port object.
599 * [in] Port number in the remote's node through which to
603 * Return TRUE if a link exists between the specified nodes on
604 * the specified ports.
605 * Returns FALSE otherwise.
613 /****f* OpenSM: Node/osm_node_has_any_link
615 * osm_node_has_any_link
618 * Return TRUE if a any link exists from the specified nodes on
619 * the specified port.
620 * Returns FALSE otherwise.
625 osm_node_has_any_link(IN osm_node_t * const p_node, IN const uint8_t port_num);
629 * [in] Pointer to an osm_node_t object.
632 * [in] Port number in p_node through which to check the link.
635 * Return TRUE if a any link exists from the specified nodes on
636 * the specified port.
637 * Returns FALSE otherwise.
645 /****f* OpenSM: Node/osm_node_link_has_valid_ports
647 * osm_node_link_has_valid_ports
650 * Return TRUE if both ports in the link are valid (initialized).
651 * Returns FALSE otherwise.
656 osm_node_link_has_valid_ports(IN osm_node_t * const p_node,
657 IN const uint8_t port_num,
658 IN osm_node_t * const p_remote_node,
659 IN const uint8_t remote_port_num);
663 * [in] Pointer to an osm_node_t object.
666 * [in] Port number in p_node through which to check the link.
669 * Return TRUE if both ports in the link are valid (initialized).
670 * Returns FALSE otherwise.
679 #endif /* _OSM_NODE_H_ */