~ubuntu-branches/ubuntu/raring/ibutils/raring-proposed

« back to all changes in this revision

Viewing changes to ibmgtsim/src/ib_types.i

  • Committer: Bazaar Package Importer
  • Author(s): Benoit Mortier
  • Date: 2010-01-11 22:22:00 UTC
  • Revision ID: james.westby@ubuntu.com-20100111222200-53kum2et5nh13rv3
Tags: upstream-1.2-OFED-1.4.2
ImportĀ upstreamĀ versionĀ 1.2-OFED-1.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2004 Mellanox Technologies LTD. All rights reserved.
 
3
 *
 
4
 * This software is available to you under a choice of one of two
 
5
 * licenses.  You may choose to be licensed under the terms of the GNU
 
6
 * General Public License (GPL) Version 2, available from the file
 
7
 * COPYING in the main directory of this source tree, or the
 
8
 * OpenIB.org BSD license below:
 
9
 *
 
10
 *     Redistribution and use in source and binary forms, with or
 
11
 *     without modification, are permitted provided that the following
 
12
 *     conditions are met:
 
13
 *
 
14
 *      - Redistributions of source code must retain the above
 
15
 *        copyright notice, this list of conditions and the following
 
16
 *        disclaimer.
 
17
 *
 
18
 *      - Redistributions in binary form must reproduce the above
 
19
 *        copyright notice, this list of conditions and the following
 
20
 *        disclaimer in the documentation and/or other materials
 
21
 *        provided with the distribution.
 
22
 *
 
23
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
24
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
25
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
26
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 
27
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 
28
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
29
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 
30
 * SOFTWARE.
 
31
 *
 
32
 * $Id$
 
33
 */
 
34
 
 
35
/* Holds ib_types.h MAD structs in and out TypeMaps */
 
36
%{
 
37
 
 
38
  /* for IB structs we use the format: <type>:<ptr> */
 
39
 
 
40
  /* Given the Object Pointer and Type provide it's TCL name */
 
41
  int ibmsGetIBStructObjNameByPtr(Tcl_Obj *objPtr, void *ptr, char *type) {
 
42
         char tclName[128];
 
43
         string uiType;
 
44
         char name[128];
 
45
 
 
46
    /* check that the string starts with _ib_ and ends with _t_p */
 
47
    if (strncmp(type, "_ib_", 4)) {
 
48
                sprintf(tclName, "-E- Unrecognized Object Type:%s (should start with _ib_)", type);
 
49
                Tcl_SetStringObj(objPtr, tclName, -1);
 
50
                return TCL_ERROR;
 
51
         }
 
52
 
 
53
    if (strncmp(type+strlen(type) - 4, "_t_p", 4)) {
 
54
                sprintf(tclName, "-E- Unrecognized Object Type:%s (should end with _t_p %s)",
 
55
              type, type+strlen(type) - 4);
 
56
                Tcl_SetStringObj(objPtr, tclName, -1);
 
57
                return TCL_ERROR;
 
58
         }
 
59
 
 
60
    strncpy(name, type+4, strlen(type) - 8);
 
61
    name[strlen(type) - 8] = '\0';
 
62
    sprintf(tclName, "%s:%p", name, ptr);
 
63
    Tcl_SetStringObj(objPtr, tclName, -1);
 
64
    return TCL_OK;
 
65
  }
 
66
 
 
67
  /* Given the Object TCL Name Get it's pointer */
 
68
  int ibmsGetIBStructObjPtrByTclName(Tcl_Obj *objPtr, void **ptr) {
 
69
         /* we need to parse the name and get the type etc. */
 
70
         char *colonIdx;
 
71
         *ptr = NULL;
 
72
    char buf[256];
 
73
 
 
74
         strcpy(buf, Tcl_GetStringFromObj(objPtr,0));
 
75
 
 
76
         /* the format is always: <type>:<idx>[:<name>] */
 
77
 
 
78
         /* first separate the type */
 
79
         colonIdx = index(buf,':');
 
80
         if (!colonIdx) {
 
81
                printf("-E- Bad formatted (no :) ibdm object:%s\n", buf);
 
82
                return TCL_ERROR;
 
83
         }
 
84
         *colonIdx = '\0';
 
85
    colonIdx++;
 
86
 
 
87
    /* now all we need is to extract the pointer value from the
 
88
       rest of the string */
 
89
    if (sscanf(colonIdx,"%p", ptr) != 1) {
 
90
                printf("-E- Bad formatted pointer value:%s\n", colonIdx);
 
91
                return TCL_ERROR;
 
92
    }
 
93
         return TCL_OK;
 
94
  }
 
95
%}
 
