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  * Copyright (c) 2009 HNR Consulting. All rights reserved.
6  *
7  * This software is available to you under a choice of one of two
8  * licenses.  You may choose to be licensed under the terms of the GNU
9  * General Public License (GPL) Version 2, available from the file
10  * COPYING in the main directory of this source tree, or the
11  * OpenIB.org BSD license below:
12  *
13  *     Redistribution and use in source and binary forms, with or
14  *     without modification, are permitted provided that the following
15  *     conditions are met:
16  *
17  *      - Redistributions of source code must retain the above
18  *        copyright notice, this list of conditions and the following
19  *        disclaimer.
20  *
21  *      - Redistributions in binary form must reproduce the above
22  *        copyright notice, this list of conditions and the following
23  *        disclaimer in the documentation and/or other materials
24  *        provided with the distribution.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33  * SOFTWARE.
34  *
35  */
36 
37 #ifndef _OSM_PATH_H_
38 #define _OSM_PATH_H_
39 
40 #include <string.h>
41 #include <opensm/osm_base.h>
42 #include <vendor/osm_vendor_api.h>
43 
44 #ifdef __cplusplus
45 #  define BEGIN_C_DECLS extern "C" {
46 #  define END_C_DECLS   }
47 #else				/* !__cplusplus */
48 #  define BEGIN_C_DECLS
49 #  define END_C_DECLS
50 #endif				/* __cplusplus */
51 
52 BEGIN_C_DECLS
53 /*
54  * Abstract:
55  * 	Declaration of path related objects.
56  *	These objects are part of the OpenSM family of objects.
57  */
58 /****h* OpenSM/DR Path
59 * NAME
60 *	DR Path
61 *
62 * DESCRIPTION
63 *	The DR Path structure encapsulates a directed route through the subnet.
64 *
65 *	This structure allows direct access to member variables.
66 *
67 * AUTHOR
68 *	Steve King, Intel
69 *
70 *********/
71 /****s* OpenSM: DR Path/osm_dr_path_t
72 * NAME
73 *	osm_dr_path_t
74 *
75 * DESCRIPTION
76 *	Directed Route structure.
77 *
78 *	This structure allows direct access to member variables.
79 *
80 * SYNOPSIS
81 */
82 typedef struct osm_dr_path {
83 	uint8_t hop_count;
84 	uint8_t path[IB_SUBNET_PATH_HOPS_MAX];
85 } osm_dr_path_t;
86 /*
87 * FIELDS
88 *	h_bind
89 *		Bind handle for port to which this path applies.
90 *
91 *	hop_count
92 *		The number of hops in this path.
93 *
94 *	path
95 *		The array of port numbers that comprise this path.
96 *
97 * SEE ALSO
98 *	DR Path structure
99 *********/
100 /****f* OpenSM: DR Path/osm_dr_path_construct
101 * NAME
102 *	osm_dr_path_construct
103 *
104 * DESCRIPTION
105 *	This function constructs a directed route path object.
106 *
107 * SYNOPSIS
108 */
osm_dr_path_construct(IN osm_dr_path_t * p_path)109 static inline void osm_dr_path_construct(IN osm_dr_path_t * p_path)
110 {
111 	/* The first location in the path array is reserved. */
112 	memset(p_path, 0, sizeof(*p_path));
113 }
114 
115 /*
116 * PARAMETERS
117 *	p_path
118 *		[in] Pointer to a directed route path object to initialize.
119 *
120 *	h_bind
121 *		[in] Bind handle for the port on which this path applies.
122 *
123 *	hop_count
124 *		[in] Hop count needed to reach this node.
125 *
126 *	path
127 *		[in] Directed route path to reach this node.
128 *
129 * RETURN VALUE
130 *	None.
131 *
132 * NOTES
133 *
134 * SEE ALSO
135 *********/
136 
137 /****f* OpenSM: DR Path/osm_dr_path_init
138 * NAME
139 *	osm_dr_path_init
140 *
141 * DESCRIPTION
142 *	This function initializes a directed route path object.
143 *
144 * SYNOPSIS
145 */
146 static inline void
osm_dr_path_init(IN osm_dr_path_t * p_path,IN uint8_t hop_count,IN const uint8_t path[IB_SUBNET_PATH_HOPS_MAX])147 osm_dr_path_init(IN osm_dr_path_t * p_path, IN uint8_t hop_count,
148 		 IN const uint8_t path[IB_SUBNET_PATH_HOPS_MAX])
149 {
150 	/* The first location in the path array is reserved. */
151 	CL_ASSERT(path[0] == 0);
152 	CL_ASSERT(hop_count < IB_SUBNET_PATH_HOPS_MAX);
153 	p_path->hop_count = hop_count;
154 	memcpy(p_path->path, path, hop_count + 1);
155 }
156 
157 /*
158 * PARAMETERS
159 *	p_path
160 *		[in] Pointer to a directed route path object to initialize.
161 *
162 *	h_bind
163 *		[in] Bind handle for the port on which this path applies.
164 *
165 *	hop_count
166 *		[in] Hop count needed to reach this node.
167 *
168 *	path
169 *		[in] Directed route path to reach this node.
170 *
171 * RETURN VALUE
172 *	None.
173 *
174 * NOTES
175 *
176 * SEE ALSO
177 *********/
178 /****f* OpenSM: DR Path/osm_dr_path_extend
179 * NAME
180 *	osm_dr_path_extend
181 *
182 * DESCRIPTION
183 *	Adds a new hop to a path.
184 *
185 * SYNOPSIS
186 */
osm_dr_path_extend(IN osm_dr_path_t * p_path,IN uint8_t port_num)187 static inline int osm_dr_path_extend(IN osm_dr_path_t * p_path,
188 				     IN uint8_t port_num)
189 {
190 	p_path->hop_count++;
191 
192 	if (p_path->hop_count >= IB_SUBNET_PATH_HOPS_MAX)
193 		return -1;
194 	/*
195 	   Location 0 in the path array is reserved per IB spec.
196 	 */
197 	p_path->path[p_path->hop_count] = port_num;
198 	return 0;
199 }
200 
201 /*
202 * PARAMETERS
203 *	p_path
204 *		[in] Pointer to a directed route path object to initialize.
205 *
206 *	port_num
207 *		[in] Additional port to add to the DR path.
208 *
209 * RETURN VALUES
210 *	0 indicates path was extended.
211 *	Other than 0 indicates path was not extended.
212 *
213 * NOTES
214 *
215 * SEE ALSO
216 *********/
217 
218 END_C_DECLS
219 #endif				/* _OSM_PATH_H_ */
220