1219820Sjeff/*
2219820Sjeff * Copyright (c) 2004-2006 Voltaire, Inc. All rights reserved.
3219820Sjeff * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
4219820Sjeff * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5219820Sjeff *
6219820Sjeff * This software is available to you under a choice of one of two
7219820Sjeff * licenses.  You may choose to be licensed under the terms of the GNU
8219820Sjeff * General Public License (GPL) Version 2, available from the file
9219820Sjeff * COPYING in the main directory of this source tree, or the
10219820Sjeff * OpenIB.org BSD license below:
11219820Sjeff *
12219820Sjeff *     Redistribution and use in source and binary forms, with or
13219820Sjeff *     without modification, are permitted provided that the following
14219820Sjeff *     conditions are met:
15219820Sjeff *
16219820Sjeff *      - Redistributions of source code must retain the above
17219820Sjeff *        copyright notice, this list of conditions and the following
18219820Sjeff *        disclaimer.
19219820Sjeff *
20219820Sjeff *      - Redistributions in binary form must reproduce the above
21219820Sjeff *        copyright notice, this list of conditions and the following
22219820Sjeff *        disclaimer in the documentation and/or other materials
23219820Sjeff *        provided with the distribution.
24219820Sjeff *
25219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32219820Sjeff * SOFTWARE.
33219820Sjeff *
34219820Sjeff */
35219820Sjeff
36219820Sjeff/*
37219820Sjeff * Abstract:
38219820Sjeff * 	Declaration of osm_mtree_t.
39219820Sjeff *	This object represents multicast spanning tree.
40219820Sjeff *	This object is part of the OpenSM family of objects.
41219820Sjeff */
42219820Sjeff
43219820Sjeff#ifndef _OSM_MTREE_H_
44219820Sjeff#define _OSM_MTREE_H_
45219820Sjeff
46219820Sjeff#include <iba/ib_types.h>
47219820Sjeff#include <complib/cl_qmap.h>
48219820Sjeff#include <opensm/osm_base.h>
49219820Sjeff#include <opensm/osm_switch.h>
50219820Sjeff
51219820Sjeff#ifdef __cplusplus
52219820Sjeff#  define BEGIN_C_DECLS extern "C" {
53219820Sjeff#  define END_C_DECLS   }
54219820Sjeff#else				/* !__cplusplus */
55219820Sjeff#  define BEGIN_C_DECLS
56219820Sjeff#  define END_C_DECLS
57219820Sjeff#endif				/* __cplusplus */
58219820Sjeff
59219820SjeffBEGIN_C_DECLS
60219820Sjeff#define OSM_MTREE_LEAF ((void*)-1)
61219820Sjeff/****h* OpenSM/Multicast Tree
62219820Sjeff* NAME
63219820Sjeff*	Multicast Tree
64219820Sjeff*
65219820Sjeff* DESCRIPTION
66219820Sjeff*	The Multicast Tree object encapsulates the information needed by the
67219820Sjeff*	OpenSM to manage multicast fabric routes.  It is a tree structure
68219820Sjeff*	in which each node in the tree represents a switch, and may have a
69219820Sjeff*	varying number of children.
70219820Sjeff*
71219820Sjeff*	Multicast trees do not contain loops.
72219820Sjeff*
73219820Sjeff*	The Multicast Tree is not thread safe, thus callers must provide
74219820Sjeff*	serialization.
75219820Sjeff*
76219820Sjeff*	This object should be treated as opaque and should be
77219820Sjeff*	manipulated only through the provided functions.
78219820Sjeff*
79219820Sjeff* AUTHOR
80219820Sjeff*	Steve King, Intel
81219820Sjeff*
82219820Sjeff*********/
83219820Sjeff/****s* OpenSM: Multicast Tree/osm_mtree_node_t
84219820Sjeff* NAME
85219820Sjeff*	osm_mtree_node_t
86219820Sjeff*
87219820Sjeff* DESCRIPTION
88219820Sjeff*	The MTree Node object encapsulates the information needed by the
89219820Sjeff*	OpenSM for a particular switch in the multicast tree.
90219820Sjeff*
91219820Sjeff*	The MTree Node object is not thread safe, thus callers must provide
92219820Sjeff*	serialization.
93219820Sjeff*
94219820Sjeff*	This object should be treated as opaque and should be
95219820Sjeff*	manipulated only through the provided functions.
96219820Sjeff*
97219820Sjeff* SYNOPSIS
98219820Sjeff*/
99219820Sjefftypedef struct osm_mtree_node {
100219820Sjeff	cl_map_item_t map_item;
101219820Sjeff	osm_switch_t *p_sw;
102219820Sjeff	uint8_t max_children;
103219820Sjeff	struct osm_mtree_node *p_up;
104219820Sjeff	struct osm_mtree_node *child_array[1];
105219820Sjeff} osm_mtree_node_t;
106219820Sjeff/*
107219820Sjeff* FIELDS
108219820Sjeff*	map_item
109219820Sjeff*		Linkage for quick map.  MUST BE FIRST ELEMENT!!!
110219820Sjeff*
111219820Sjeff*	p_sw
112219820Sjeff*		Pointer to the switch represented by this tree node.
113219820Sjeff*
114219820Sjeff*	max_children
115219820Sjeff*		Maximum number of child nodes of this node.  Equal to the
116219820Sjeff*		the number of ports on the switch if the switch supports
117219820Sjeff*		multicast.  Equal to 1 (default route) if the switch does
118219820Sjeff*		not support multicast.
119219820Sjeff*
120219820Sjeff*	p_up
121219820Sjeff*		Pointer to the parent of this node.  If this pointer is
122219820Sjeff*		NULL, the node is at the root of the tree.
123219820Sjeff*
124219820Sjeff*	child_array
125219820Sjeff*		Array (indexed by port number) of pointers to the
126219820Sjeff*		child osm_mtree_node_t objects of this tree node, if any.
127219820Sjeff*
128219820Sjeff* SEE ALSO
129219820Sjeff*********/
130219820Sjeff
131219820Sjeff/****f* OpenSM: Multicast Tree/osm_mtree_node_new
132219820Sjeff* NAME
133219820Sjeff*	osm_mtree_node_new
134219820Sjeff*
135219820Sjeff* DESCRIPTION
136219820Sjeff*	Returns an initialized a Multicast Tree object for use.
137219820Sjeff*
138219820Sjeff* SYNOPSIS
139219820Sjeff*/
140219820Sjeffosm_mtree_node_t *osm_mtree_node_new(IN const osm_switch_t * const p_sw);
141219820Sjeff/*
142219820Sjeff* PARAMETERS
143219820Sjeff*	p_sw
144219820Sjeff*		[in] Pointer to the switch represented by this node.
145219820Sjeff*
146219820Sjeff* RETURN VALUES
147219820Sjeff*	Pointer to an initialized tree node.
148219820Sjeff*
149219820Sjeff* NOTES
150219820Sjeff*
151219820Sjeff* SEE ALSO
152219820Sjeff*********/
153219820Sjeff
154219820Sjeff/****f* OpenSM: Multicast Tree/osm_mtree_destroy
155219820Sjeff* NAME
156219820Sjeff*	osm_mtree_destroy
157219820Sjeff*
158219820Sjeff* DESCRIPTION
159219820Sjeff*	Destroys a Multicast Tree object given by the p_mtn
160219820Sjeff*
161219820Sjeff* SYNOPSIS
162219820Sjeff*/
163219820Sjeffvoid osm_mtree_destroy(IN osm_mtree_node_t * p_mtn);
164219820Sjeff/*
165219820Sjeff* PARAMETERS
166219820Sjeff*	p_mtn
167219820Sjeff*		[in] Pointer to an osm_mtree_node_t object to destroy.
168219820Sjeff*
169219820Sjeff* RETURN VALUES
170219820Sjeff*	None.
171219820Sjeff*
172219820Sjeff* NOTES
173219820Sjeff*
174219820Sjeff* SEE ALSO
175219820Sjeff*********/
176219820Sjeff
177219820Sjeff/****f* OpenSM: Multicast Tree/osm_mtree_node_get_max_children
178219820Sjeff* NAME
179219820Sjeff*	osm_mtree_node_get_max_children
180219820Sjeff*
181219820Sjeff* DESCRIPTION
182219820Sjeff*	Returns the number maximum number of children of this node.
183219820Sjeff*	The return value is 1 greater than the highest valid port
184219820Sjeff*	number on the switch.
185219820Sjeff*
186219820Sjeff*
187219820Sjeff* SYNOPSIS
188219820Sjeff*/
189219820Sjeffstatic inline uint8_t
190219820Sjeffosm_mtree_node_get_max_children(IN const osm_mtree_node_t * const p_mtn)
191219820Sjeff{
192219820Sjeff	return (p_mtn->max_children);
193219820Sjeff}
194219820Sjeff/*
195219820Sjeff* PARAMETERS
196219820Sjeff*	p_mtn
197219820Sjeff*		[in] Pointer to the multicast tree node.
198219820Sjeff*
199219820Sjeff* RETURN VALUES
200219820Sjeff*	See description.
201219820Sjeff*
202219820Sjeff* NOTES
203219820Sjeff*
204219820Sjeff* SEE ALSO
205219820Sjeff*********/
206219820Sjeff
207219820Sjeff/****f* OpenSM: Multicast Tree/osm_mtree_node_get_child
208219820Sjeff* NAME
209219820Sjeff*	osm_mtree_node_get_child
210219820Sjeff*
211219820Sjeff* DESCRIPTION
212219820Sjeff*	Returns the specified child node of this node.
213219820Sjeff*
214219820Sjeff* SYNOPSIS
215219820Sjeff*/
216219820Sjeffstatic inline osm_mtree_node_t *osm_mtree_node_get_child(IN const
217219820Sjeff							 osm_mtree_node_t *
218219820Sjeff							 const p_mtn,
219219820Sjeff							 IN const uint8_t child)
220219820Sjeff{
221219820Sjeff	CL_ASSERT(child < p_mtn->max_children);
222219820Sjeff	return (p_mtn->child_array[child]);
223219820Sjeff}
224219820Sjeff/*
225219820Sjeff* PARAMETERS
226219820Sjeff*	p_mtn
227219820Sjeff*		[in] Pointer to the multicast tree node.
228219820Sjeff*
229219820Sjeff*	child
230219820Sjeff*		[in] Index of the child to retrieve.
231219820Sjeff*
232219820Sjeff* RETURN VALUES
233219820Sjeff*	Returns the specified child node of this node.
234219820Sjeff*
235219820Sjeff*
236219820Sjeff* NOTES
237219820Sjeff*
238219820Sjeff* SEE ALSO
239219820Sjeff*********/
240219820Sjeff
241219820Sjeff/****f* OpenSM: Multicast Tree/osm_mtree_node_get_switch_ptr
242219820Sjeff* NAME
243219820Sjeff*	osm_mtree_node_get_switch_ptr
244219820Sjeff*
245219820Sjeff* DESCRIPTION
246219820Sjeff*	Returns a pointer to the switch object represented by this tree node.
247219820Sjeff*
248219820Sjeff* SYNOPSIS
249219820Sjeff*/
250219820Sjeffstatic inline osm_switch_t *osm_mtree_node_get_switch_ptr(IN const
251219820Sjeff							  osm_mtree_node_t *
252219820Sjeff							  const p_mtn)
253219820Sjeff{
254219820Sjeff	return (p_mtn->p_sw);
255219820Sjeff}
256219820Sjeff/*
257219820Sjeff* PARAMETERS
258219820Sjeff*	p_mtn
259219820Sjeff*		[in] Pointer to the multicast tree node.
260219820Sjeff*
261219820Sjeff*	child
262219820Sjeff*		[in] Index of the child to retrieve.
263219820Sjeff*
264219820Sjeff* RETURN VALUES
265219820Sjeff*	Returns a pointer to the switch object represented by this tree node.
266219820Sjeff*
267219820Sjeff*
268219820Sjeff* NOTES
269219820Sjeff*
270219820Sjeff* SEE ALSO
271219820Sjeff*********/
272219820Sjeff
273219820SjeffEND_C_DECLS
274219820Sjeff#endif				/* _OSM_MTREE_H_ */
275