96
 
 
97
%typemap(tcl8,in) ib_gid_t*(ib_gid_t temp) {
 
98
  char buf[36];
 
99
  char *p_prefix, *p_guid;
 
100
  char *str_token;
 
101
 
 
102
  strcpy(buf, Tcl_GetStringFromObj($source,NULL));
 
103
  p_prefix = strtok_r(buf,":", &str_token);
 
104
  p_guid = strtok_r(NULL, " ", &str_token);
 
105
  errno = 0;
 
106
  temp.unicast.prefix = cl_hton64(strtoull(p_prefix, NULL, 16));
 
107
  if (errno) {
 
108
    printf("Wrong format for gid prefix:%s\n", p_prefix);
 
109
    return TCL_ERROR;
 
110
  }
 
111
 
 
112
  temp.unicast.interface_id = cl_hton64(strtoull(p_guid, NULL, 16));
 
113
  if (errno) {
 
114
    printf("Wrong format for gid guid:%s\n", p_guid);
 
115
    return TCL_ERROR;
 
116
  }
 
117
 
 
118
  $target = &temp;
 
119
}
 
120
 
 
121
%typemap(tcl8,out) ib_gid_t* {
 
122
  char buff[36];
 
123
  sprintf(buff, "0x%016" PRIx64 ":0x%016" PRIx64,
 
124
          cl_ntoh64($source->unicast.prefix),
 
125
          cl_ntoh64($source->unicast.interface_id)
 
126
          );
 
127
  Tcl_SetStringObj($target,buff,strlen(buff));
 
128
}
 
129
 
 
130
%typemap(tcl8,out) ib_vl_arb_table_t* {
 
131
  char buff[256];
 
132
  int i;
 
133
  if ($source != NULL)
 
134
  {
 
135
    for (i = 0; i < 32; i++)
 
136
    {
 
137
      sprintf(buff, "{0x%02x 0x%02x} ", $source->vl_entry[i].vl, $source->vl_entry[i].weight);
 
138
      Tcl_AppendToObj($target,buff,strlen(buff));
 
139
    }
 
140
  }
 
141
  else
 
142
  {
 
143
    Tcl_SetStringObj($target, "{0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0} {0 0}", -1);
 
144
  }
 
145
}
 
146
 
 
147
/* break the list of sub lists into vl weight ... */
 
148
%typemap(tcl8,in) ib_vl_arb_table_t* (ib_vl_arb_table_t tmp) {
 
149
  int i;
 
150
 
 
151
  int numEntries, numElements, code;
 
152
  const char **subListStrings, **elements;
 
153
 
 
154
  code = Tcl_SplitList(interp, Tcl_GetStringFromObj($source,NULL),
 
155
                                                          &numEntries, &subListStrings);
 
156
  if (code != TCL_OK) {
 
157
         printf("Wrong format for vl_arb_table should be list of lists:%s\n",
 
158
                          Tcl_GetStringFromObj($source,NULL));
 
159
         return TCL_ERROR;
 
160
  }
 
161
 
 
162
  memset(&tmp, 0, sizeof(ib_vl_arb_table_t));
 
163
  for (i = 0; i < numEntries; i++) {
 
164
         code = Tcl_SplitList(interp, subListStrings[i], &numElements, &elements);
 
165
         if (code != TCL_OK) {
 
166
                printf("Wrong format for vl_arb_table sublist:%s\n", subListStrings[i]);
 
167
                Tcl_Free((char *) subListStrings);
 
168
                return TCL_ERROR;
 
169
         }
 
170
         if (numElements != 2) {
 
171
                printf("Wrong format for vl_arb_table sublist:%s num elements:%d != 2\n",
 
172
                                 subListStrings[i], numElements);
 
173
                Tcl_Free((char *) elements);
 
174
                Tcl_Free((char *) subListStrings);
 
175
                return TCL_ERROR;
 
176
         }
 
177
         errno = 0;
 
178
         tmp.vl_entry[i].vl = strtoul(elements[0],NULL,0);
 
179
         if (errno) {
 
180
                printf("Wrong format for vl_arb_table sublist %d vl:%s\n",
 
181
                                 i, elements[0]);
 
182
                Tcl_Free((char *) elements);
 
183
                Tcl_Free((char *) subListStrings);
 
184
                return TCL_ERROR;
 
185
         }
 
186
         tmp.vl_entry[i].weight =  strtoul(elements[1],NULL,0);
 
187
         if (errno) {
 
188
                 printf("Wrong format for vl_arb_table sublist %d weight:%s\n",
 
189
                                  i, elements[1]);
 
190
                Tcl_Free((char *) elements);
 
191
                Tcl_Free((char *) subListStrings);
 
192
                return TCL_ERROR;
 
193
         }
 
194
         Tcl_Free((char *) elements);
 
195
  }
 
196
  Tcl_Free((char *) subListStrings);
 
197
 
 
198
  $target = &tmp;
 
199
}
 
