]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ofed/opensm/libvendor/osm_vendor_test.c
Import libxo-1.3.0:
[FreeBSD/FreeBSD.git] / contrib / ofed / opensm / libvendor / osm_vendor_test.c
1 /*
2  * Copyright (c) 2004-2008 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 /*
37  * Abstract:
38  *    Implementation of vendor specific transport interface.
39  *  This is the "Test" vendor which allows compilation and some
40  *  testing without a real vendor interface.
41  * These objects are part of the opensm family of objects.
42  *
43  */
44
45 #if HAVE_CONFIG_H
46 #  include <config.h>
47 #endif                          /* HAVE_CONFIG_H */
48
49 #ifdef OSM_VENDOR_INTF_TEST
50
51 #include <stdlib.h>
52 #include <string.h>
53 #include <opensm/osm_log.h>
54 #include <vendor/osm_vendor_test.h>
55 #include <vendor/osm_vendor_api.h>
56
57 void osm_vendor_construct(IN osm_vendor_t * const p_vend)
58 {
59         memset(p_vend, 0, sizeof(*p_vend));
60 }
61
62 void osm_vendor_destroy(IN osm_vendor_t * const p_vend)
63 {
64         UNUSED_PARAM(p_vend);
65 }
66
67 void osm_vendor_delete(IN osm_vendor_t ** const pp_vend)
68 {
69         CL_ASSERT(pp_vend);
70
71         osm_vendor_destroy(*pp_vend);
72         free(*pp_vend);
73         *pp_vend = NULL;
74 }
75
76 ib_api_status_t
77 osm_vendor_init(IN osm_vendor_t * const p_vend,
78                 IN osm_log_t * const p_log, IN const uint32_t timeout)
79 {
80         OSM_LOG_ENTER(p_log);
81
82         CL_ASSERT(p_vend);
83         CL_ASSERT(p_log);
84
85         p_vend->p_log = p_log;
86         p_vend->timeout = timeout;
87         OSM_LOG_EXIT(p_log);
88         return (IB_SUCCESS);
89 }
90
91 osm_vendor_t *osm_vendor_new(IN osm_log_t * const p_log,
92                              IN const uint32_t timeout)
93 {
94         ib_api_status_t status;
95         osm_vendor_t *p_vend;
96         OSM_LOG_ENTER(p_log);
97
98         CL_ASSERT(p_log);
99
100         p_vend = malloc(sizeof(*p_vend));
101         if (p_vend != NULL) {
102                 memset(p_vend, 0, sizeof(*p_vend));
103
104                 status = osm_vendor_init(p_vend, p_log, timeout);
105                 if (status != IB_SUCCESS) {
106                         osm_vendor_delete(&p_vend);
107                 }
108         }
109
110         OSM_LOG_EXIT(p_log);
111         return (p_vend);
112 }
113
114 ib_mad_t *osm_vendor_get(IN osm_bind_handle_t h_bind,
115                          IN const uint32_t size,
116                          IN osm_vend_wrap_t * const p_vend_wrap)
117 {
118         osm_vendor_t *p_vend;
119         ib_mad_t *p_mad;
120         OSM_LOG_ENTER(h_bind->p_vend->p_log);
121
122         UNUSED_PARAM(p_vend_wrap);
123
124         p_vend = h_bind->p_vend;
125
126         /*
127            Simply malloc the MAD off the heap.
128          */
129         p_mad = (ib_mad_t *) malloc(size);
130
131         osm_log(p_vend->p_log, OSM_LOG_VERBOSE,
132                 "osm_vendor_get: " "MAD %p.\n", p_mad);
133
134         if (p_mad)
135                 memset(p_mad, 0, size);
136
137         OSM_LOG_EXIT(p_vend->p_log);
138         return (p_mad);
139 }
140
141 void
142 osm_vendor_put(IN osm_bind_handle_t h_bind,
143                IN osm_vend_wrap_t * const p_vend_wrap,
144                IN ib_mad_t * const p_mad)
145 {
146         osm_vendor_t *p_vend;
147
148         OSM_LOG_ENTER(h_bind->p_vend->p_log);
149
150         UNUSED_PARAM(p_vend_wrap);
151
152         p_vend = h_bind->p_vend;
153
154         osm_log(p_vend->p_log, OSM_LOG_VERBOSE,
155                 "osm_vendor_put: " "MAD %p.\n", p_mad);
156
157         /*
158            Return the MAD to the heap.
159          */
160         free(p_mad);
161
162         OSM_LOG_EXIT(p_vend->p_log);
163 }
164
165 ib_api_status_t
166 osm_vendor_send(IN osm_bind_handle_t h_bind,
167                 IN osm_vend_wrap_t * const p_vend_wrap,
168                 IN osm_mad_addr_t * const p_mad_addr,
169                 IN ib_mad_t * const p_mad,
170                 IN void *transaction_context, IN boolean_t const resp_expected)
171 {
172         osm_vendor_t *p_vend = h_bind->p_vend;
173
174         OSM_LOG_ENTER(p_vend->p_log);
175
176         UNUSED_PARAM(p_vend_wrap);
177         UNUSED_PARAM(p_mad_addr);
178         UNUSED_PARAM(transaction_context);
179         UNUSED_PARAM(resp_expected);
180
181         osm_log(p_vend->p_log, OSM_LOG_VERBOSE,
182                 "osm_vendor_send: " "MAD %p.\n", p_mad);
183
184         OSM_LOG_EXIT(p_vend->p_log);
185         return (IB_SUCCESS);
186 }
187
188 osm_bind_handle_t
189 osm_vendor_bind(IN osm_vendor_t * const p_vend,
190                 IN osm_bind_info_t * const p_bind_info,
191                 IN osm_mad_pool_t * const p_mad_pool,
192                 IN osm_vend_mad_recv_callback_t mad_recv_callback,
193                 IN void *context)
194 {
195         osm_bind_handle_t h_bind;
196
197         OSM_LOG_ENTER(p_vend->p_log);
198
199         CL_ASSERT(p_vend);
200         CL_ASSERT(p_bind_info);
201         CL_ASSERT(p_mad_pool);
202         CL_ASSERT(mad_recv_callback);
203         CL_ASSERT(context);
204
205         UNUSED_PARAM(p_vend);
206         UNUSED_PARAM(p_mad_pool);
207         UNUSED_PARAM(mad_recv_callback);
208         UNUSED_PARAM(context);
209
210         h_bind = (osm_bind_handle_t) malloc(sizeof(*h_bind));
211         if (h_bind != NULL) {
212                 memset(h_bind, 0, sizeof(*h_bind));
213                 h_bind->p_vend = p_vend;
214                 h_bind->port_guid = p_bind_info->port_guid;
215                 h_bind->mad_class = p_bind_info->mad_class;
216                 h_bind->class_version = p_bind_info->class_version;
217                 h_bind->is_responder = p_bind_info->is_responder;
218                 h_bind->is_trap_processor = p_bind_info->is_trap_processor;
219                 h_bind->is_report_processor = p_bind_info->is_report_processor;
220                 h_bind->send_q_size = p_bind_info->send_q_size;
221                 h_bind->recv_q_size = p_bind_info->recv_q_size;
222         }
223
224         OSM_LOG_EXIT(p_vend->p_log);
225         return (h_bind);
226 }
227
228 ib_api_status_t
229 osm_vendor_get_ports(IN osm_vendor_t * const p_vend,
230                      IN ib_net64_t * const p_guids,
231                      IN uint32_t * const num_guids)
232 {
233         OSM_LOG_ENTER(p_vend->p_log);
234
235         *p_guids = CL_NTOH64(0x0000000000001234);
236         *num_guids = 1;
237
238         OSM_LOG_EXIT(p_vend->p_log);
239         return (IB_SUCCESS);
240 }
241
242 ib_api_status_t osm_vendor_local_lid_change(IN osm_bind_handle_t h_bind)
243 {
244         osm_vendor_t *p_vend = h_bind->p_vend;
245
246         OSM_LOG_ENTER(p_vend->p_log);
247
248         OSM_LOG_EXIT(p_vend->p_log);
249
250         return (IB_SUCCESS);
251 }
252
253 void osm_vendor_set_debug(IN osm_vendor_t * const p_vend, IN int32_t level)
254 {
255
256 }
257
258 #endif                          /* OSM_VENDOR_INTF_TEST */