]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/ofed/management/opensm/include/vendor/osm_vendor_mlx_svc.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / ofed / management / opensm / include / vendor / osm_vendor_mlx_svc.h
1 /*
2  * Copyright (c) 2004, 2005 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 #ifndef _OSMV_SVC_H_
37 #define _OSMV_SVC_H_
38
39 #include <stdlib.h>
40 #include <string.h>
41 #include <iba/ib_types.h>
42 #include <vendor/osm_vendor_mlx_defs.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 inline static boolean_t osmv_mad_is_response(IN const ib_mad_t * p_mad)
54 {
55         return (ib_mad_is_response(p_mad) ||
56                 (p_mad->method == IB_MAD_METHOD_TRAP_REPRESS));
57 }
58
59 inline static uint8_t osmv_invert_method(IN uint8_t req_method)
60 {
61         switch (req_method) {
62         case IB_MAD_METHOD_GET_RESP:
63                 /* Not a 1-1 mapping! */
64                 return IB_MAD_METHOD_GET;
65
66         case IB_MAD_METHOD_GET:
67                 return IB_MAD_METHOD_GET_RESP;
68
69         case IB_MAD_METHOD_SET:
70                 return IB_MAD_METHOD_GET_RESP;
71
72         case IB_MAD_METHOD_GETTABLE_RESP:
73                 return IB_MAD_METHOD_GETTABLE;
74
75         case IB_MAD_METHOD_GETTABLE:
76                 return IB_MAD_METHOD_GETTABLE_RESP;
77
78         case IB_MAD_METHOD_GETMULTI_RESP:
79                 /* Not a 1-1 mapping! */
80                 return IB_MAD_METHOD_GETMULTI;
81
82         case IB_MAD_METHOD_GETTRACETABLE:
83         case IB_MAD_METHOD_GETMULTI:
84                 return IB_MAD_METHOD_GETMULTI_RESP;
85
86         case IB_MAD_METHOD_TRAP:
87                 return IB_MAD_METHOD_TRAP_REPRESS;
88
89         case IB_MAD_METHOD_TRAP_REPRESS:
90                 return IB_MAD_METHOD_TRAP;
91
92         case IB_MAD_METHOD_REPORT:
93                 return IB_MAD_METHOD_REPORT_RESP;
94
95         case IB_MAD_METHOD_REPORT_RESP:
96                 return IB_MAD_METHOD_REPORT;
97
98                 /*  IB_MAD_METHOD_SEND does not have a response */
99         case IB_MAD_METHOD_SEND:
100                 return IB_MAD_METHOD_SEND;
101
102         default:
103                 CL_ASSERT(FALSE);
104         }
105
106         return 0;               /* Just make the compiler happy */
107 }
108
109 inline static boolean_t osmv_mad_is_rmpp(IN const ib_mad_t * p_mad)
110 {
111         uint8_t rmpp_flags;
112         CL_ASSERT(NULL != p_mad);
113
114         rmpp_flags = ((ib_rmpp_mad_t *) p_mad)->rmpp_flags;
115         /* HACK - JUST SA and DevMgt for now - need to add BIS and DevAdm */
116         if ((p_mad->mgmt_class != IB_MCLASS_SUBN_ADM) &&
117             (p_mad->mgmt_class != IB_MCLASS_DEV_MGMT))
118                 return (0);
119         return (0 != (rmpp_flags & IB_RMPP_FLAG_ACTIVE));
120 }
121
122 inline static boolean_t osmv_mad_is_multi_resp(IN const ib_mad_t * p_mad)
123 {
124         CL_ASSERT(NULL != p_mad);
125         return (IB_MAD_METHOD_GETMULTI == p_mad->method
126                 || IB_MAD_METHOD_GETTRACETABLE == p_mad->method);
127 }
128
129 inline static boolean_t osmv_mad_is_sa(IN const ib_mad_t * p_mad)
130 {
131         CL_ASSERT(NULL != p_mad);
132         return (IB_MCLASS_SUBN_ADM == p_mad->mgmt_class);
133 }
134
135 inline static boolean_t osmv_rmpp_is_abort_stop(IN const ib_mad_t * p_mad)
136 {
137         uint8_t rmpp_type;
138         CL_ASSERT(p_mad);
139
140         rmpp_type = ((ib_rmpp_mad_t *) p_mad)->rmpp_type;
141         return (IB_RMPP_TYPE_STOP == rmpp_type
142                 || IB_RMPP_TYPE_ABORT == rmpp_type);
143 }
144
145 inline static boolean_t osmv_rmpp_is_data(IN const ib_mad_t * p_mad)
146 {
147         CL_ASSERT(p_mad);
148         return (IB_RMPP_TYPE_DATA == ((ib_rmpp_mad_t *) p_mad)->rmpp_type);
149 }
150
151 inline static boolean_t osmv_rmpp_is_ack(IN const ib_mad_t * p_mad)
152 {
153         CL_ASSERT(p_mad);
154         return (IB_RMPP_TYPE_ACK == ((ib_rmpp_mad_t *) p_mad)->rmpp_type);
155 }
156
157 inline static boolean_t osmv_rmpp_is_first(IN const ib_mad_t * p_mad)
158 {
159         uint8_t rmpp_flags;
160         CL_ASSERT(NULL != p_mad);
161
162         rmpp_flags = ((ib_rmpp_mad_t *) p_mad)->rmpp_flags;
163         return (0 != (IB_RMPP_FLAG_FIRST & rmpp_flags));
164 }
165
166 inline static boolean_t osmv_rmpp_is_last(IN const ib_mad_t * p_mad)
167 {
168         uint8_t rmpp_flags;
169         CL_ASSERT(NULL != p_mad);
170
171         rmpp_flags = ((ib_rmpp_mad_t *) p_mad)->rmpp_flags;
172         return (0 != (IB_RMPP_FLAG_LAST & rmpp_flags));
173 }
174
175 inline static uint8_t *osmv_mad_copy(IN const ib_mad_t * p_mad)
176 {
177         uint8_t *p_copy;
178
179         CL_ASSERT(p_mad);
180         p_copy = malloc(MAD_BLOCK_SIZE);
181
182         if (NULL != p_copy) {
183                 memset(p_copy, 0, MAD_BLOCK_SIZE);
184                 memcpy(p_copy, p_mad, MAD_BLOCK_SIZE);
185         }
186
187         return p_copy;
188 }
189
190 /* Should be passed externally from the Makefile */
191 /*  #define OSMV_RANDOM_DROP 1 */
192 #define OSMV_DROP_RATE   0.3
193
194 inline static boolean_t osmv_random_drop(void)
195 {
196         srand(1);               /* Pick a new base */
197         return (rand() / (double)RAND_MAX < OSMV_DROP_RATE);
198 }
199
200 END_C_DECLS
201 #endif                          /* _OSMV_SVC_H_ */