200
 
 
201
%typemap(tcl8,out) ib_slvl_table_t* {
 
202
  char buff[64];
 
203
  int i;
 
204
  int entry;
 
205
  if ($source != NULL)
 
206
  {
 
207
    for (i = 0; i < 8; i++)
 
208
         {
 
209
                 entry = $source->raw_vl_by_sl[i];
 
210
                 sprintf(buff, "0x%02x 0x%02x ", ((entry & 0xf0) >> 4), (entry & 0xf));
 
211
                 Tcl_AppendToObj($target,buff,strlen(buff));
 
212
         }
 
213
  }
 
214
  else
 
215
  {
 
216
    Tcl_SetStringObj($target, "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ", -1);
 
217
  }
 
218
}
 
219
 
 
220
%typemap(tcl8,in) ib_slvl_table_t* (ib_slvl_table_t tmp) {
 
221
  int i;
 
222
  int entry, value;
 
223
  int numEntries, code;
 
224
  const char **subListStrings;
 
225
 
 
226
  code = Tcl_SplitList(interp, Tcl_GetStringFromObj($source,NULL),
 
227
                                                          &numEntries, &subListStrings);
 
228
  if (code != TCL_OK) {
 
229
         printf("Wrong format for ib_slvl_table_t should be list:%s\n",
 
230
                          Tcl_GetStringFromObj($source,NULL));
 
231
         return TCL_ERROR;
 
232
  }
 
233
  if (numEntries > 16) {
 
234
         printf("Maximal number of SL2VL entries is 16:%s\n",
 
235
                          Tcl_GetStringFromObj($source,NULL));
 
236
         Tcl_Free((char *) subListStrings);
 
237
         return TCL_ERROR;
 
238
  }
 
239
  memset(&tmp, 0, sizeof(ib_slvl_table_t));
 
240
  for (i = 0; i < numEntries; i++) {
 
241
          errno = 0;
 
242
          value = strtoul(subListStrings[i],NULL,0);
 
243
          if (errno) {
 
244
                  printf("Wrong format for vl_arb_table sublist %d vl:%s\n",
 
245
                                        i, subListStrings[i]);
 
246
                  Tcl_Free((char *) subListStrings);
 
247
                  return TCL_ERROR;
 
248
          }
 
249
          if (value > 15) {
 
250
                  printf("Given VL at index %d is %d > 15\n", i, value);
 
251
                  Tcl_Free((char *) subListStrings);
 
252
                  return TCL_ERROR;
 
253
          }
 
254
          entry = tmp.raw_vl_by_sl[i/2];
 
255
          if (i % 2) {
 
256
                  entry = (value & 0xf) | (entry & 0xf0) ;
 
257
          } else {
 
258
                  entry = ((value & 0xf) << 4) | (entry & 0xf);
 
259
          }
 
260
          tmp.raw_vl_by_sl[i/2] = entry;
 
261
  }
 
262
  Tcl_Free((char *) subListStrings);
 
263
 
 
264
  $target = &tmp;
 
265
}
 
266
 
 
267
%typemap(tcl8,out) ib_pkey_table_t* {
 
268
  char buff[36];
 
269
  int i;
 
270
  if ($source != NULL)
 
271
  {
 
272
    for (i = 0; i < 32; i++)
 
273
    {
 
274
      sprintf(buff, "0x%04x ", cl_ntoh16($source->pkey_entry[i]));
 
275
      Tcl_AppendToObj($target,buff,strlen(buff));
 
276
    }
 
277
  }
 
278
  else
 
279
  {
 
280
    Tcl_SetStringObj($target, "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", 64);
 
281
  }
 
282
}
 
