2 * Copyright (c) 2004-2006 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 #endif /* HAVE_CONFIG_H */
42 #include <iba/ib_types.h>
43 #include <complib/cl_qlist.h>
45 #include <vendor/osm_vendor_mlx_rmpp_ctx.h>
46 #include <vendor/osm_vendor_mlx_svc.h>
49 osmv_rmpp_send_ctx_init(osmv_rmpp_send_ctx_t * p_ctx, void *p_arbt_mad,
50 uint32_t mad_sz, osm_log_t * p_log)
52 ib_api_status_t st = IB_SUCCESS;
56 if (NULL == p_arbt_mad) {
57 return IB_INVALID_PARAMETER;
60 if (osmv_mad_is_sa((ib_mad_t *) p_arbt_mad)) {
61 p_ctx->is_sa_mad = TRUE;
63 p_ctx->is_sa_mad = FALSE;
65 p_ctx->mad_sz = mad_sz;
67 cl_event_construct(&p_ctx->event);
68 cl_st = cl_event_init(&p_ctx->event, FALSE);
69 if (cl_st != CL_SUCCESS) {
73 st = osmv_rmpp_sar_init(&p_ctx->sar, p_arbt_mad, p_ctx->mad_sz,
75 if (st == IB_SUCCESS) {
76 p_ctx->window_first = 1;
77 p_ctx->window_last = 1;
84 void osmv_rmpp_send_ctx_done(IN osmv_rmpp_send_ctx_t * p_ctx)
87 cl_event_destroy(&p_ctx->event);
88 osmv_rmpp_sar_done(&p_ctx->sar);
92 uint32_t osmv_rmpp_send_ctx_get_num_segs(IN osmv_rmpp_send_ctx_t * p_send_ctx)
94 uint32_t data_len, data_sz, num;
96 CL_ASSERT(p_send_ctx);
98 if (p_send_ctx->is_sa_mad) {
99 data_len = p_send_ctx->mad_sz - IB_SA_MAD_HDR_SIZE;
100 data_sz = IB_SA_DATA_SIZE;
102 data_len = p_send_ctx->mad_sz - MAD_RMPP_HDR_SIZE;
103 data_sz = MAD_RMPP_DATA_SIZE;
106 num = data_len / data_sz;
107 if (0 == data_len || (data_len % data_sz) > 0) {
115 osmv_rmpp_send_ctx_get_seg(IN osmv_rmpp_send_ctx_t * p_send_ctx,
117 IN uint32_t resp_timeout, OUT void *p_buf)
119 ib_api_status_t st = IB_SUCCESS;
120 uint32_t num_segs, paylen = 0;
121 ib_rmpp_mad_t *p_rmpp_mad;
123 OSM_LOG_ENTER(p_send_ctx->p_log);
124 CL_ASSERT(p_send_ctx);
126 st = osmv_rmpp_sar_get_mad_seg(&p_send_ctx->sar, seg_idx, p_buf);
127 if (st != IB_SUCCESS) {
131 p_rmpp_mad = (ib_rmpp_mad_t *) p_buf;
132 /* Set the relevant bits in the RMPP hdr */
133 p_rmpp_mad->rmpp_status = IB_RMPP_STATUS_SUCCESS;
134 p_rmpp_mad->rmpp_flags |= IB_RMPP_FLAG_ACTIVE;
135 p_rmpp_mad->rmpp_flags |= resp_timeout << 3;
137 num_segs = osmv_rmpp_send_ctx_get_num_segs(p_send_ctx);
140 p_rmpp_mad->rmpp_flags |= IB_RMPP_FLAG_FIRST;
142 /* This is the first segment -
143 the reported paylen is the total amount of data.
145 if (p_send_ctx->is_sa_mad) {
147 paylen = p_send_ctx->mad_sz - IB_SA_MAD_HDR_SIZE;
149 num_segs * (IB_SA_MAD_HDR_SIZE - MAD_RMPP_HDR_SIZE);
152 paylen = p_send_ctx->mad_sz - MAD_RMPP_HDR_SIZE;
156 if (seg_idx == num_segs) {
157 p_rmpp_mad->rmpp_flags |= IB_RMPP_FLAG_LAST;
160 This is the last segment -
161 the reported paylen is only the amount of data left on this segment.
163 if (p_send_ctx->is_sa_mad) {
164 paylen = p_send_ctx->mad_sz - IB_SA_MAD_HDR_SIZE;
165 paylen -= (num_segs - 1) * IB_SA_DATA_SIZE;
166 paylen += (IB_SA_MAD_HDR_SIZE - MAD_RMPP_HDR_SIZE);
168 paylen = p_send_ctx->mad_sz - MAD_RMPP_HDR_SIZE;
170 (num_segs - 1) * (MAD_BLOCK_SIZE -
175 p_rmpp_mad->rmpp_type = IB_RMPP_TYPE_DATA;
176 p_rmpp_mad->rmpp_version = 1;
177 p_rmpp_mad->paylen_newwin = cl_ntoh32(paylen);
178 p_rmpp_mad->seg_num = cl_ntoh32(seg_idx);
181 OSM_LOG_EXIT(p_send_ctx->p_log);
186 osmv_rmpp_recv_ctx_init(osmv_rmpp_recv_ctx_t * p_ctx, osm_log_t * p_log)
188 ib_api_status_t st = IB_SUCCESS;
192 p_ctx->is_sa_mad = FALSE;
194 p_ctx->p_rbuf = malloc(sizeof(cl_qlist_t));
196 memset(p_ctx->p_rbuf, 0, sizeof(cl_qlist_t));
197 cl_qlist_init(p_ctx->p_rbuf);
198 p_ctx->expected_seg = 1;
200 st = IB_INSUFFICIENT_MEMORY;
202 p_ctx->p_log = p_log;
207 void osmv_rmpp_recv_ctx_done(IN osmv_rmpp_recv_ctx_t * p_ctx)
209 cl_list_item_t *p_list_item;
210 cl_list_obj_t *p_obj;
214 /* go over all the items in the list and remove them */
215 p_list_item = cl_qlist_remove_head(p_ctx->p_rbuf);
216 while (p_list_item != cl_qlist_end(p_ctx->p_rbuf)) {
218 p_obj = PARENT_STRUCT(p_list_item, cl_list_obj_t, list_item);
220 free(cl_qlist_obj(p_obj));
223 p_list_item = cl_qlist_remove_head(p_ctx->p_rbuf);
226 osmv_rmpp_sar_done(&p_ctx->sar);
233 osmv_rmpp_recv_ctx_store_mad_seg(IN osmv_rmpp_recv_ctx_t * p_recv_ctx,
236 cl_list_obj_t *p_obj = NULL;
239 OSM_LOG_ENTER(p_recv_ctx->p_log);
241 CL_ASSERT(p_recv_ctx);
242 p_list_mad = malloc(MAD_BLOCK_SIZE);
243 if (NULL == p_list_mad) {
244 return IB_INSUFFICIENT_MEMORY;
246 memset(p_list_mad, 0, MAD_BLOCK_SIZE);
247 memcpy(p_list_mad, p_mad, MAD_BLOCK_SIZE);
249 p_obj = malloc(sizeof(cl_list_obj_t));
252 return IB_INSUFFICIENT_MEMORY;
254 memset(p_obj, 0, sizeof(cl_list_obj_t));
255 cl_qlist_set_obj(p_obj, p_list_mad);
257 cl_qlist_insert_tail(p_recv_ctx->p_rbuf, &p_obj->list_item);
259 if (osmv_mad_is_sa((ib_mad_t *) p_mad)) {
260 p_recv_ctx->is_sa_mad = TRUE;
268 osmv_rmpp_recv_ctx_get_cur_byte_num(IN osmv_rmpp_recv_ctx_t * p_recv_ctx)
272 num_segs = cl_qlist_count(p_recv_ctx->p_rbuf);
273 if (p_recv_ctx->is_sa_mad)
274 return ((num_segs * IB_SA_DATA_SIZE) + IB_SA_MAD_HDR_SIZE);
276 return ((num_segs * MAD_RMPP_DATA_SIZE) + MAD_RMPP_HDR_SIZE);
280 osmv_rmpp_recv_ctx_get_byte_num_from_first(IN osmv_rmpp_recv_ctx_t * p_recv_ctx)
282 cl_list_item_t *p_item;
283 cl_list_obj_t *p_obj;
285 uint32_t num_bytes, num_segs;
287 p_item = cl_qlist_head(p_recv_ctx->p_rbuf);
288 p_obj = PARENT_STRUCT(p_item, cl_list_obj_t, list_item);
289 p_list_mad = cl_qlist_obj(p_obj);
292 num_bytes = cl_ntoh32(((ib_rmpp_mad_t *) p_list_mad)->paylen_newwin);
293 if (0 != num_bytes) {
294 if (p_recv_ctx->is_sa_mad) {
296 num_segs = cl_qlist_count(p_recv_ctx->p_rbuf);
298 num_segs * (IB_SA_MAD_HDR_SIZE - MAD_RMPP_HDR_SIZE);
299 num_bytes += IB_SA_MAD_HDR_SIZE;
302 num_bytes += MAD_RMPP_HDR_SIZE;
310 osmv_rmpp_recv_ctx_get_byte_num_from_last(IN osmv_rmpp_recv_ctx_t * p_recv_ctx)
312 cl_list_item_t *p_item;
313 cl_list_obj_t *p_obj;
315 uint32_t num_bytes, num_segs;
317 p_item = cl_qlist_tail(p_recv_ctx->p_rbuf);
318 p_obj = PARENT_STRUCT(p_item, cl_list_obj_t, list_item);
319 p_list_mad = cl_qlist_obj(p_obj);
322 num_segs = cl_qlist_count(p_recv_ctx->p_rbuf);
323 num_bytes = cl_ntoh32(((ib_rmpp_mad_t *) p_list_mad)->paylen_newwin);
325 if (0 != num_bytes) {
326 if (p_recv_ctx->is_sa_mad) {
328 num_bytes += MAD_RMPP_HDR_SIZE;
329 num_bytes += (num_segs - 1) * IB_SA_DATA_SIZE;
332 num_bytes += MAD_RMPP_HDR_SIZE;
333 num_bytes += (num_segs - 1) * MAD_RMPP_DATA_SIZE;
340 /* assuming that the last rmpp pkt arrived so that data member: total_bytes has the right value */
342 osmv_rmpp_recv_ctx_reassemble_arbt_mad(IN osmv_rmpp_recv_ctx_t * p_recv_ctx,
343 IN uint32_t size, IN void *p_arbt_mad)
345 ib_api_status_t st = IB_SUCCESS;
347 CL_ASSERT(p_recv_ctx);
349 st = osmv_rmpp_sar_init(&p_recv_ctx->sar, p_arbt_mad, size,
350 p_recv_ctx->is_sa_mad);
351 if (st != IB_SUCCESS) {
355 st = osmv_rmpp_sar_reassemble_arbt_mad(&p_recv_ctx->sar,
358 osmv_rmpp_sar_done(&p_recv_ctx->sar);