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.
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
38 * Implementation of osm_mad_pool_t.
39 * This object represents a pool of management datagram (MAD) objects.
40 * This object is part of the opensm family of objects.
45 #endif /* HAVE_CONFIG_H */
49 #include <opensm/osm_mad_pool.h>
50 #include <opensm/osm_madw.h>
51 #include <vendor/osm_vendor_api.h>
53 /**********************************************************************
54 **********************************************************************/
55 void osm_mad_pool_construct(IN osm_mad_pool_t * const p_pool)
59 memset(p_pool, 0, sizeof(*p_pool));
62 /**********************************************************************
63 **********************************************************************/
64 void osm_mad_pool_destroy(IN osm_mad_pool_t * const p_pool)
69 /**********************************************************************
70 **********************************************************************/
71 ib_api_status_t osm_mad_pool_init(IN osm_mad_pool_t * const p_pool)
78 /**********************************************************************
79 **********************************************************************/
80 osm_madw_t *osm_mad_pool_get(IN osm_mad_pool_t * const p_pool,
81 IN osm_bind_handle_t h_bind,
82 IN const uint32_t total_size,
83 IN const osm_mad_addr_t * const p_mad_addr)
88 CL_ASSERT(h_bind != OSM_BIND_INVALID_HANDLE);
89 CL_ASSERT(total_size);
92 First, acquire a mad wrapper from the mad wrapper pool.
94 p_madw = malloc(sizeof(*p_madw));
98 osm_madw_init(p_madw, h_bind, total_size, p_mad_addr);
101 Next, acquire a wire mad of the specified size.
103 p_mad = osm_vendor_get(h_bind, total_size, &p_madw->vend_wrap);
105 /* Don't leak wrappers! */
111 cl_atomic_inc(&p_pool->mads_out);
113 Finally, attach the wire MAD to this wrapper.
115 osm_madw_set_mad(p_madw, p_mad);
121 /**********************************************************************
122 **********************************************************************/
123 osm_madw_t *osm_mad_pool_get_wrapper(IN osm_mad_pool_t * const p_pool,
124 IN osm_bind_handle_t h_bind,
125 IN const uint32_t total_size,
126 IN const ib_mad_t * const p_mad,
127 IN const osm_mad_addr_t * const p_mad_addr)
131 CL_ASSERT(h_bind != OSM_BIND_INVALID_HANDLE);
132 CL_ASSERT(total_size);
136 First, acquire a mad wrapper from the mad wrapper pool.
138 p_madw = malloc(sizeof(*p_madw));
143 Finally, initialize the wrapper object.
145 cl_atomic_inc(&p_pool->mads_out);
146 osm_madw_init(p_madw, h_bind, total_size, p_mad_addr);
147 osm_madw_set_mad(p_madw, p_mad);
153 /**********************************************************************
154 **********************************************************************/
155 osm_madw_t *osm_mad_pool_get_wrapper_raw(IN osm_mad_pool_t * const p_pool)
159 p_madw = malloc(sizeof(*p_madw));
163 osm_madw_init(p_madw, 0, 0, 0);
164 osm_madw_set_mad(p_madw, 0);
165 cl_atomic_inc(&p_pool->mads_out);
170 /**********************************************************************
171 **********************************************************************/
173 osm_mad_pool_put(IN osm_mad_pool_t * const p_pool, IN osm_madw_t * const p_madw)
178 First, return the wire mad to the pool
181 osm_vendor_put(p_madw->h_bind, &p_madw->vend_wrap);
184 Return the mad wrapper to the wrapper pool
187 cl_atomic_dec(&p_pool->mads_out);