283
 
 
284
%typemap(tcl8,in) ib_pkey_table_t* (ib_pkey_table_t tmp) {
 
285
  char buf[256];
 
286
  char *p_pkey;
 
287
  char *str_token;
 
288
  int i = 0;
 
289
  memset(&tmp, 0, sizeof(ib_pkey_table_t));
 
290
 
 
291
  strncpy(buf, Tcl_GetStringFromObj($source,NULL), 255);
 
292
  buf[255] = '\0';
 
293
  p_pkey = strtok_r(buf," ", &str_token);
 
294
  while (p_pkey && (i < 32))
 
295
  {
 
296
    errno = 0;
 
297
    tmp.pkey_entry[i++] = cl_hton16(strtoul(p_pkey, NULL, 0));
 
298
    if (errno) {
 
299
      printf("Wrong format for pkey:%s\n", p_pkey);
 
300
      return TCL_ERROR;
 
301
    }
 
302
 
 
303
    p_pkey = strtok_r(NULL," ", &str_token);
 
304
  }
 
305
  $target = &tmp;
 
306
}
 
307
 
 
308
%typemap(tcl8,out) ib_mft_table_t* {
 
309
  char buff[36];
 
310
  int i;
 
311
  for (i = 0; i < IB_MCAST_BLOCK_SIZE; i++)
 
312
  {
 
313
    sprintf(buff, "0x%04x ", cl_ntoh16($source->mft_entry[i]));
 
314
    Tcl_AppendToObj($target,buff,strlen(buff));
 
315
  }
 
316
}
 
317
 
 
318
%typemap(tcl8,ignore) ib_mft_table_t *OUTPUT(ib_mft_table_t temp) {
 
319
  $target = &temp;
 
320
}
 
321
 
 
322
%typemap(tcl8,argout) ib_mft_table_t *OUTPUT {
 
323
  /* Argout ib_mft_table_t */
 
324
  char buff[36];
 
325
  int i;
 
326
  /* HACK if we did not have the result show an error ... */
 
327
  if (!_result)
 
328
  {
 
329
    /* we need to cleanup the result 0 ... */
 
330
    Tcl_ResetResult(interp);
 
331
    for (i = 0; i < IB_MCAST_BLOCK_SIZE; i++)
 
332
    {
 
333
      sprintf(buff, "0x%04x ", cl_ntoh16($source->mft_entry[i]));
 
334
      Tcl_AppendToObj($target,buff,strlen(buff));
 
335
    }
 
336
  }
 
337
}
 
338
 
 
339
%typemap(tcl8,in) ib_mft_table_t* (ib_mft_table_t tmp) {
 
340
  char buf[256];
 
341
  char *p_mftEntry;
 
342
  char *str_token;
 
343
  int i = 0;
 
344
 
 
345
  strncpy(buf, Tcl_GetStringFromObj($source,NULL), 255);
 
346
  buf[255] = '\0';
 
347
  p_mftEntry = strtok_r(buf," ", &str_token);
 
348
  while (p_mftEntry && (i < IB_MCAST_BLOCK_SIZE))
 
349
  {
 
350
    errno = 0;
 
351
    tmp.mft_entry[i++] = cl_hton16(strtoul(p_mftEntry, NULL, 0));
 
352
    if (errno) {
 
353
      printf("Wrong format for MFT Entry:%s\n", p_mftEntry);
 
354
      return TCL_ERROR;
 
355
    }
 
356
 
 
357
    p_mftEntry = strtok_r(NULL," ", &str_token);
 
358
  }
 
359
  while (i < IB_MCAST_BLOCK_SIZE)
 
360
  {
 
361
    tmp.mft_entry[i++] = 0;
 
362
  }
 
363
  $target = &tmp;
 
364
}
 
365
 
 
366
%{
 
367
#define uint8_array_t uint8_t
 
368
%}
 
369
%typemap(memberin)  uint8_array_t[ANY] {
 
370
        int i;
 
371
        for (i=0; i <$dim0 ; i++) {
 
372
                $target[i] = *($source+i);
 
373
        }
 
374
}
 
375
 
 
376
%{
 
377
#define uint32_array_t uint32_t
 
378
%}
 
379
%typemap(memberin)  uint32_array_t[ANY] {
 
380
        int i;
 
381
        for (i=0; i <$dim0 ; i++) {
 
382
                $target[i] = *($source+i);
 
383
        }
 
384
}
 
385
 
 
386
typedef struct _ib_node_info
 
387
{
 
388
        uint8_t                         base_version;
 
389
        uint8_t                         class_version;
 
390
        uint8_t                         node_type;
 
391
        uint8_t                         num_ports;
 
392
        ib_net64_t                      sys_guid;
 
393
        ib_net64_t                      node_guid;
 
394
        ib_net64_t                      port_guid;
 
395
        ib_net16_t                      partition_cap;
 
396
        ib_net16_t                      device_id;
 
397
        ib_net32_t                      revision;
 
398
        ib_net32_t                      port_num_vendor_id;
 
399
} ib_node_info_t;
 
