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.
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
41 #include <iba/ib_types.h>
42 #include <vendor/osm_vendor_mlx_defs.h>
45 # define BEGIN_C_DECLS extern "C" {
46 # define END_C_DECLS }
47 #else /* !__cplusplus */
48 # define BEGIN_C_DECLS
50 #endif /* __cplusplus */
53 inline static boolean_t osmv_mad_is_response(IN const ib_mad_t * p_mad)
55 return (ib_mad_is_response(p_mad) ||
56 (p_mad->method == IB_MAD_METHOD_TRAP_REPRESS));
59 inline static uint8_t osmv_invert_method(IN uint8_t req_method)
62 case IB_MAD_METHOD_GET_RESP:
63 /* Not a 1-1 mapping! */
64 return IB_MAD_METHOD_GET;
66 case IB_MAD_METHOD_GET:
67 return IB_MAD_METHOD_GET_RESP;
69 case IB_MAD_METHOD_SET:
70 return IB_MAD_METHOD_GET_RESP;
72 case IB_MAD_METHOD_GETTABLE_RESP:
73 return IB_MAD_METHOD_GETTABLE;
75 case IB_MAD_METHOD_GETTABLE:
76 return IB_MAD_METHOD_GETTABLE_RESP;
78 case IB_MAD_METHOD_GETMULTI_RESP:
79 /* Not a 1-1 mapping! */
80 return IB_MAD_METHOD_GETMULTI;
82 case IB_MAD_METHOD_GETTRACETABLE:
83 case IB_MAD_METHOD_GETMULTI:
84 return IB_MAD_METHOD_GETMULTI_RESP;
86 case IB_MAD_METHOD_TRAP:
87 return IB_MAD_METHOD_TRAP_REPRESS;
89 case IB_MAD_METHOD_TRAP_REPRESS:
90 return IB_MAD_METHOD_TRAP;
92 case IB_MAD_METHOD_REPORT:
93 return IB_MAD_METHOD_REPORT_RESP;
95 case IB_MAD_METHOD_REPORT_RESP:
96 return IB_MAD_METHOD_REPORT;
98 /* IB_MAD_METHOD_SEND does not have a response */
99 case IB_MAD_METHOD_SEND:
100 return IB_MAD_METHOD_SEND;
106 return 0; /* Just make the compiler happy */
109 inline static boolean_t osmv_mad_is_rmpp(IN const ib_mad_t * p_mad)
112 CL_ASSERT(NULL != p_mad);
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))
119 return (0 != (rmpp_flags & IB_RMPP_FLAG_ACTIVE));
122 inline static boolean_t osmv_mad_is_multi_resp(IN const ib_mad_t * p_mad)
124 CL_ASSERT(NULL != p_mad);
125 return (IB_MAD_METHOD_GETMULTI == p_mad->method
126 || IB_MAD_METHOD_GETTRACETABLE == p_mad->method);
129 inline static boolean_t osmv_mad_is_sa(IN const ib_mad_t * p_mad)
131 CL_ASSERT(NULL != p_mad);
132 return (IB_MCLASS_SUBN_ADM == p_mad->mgmt_class);
135 inline static boolean_t osmv_rmpp_is_abort_stop(IN const ib_mad_t * p_mad)
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);
145 inline static boolean_t osmv_rmpp_is_data(IN const ib_mad_t * p_mad)
148 return (IB_RMPP_TYPE_DATA == ((ib_rmpp_mad_t *) p_mad)->rmpp_type);
151 inline static boolean_t osmv_rmpp_is_ack(IN const ib_mad_t * p_mad)
154 return (IB_RMPP_TYPE_ACK == ((ib_rmpp_mad_t *) p_mad)->rmpp_type);
157 inline static boolean_t osmv_rmpp_is_first(IN const ib_mad_t * p_mad)
160 CL_ASSERT(NULL != p_mad);
162 rmpp_flags = ((ib_rmpp_mad_t *) p_mad)->rmpp_flags;
163 return (0 != (IB_RMPP_FLAG_FIRST & rmpp_flags));
166 inline static boolean_t osmv_rmpp_is_last(IN const ib_mad_t * p_mad)
169 CL_ASSERT(NULL != p_mad);
171 rmpp_flags = ((ib_rmpp_mad_t *) p_mad)->rmpp_flags;
172 return (0 != (IB_RMPP_FLAG_LAST & rmpp_flags));
175 inline static uint8_t *osmv_mad_copy(IN const ib_mad_t * p_mad)
180 p_copy = malloc(MAD_BLOCK_SIZE);
182 if (NULL != p_copy) {
183 memset(p_copy, 0, MAD_BLOCK_SIZE);
184 memcpy(p_copy, p_mad, MAD_BLOCK_SIZE);
190 /* Should be passed externally from the Makefile */
191 /* #define OSMV_RANDOM_DROP 1 */
192 #define OSMV_DROP_RATE 0.3
194 inline static boolean_t osmv_random_drop(void)
196 srand(1); /* Pick a new base */
197 return (rand() / (double)RAND_MAX < OSMV_DROP_RATE);
201 #endif /* _OSMV_SVC_H_ */