File: ibis.c

package info (click to toggle)
ibutils 1.2-OFED-1.4.2-1.3
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 23,616 kB
  • sloc: cpp: 153,349; ansic: 77,237; tcl: 13,447; sh: 11,852; makefile: 494; yacc: 333; lex: 169; awk: 53
file content (248 lines) | stat: -rw-r--r-- 6,787 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*
 * Copyright (c) 2004 Mellanox Technologies LTD. All rights reserved.
 *
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the
 * OpenIB.org BSD license below:
 *
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      - Redistributions of source code must retain the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer in the documentation and/or other materials
 *        provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 * $Id$
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <complib/cl_debug.h>
#include "ibis.h"
#include "ibis_api.h"
#include "git_version.h"
#include <opensm/osm_log.h>
#include <opensm/osm_mad_pool.h>
#include <opensm/osm_helper.h>


/****g* IBIS/IbisObj
 * NAME
 * IbisObj
 *
 * DESCRIPTION
 * global IBIS Object
 *
 * SYNOPSIS
 */
ibis_t IbisObj;
/*
 * SEE ALSO
 * IBIS object, ibis_construct, ibis_destroy
 *********/

/**********************************************************************
 **********************************************************************/
void
ibis_construct(void) {
  memset( &IbisObj, 0, sizeof( ibis_t ) );
  IbisObj.initialized = FALSE;
  IbisObj.trans_id = 0x1;
  osm_log_construct( &(IbisObj.log) );
  osm_mad_pool_construct( &(IbisObj.mad_pool));
  cl_disp_construct( &(IbisObj.disp) );
  ibis_gsi_mad_ctrl_construct( &(IbisObj.mad_ctrl) );
}

/**********************************************************************
 **********************************************************************/
void
ibis_destroy(void) {

  if (! IbisObj.initialized) return;

  ibis_gsi_mad_ctrl_destroy( &(IbisObj.mad_ctrl) );
  cl_disp_destroy( &(IbisObj.disp) );

  if (IbisObj.p_vendor)
    osm_vendor_delete(&(IbisObj.p_vendor));

  osm_mad_pool_destroy( &(IbisObj.mad_pool));

  osm_log_destroy( &(IbisObj.log) );

  IbisObj.initialized = FALSE;
}

/**********************************************************************
 **********************************************************************/
ib_api_status_t
ibis_init(
  IN ibis_opt_t *p_opt,
  IN const osm_log_level_t log_flags
  )
{
  ib_api_status_t status;

  IbisObj.port_guid = 0;
  ibis_construct();
  status = osm_log_init( &(IbisObj.log),
                         p_opt->force_log_flush,0x01, p_opt->log_file
#ifdef OSM_BUILD_OPENIB
                         , FALSE /* do not accumulate log ... */
#endif
                         );
  if( status != IB_SUCCESS )
    return ( status ); // no log ....

  /* but we do not want any extra staff here */
  osm_log_set_level( &(IbisObj.log), log_flags );

  osm_log( &(IbisObj.log), OSM_LOG_FUNCS,"ibis_init: [\n" );

  IbisObj.p_opt = p_opt;

  status = osm_mad_pool_init( &(IbisObj.mad_pool) );
  if( status != IB_SUCCESS )
  {
    osm_log( &IbisObj.log, OSM_LOG_ERROR,
             "ibis_init: ERR 0002: "
             "Unable to allocate MAD pool\n");
    goto Exit;
  }

  IbisObj.p_vendor = osm_vendor_new( &(IbisObj.log),
                                     p_opt->transaction_timeout );


  if( IbisObj.p_vendor == NULL )
  {
    status = IB_INSUFFICIENT_RESOURCES;
    osm_log( &IbisObj.log, OSM_LOG_ERROR,
             "ibis_init: ERR 0001: "
             "Unable to allocate vendor object" );
    goto Exit;
  }

  if (IbisObj.p_opt->single_thread)
  {
    status = cl_disp_init(&(IbisObj.disp),1,"gsi" );
  }
  else
  {
    status = cl_disp_init(&(IbisObj.disp),0,"gsi" );
  }

  if( status != IB_SUCCESS )
  {
    osm_log( &IbisObj.log, OSM_LOG_ERROR,
             "ibis_init: ERR 0003: "
             "Unable to allocate GSI MADs Dispatcher\n");
    goto Exit;
  }

  status = ibis_gsi_mad_ctrl_init(&(IbisObj.mad_ctrl),
                                  &(IbisObj.mad_pool),
                                  IbisObj.p_vendor,
                                  &(IbisObj.log),
                                  &(IbisObj.disp));

  if( status != IB_SUCCESS )
  {
    osm_log( &IbisObj.log, OSM_LOG_ERROR,
             "ibis_init: ERR 0003: "
             "Unable to allocate GSI MADs Control\n");
    goto Exit;
  }

  IbisObj.initialized = TRUE;
 Exit:
  return ( status );
}

/**********************************************************************
 **********************************************************************/

const ibis_gsi_mad_ctrl_t*
ibis_get_gsi_mad_ctrl()
{
  return (&(IbisObj.mad_ctrl));
}

/**********************************************************************
 **********************************************************************/
ib_api_status_t
ibis_get_ports_status(
  IN OUT uint32_t *num_ports,
  IN OUT ibis_port_info_t ports_array[] )
{
  uint32_t i;
  ib_api_status_t status;
  ib_port_attr_t attr_array[GUID_ARRAY_SIZE];

  OSM_LOG_ENTER(&(IbisObj.log));

  *num_ports = GUID_ARRAY_SIZE;
  status = osm_vendor_get_all_port_attr(
    IbisObj.p_vendor,
    attr_array,
    num_ports );

  if( status != IB_SUCCESS )
  {
    osm_log( &IbisObj.log, OSM_LOG_ERROR,
             "ibis_get_ports_status: ERR 0001: "
             "Unable to obtain ports information - got err code:%u.\n",
             status);
    goto Exit;
  }

  if( num_ports == 0 )
  {
    status = IB_ERROR;
    goto Exit;
  }

  for( i = 0; i < *num_ports; i++ )
  {
    ports_array[i].port_guid = cl_ntoh64(attr_array[i].port_guid);
    ports_array[i].lid = cl_ntoh16( attr_array[i].lid );
    ports_array[i].link_state = attr_array[i].link_state;
  }

  Exit :
    OSM_LOG_EXIT( &(IbisObj.log) );
  return (status);
}

/**********************************************************************
 **********************************************************************/
ib_net64_t
ibis_get_tid(void)
{
  return( cl_ntoh64(cl_atomic_inc(&IbisObj.trans_id)));
}


#ifndef IBIS_CODE_VERSION
#define IBIS_CODE_VERSION "undefined"
#endif
const char * ibisSourceVersion = IBIS_CODE_VERSION ;