400
 
 
401
typedef struct _ib_switch_info
 
402
{
 
403
        ib_net16_t                      lin_cap;
 
404
        ib_net16_t                      rand_cap;
 
405
        ib_net16_t                      mcast_cap;
 
406
        ib_net16_t                      lin_top;
 
407
        uint8_t                         def_port;
 
408
        uint8_t                         def_mcast_pri_port;
 
409
        uint8_t                         def_mcast_not_port;
 
410
        uint8_t                         life_state;
 
411
        ib_net16_t                      lids_per_port;
 
412
        ib_net16_t                      enforce_cap;
 
413
        uint8_t                         flags;
 
414
 
 
415
} ib_switch_info_t;
 
416
 
 
417
typedef struct _ib_port_info
 
418
{
 
419
        ib_net64_t                      m_key;
 
420
        ib_net64_t                      subnet_prefix;
 
421
        ib_net16_t                      base_lid;
 
422
        ib_net16_t                      master_sm_base_lid;
 
423
        ib_net32_t                      capability_mask;
 
424
        ib_net16_t                      diag_code;
 
425
        ib_net16_t                      m_key_lease_period;
 
426
        uint8_t                         local_port_num;
 
427
        uint8_t                         link_width_enabled;
 
428
        uint8_t                         link_width_supported;
 
429
        uint8_t                         link_width_active;
 
430
        uint8_t                         state_info1; // LinkSpeedSupported and PortState
 
431
        uint8_t                         state_info2; // PortPhysState and LinkDownDefaultState
 
432
        uint8_t                         mkey_lmc;
 
433
        uint8_t                         link_speed;      // LinkSpeedEnabled and LinkSpeedActive
 
434
        uint8_t                         mtu_smsl;
 
435
        uint8_t                         vl_cap;          // VlCap and InitType
 
436
        uint8_t                         vl_high_limit;
 
437
        uint8_t                         vl_arb_high_cap;
 
438
        uint8_t                         vl_arb_low_cap;
 
439
        uint8_t                         mtu_cap;
 
440
        uint8_t                         vl_stall_life;
 
441
        uint8_t                         vl_enforce;
 
442
        ib_net16_t                      m_key_violations;
 
443
        ib_net16_t                      p_key_violations;
 
444
        ib_net16_t                      q_key_violations;
 
445
        uint8_t                         guid_cap;
 
446
        uint8_t                         subnet_timeout;
 
447
        uint8_t                         resp_time_value;
 
448
        uint8_t                         error_threshold;
 
449
} ib_port_info_t;
 
450
 
 
451
typedef struct _ib_node_desc
 
452
{
 
453
        // Node String is an array of UTF-8 character that
 
454
        // describes the node in text format
 
455
        // Note that this string is NOT NULL TERMINATED!
 
456
        uint8_array_t description[IB_NODE_DESCRIPTION_SIZE];
 
457
} ib_node_desc_t;
 
458
 
 
459
typedef struct _ib_lft_record
 
460
{
 
461
        ib_net16_t              lid;
 
462
        ib_net16_t              block_num;
 
463
        uint32_t                   resv0;
 
464
        uint8_array_t  lft[64];
 
465
} ib_lft_record_t;
 
466
 
 
467
typedef struct _ib_pm_counters {
 
468
  ib_mad_t mad_header;
 
469
  uint32_array_t reserved0[10];
 
470
  uint8_t reserved1;
 
471
  uint8_t port_select;
 
472
  ib_net16_t counter_select;
 
473
  ib_net16_t symbol_error_counter;
 
474
  uint8_t link_error_recovery_counter;
 
475
  uint8_t link_down_counter;
 
476
  ib_net16_t port_rcv_errors;
 
477
  ib_net16_t port_rcv_remote_physical_errors;
 
478
  ib_net16_t port_rcv_switch_relay_errors;
 
479
  ib_net16_t port_xmit_discard;
 
480
  uint8_t port_xmit_constraint_errors;
 
481
  uint8_t port_rcv_constraint_errors;
 
482
  uint8_t reserved2;
 
483
  uint8_t lli_errors_exc_buf_errors;
 
484
  ib_net16_t reserved3;
 
485
  ib_net16_t vl15_dropped;
 
486
  ib_net32_t port_xmit_data;
 
487
  ib_net32_t port_rcv_data;
 
488
  ib_net32_t port_xmit_pkts;
 
489
  ib_net32_t port_rcv_pkts;
 
490
  uint32_array_t reserved5[38];
 
491
} ib_pm_counters_t;