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#ifndef _OSM_PATH_H_
37219820Sjeff#define _OSM_PATH_H_
38219820Sjeff
39219820Sjeff#include <string.h>
40219820Sjeff#include <opensm/osm_base.h>
41219820Sjeff#include <vendor/osm_vendor_api.h>
42219820Sjeff
43219820Sjeff#ifdef __cplusplus
44219820Sjeff#  define BEGIN_C_DECLS extern "C" {
45219820Sjeff#  define END_C_DECLS   }
46219820Sjeff#else				/* !__cplusplus */
47219820Sjeff#  define BEGIN_C_DECLS
48219820Sjeff#  define END_C_DECLS
49219820Sjeff#endif				/* __cplusplus */
50219820Sjeff
51219820SjeffBEGIN_C_DECLS
52219820Sjeff/*
53219820Sjeff * Abstract:
54219820Sjeff * 	Declaration of path related objects.
55219820Sjeff *	These objects are part of the OpenSM family of objects.
56219820Sjeff */
57219820Sjeff/****h* OpenSM/DR Path
58219820Sjeff* NAME
59219820Sjeff*	DR Path
60219820Sjeff*
61219820Sjeff* DESCRIPTION
62219820Sjeff*	The DR Path structure encapsulates a directed route through the subnet.
63219820Sjeff*
64219820Sjeff*	This structure allows direct access to member variables.
65219820Sjeff*
66219820Sjeff* AUTHOR
67219820Sjeff*	Steve King, Intel
68219820Sjeff*
69219820Sjeff*********/
70219820Sjeff/****s* OpenSM: DR Path/osm_dr_path_t
71219820Sjeff* NAME
72219820Sjeff*	osm_dr_path_t
73219820Sjeff*
74219820Sjeff* DESCRIPTION
75219820Sjeff*	Directed Route structure.
76219820Sjeff*
77219820Sjeff*	This structure allows direct access to member variables.
78219820Sjeff*
79219820Sjeff* SYNOPSIS
80219820Sjeff*/
81219820Sjefftypedef struct osm_dr_path {
82219820Sjeff	osm_bind_handle_t h_bind;
83219820Sjeff	uint8_t hop_count;
84219820Sjeff	uint8_t path[IB_SUBNET_PATH_HOPS_MAX];
85219820Sjeff} osm_dr_path_t;
86219820Sjeff/*
87219820Sjeff* FIELDS
88219820Sjeff*	h_bind
89219820Sjeff*		Bind handle for port to which this path applies.
90219820Sjeff*
91219820Sjeff*	hop_count
92219820Sjeff*		The number of hops in this path.
93219820Sjeff*
94219820Sjeff*	path
95219820Sjeff*		The array of port numbers that comprise this path.
96219820Sjeff*
97219820Sjeff* SEE ALSO
98219820Sjeff*	DR Path structure
99219820Sjeff*********/
100219820Sjeff/****f* OpenSM: DR Path/osm_dr_path_construct
101219820Sjeff* NAME
102219820Sjeff*	osm_dr_path_construct
103219820Sjeff*
104219820Sjeff* DESCRIPTION
105219820Sjeff*	This function constructs a directed route path object.
106219820Sjeff*
107219820Sjeff* SYNOPSIS
108219820Sjeff*/
109219820Sjeffstatic inline void osm_dr_path_construct(IN osm_dr_path_t * const p_path)
110219820Sjeff{
111219820Sjeff	/* The first location in the path array is reserved. */
112219820Sjeff	memset(p_path, 0, sizeof(*p_path));
113219820Sjeff	p_path->h_bind = OSM_BIND_INVALID_HANDLE;
114219820Sjeff}
115219820Sjeff
116219820Sjeff/*
117219820Sjeff* PARAMETERS
118219820Sjeff*	p_path
119219820Sjeff*		[in] Pointer to a directed route path object to initialize.
120219820Sjeff*
121219820Sjeff*	h_bind
122219820Sjeff*		[in] Bind handle for the port on which this path applies.
123219820Sjeff*
124219820Sjeff*	hop_count
125219820Sjeff*		[in] Hop count needed to reach this node.
126219820Sjeff*
127219820Sjeff*	path
128219820Sjeff*		[in] Directed route path to reach this node.
129219820Sjeff*
130219820Sjeff* RETURN VALUE
131219820Sjeff*	None.
132219820Sjeff*
133219820Sjeff* NOTES
134219820Sjeff*
135219820Sjeff* SEE ALSO
136219820Sjeff*********/
137219820Sjeff
138219820Sjeff/****f* OpenSM: DR Path/osm_dr_path_init
139219820Sjeff* NAME
140219820Sjeff*	osm_dr_path_init
141219820Sjeff*
142219820Sjeff* DESCRIPTION
143219820Sjeff*	This function initializes a directed route path object.
144219820Sjeff*
145219820Sjeff* SYNOPSIS
146219820Sjeff*/
147219820Sjeffstatic inline void
148219820Sjeffosm_dr_path_init(IN osm_dr_path_t * const p_path,
149219820Sjeff		 IN const osm_bind_handle_t h_bind,
150219820Sjeff		 IN const uint8_t hop_count,
151219820Sjeff		 IN const uint8_t path[IB_SUBNET_PATH_HOPS_MAX])
152219820Sjeff{
153219820Sjeff	/* The first location in the path array is reserved. */
154219820Sjeff	CL_ASSERT(path[0] == 0);
155219820Sjeff	CL_ASSERT(hop_count < IB_SUBNET_PATH_HOPS_MAX);
156219820Sjeff	p_path->h_bind = h_bind;
157219820Sjeff	p_path->hop_count = hop_count;
158219820Sjeff	memcpy(p_path->path, path, IB_SUBNET_PATH_HOPS_MAX);
159219820Sjeff}
160219820Sjeff
161219820Sjeff/*
162219820Sjeff* PARAMETERS
163219820Sjeff*	p_path
164219820Sjeff*		[in] Pointer to a directed route path object to initialize.
165219820Sjeff*
166219820Sjeff*	h_bind
167219820Sjeff*		[in] Bind handle for the port on which this path applies.
168219820Sjeff*
169219820Sjeff*	hop_count
170219820Sjeff*		[in] Hop count needed to reach this node.
171219820Sjeff*
172219820Sjeff*	path
173219820Sjeff*		[in] Directed route path to reach this node.
174219820Sjeff*
175219820Sjeff* RETURN VALUE
176219820Sjeff*	None.
177219820Sjeff*
178219820Sjeff* NOTES
179219820Sjeff*
180219820Sjeff* SEE ALSO
181219820Sjeff*********/
182219820Sjeff/****f* OpenSM: DR Path/osm_dr_path_extend
183219820Sjeff* NAME
184219820Sjeff*	osm_dr_path_extend
185219820Sjeff*
186219820Sjeff* DESCRIPTION
187219820Sjeff*	Adds a new hop to a path.
188219820Sjeff*
189219820Sjeff* SYNOPSIS
190219820Sjeff*/
191219820Sjeffstatic inline void
192219820Sjeffosm_dr_path_extend(IN osm_dr_path_t * const p_path, IN const uint8_t port_num)
193219820Sjeff{
194219820Sjeff	p_path->hop_count++;
195219820Sjeff	CL_ASSERT(p_path->hop_count < IB_SUBNET_PATH_HOPS_MAX);
196219820Sjeff	/*
197219820Sjeff	   Location 0 in the path array is reserved per IB spec.
198219820Sjeff	 */
199219820Sjeff	p_path->path[p_path->hop_count] = port_num;
200219820Sjeff}
201219820Sjeff
202219820Sjeff/*
203219820Sjeff* PARAMETERS
204219820Sjeff*	p_path
205219820Sjeff*		[in] Pointer to a directed route path object to initialize.
206219820Sjeff*
207219820Sjeff*	port_num
208219820Sjeff*		[in] Additional port to add to the DR path.
209219820Sjeff*
210219820Sjeff* RETURN VALUE
211219820Sjeff*	None.
212219820Sjeff*
213219820Sjeff* NOTES
214219820Sjeff*
215219820Sjeff* SEE ALSO
216219820Sjeff*********/
217219820Sjeff
218219820Sjeff/****f* OpenSM: DR Path/osm_dr_path_get_bind_handle
219219820Sjeff* NAME
220219820Sjeff*	osm_dr_path_get_bind_handle
221219820Sjeff*
222219820Sjeff* DESCRIPTION
223219820Sjeff*	Gets the bind handle from a path.
224219820Sjeff*
225219820Sjeff* SYNOPSIS
226219820Sjeff*/
227219820Sjeffstatic inline osm_bind_handle_t
228219820Sjeffosm_dr_path_get_bind_handle(IN const osm_dr_path_t * const p_path)
229219820Sjeff{
230219820Sjeff	return (p_path->h_bind);
231219820Sjeff}
232219820Sjeff
233219820Sjeff/*
234219820Sjeff* PARAMETERS
235219820Sjeff*	p_path
236219820Sjeff*		[in] Pointer to a directed route path object to initialize.
237219820Sjeff*
238219820Sjeff*	port_num
239219820Sjeff*		[in] Additional port to add to the DR path.
240219820Sjeff*
241219820Sjeff* RETURN VALUE
242219820Sjeff*	None.
243219820Sjeff*
244219820Sjeff* NOTES
245219820Sjeff*
246219820Sjeff* SEE ALSO
247219820Sjeff*********/
248219820Sjeff
249219820SjeffEND_C_DECLS
250219820Sjeff#endif				/* _OSM_PATH_H_ */
251