2
* Copyright (c) 2004 Mellanox Technologies LTD. All rights reserved.
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:
10
* Redistribution and use in source and binary forms, with or
11
* without modification, are permitted provided that the following
14
* - Redistributions of source code must retain the above
15
* copyright notice, this list of conditions and the following
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.
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
35
/* Holds ib_types.h MAD structs in and out TypeMaps */
38
/* for IB structs we use the format: <type>:<ptr> */
40
/* Given the Object Pointer and Type provide it's TCL name */
41
int ibmsGetIBStructObjNameByPtr(Tcl_Obj *objPtr, void *ptr, char *type) {
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);
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);
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);
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. */
74
strcpy(buf, Tcl_GetStringFromObj(objPtr,0));
76
/* the format is always: <type>:<idx>[:<name>] */
78
/* first separate the type */
79
colonIdx = index(buf,':');
81
printf("-E- Bad formatted (no :) ibdm object:%s\n", buf);
87
/* now all we need is to extract the pointer value from the
89
if (sscanf(colonIdx,"%p", ptr) != 1) {
90
printf("-E- Bad formatted pointer value:%s\n", colonIdx);
97
%typemap(tcl8,in) ib_gid_t*(ib_gid_t temp) {
99
char *p_prefix, *p_guid;
102
strcpy(buf, Tcl_GetStringFromObj($source,NULL));
103
p_prefix = strtok_r(buf,":", &str_token);
104
p_guid = strtok_r(NULL, " ", &str_token);
106
temp.unicast.prefix = cl_hton64(strtoull(p_prefix, NULL, 16));
108
printf("Wrong format for gid prefix:%s\n", p_prefix);
112
temp.unicast.interface_id = cl_hton64(strtoull(p_guid, NULL, 16));
114
printf("Wrong format for gid guid:%s\n", p_guid);
121
%typemap(tcl8,out) ib_gid_t* {
123
sprintf(buff, "0x%016" PRIx64 ":0x%016" PRIx64,
124
cl_ntoh64($source->unicast.prefix),
125
cl_ntoh64($source->unicast.interface_id)
127
Tcl_SetStringObj($target,buff,strlen(buff));
130
%typemap(tcl8,out) ib_vl_arb_table_t* {
135
for (i = 0; i < 32; i++)
137
sprintf(buff, "{0x%02x 0x%02x} ", $source->vl_entry[i].vl, $source->vl_entry[i].weight);
138
Tcl_AppendToObj($target,buff,strlen(buff));
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);
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) {
151
int numEntries, numElements, code;
152
const char **subListStrings, **elements;
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));
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);
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);
178
tmp.vl_entry[i].vl = strtoul(elements[0],NULL,0);
180
printf("Wrong format for vl_arb_table sublist %d vl:%s\n",
182
Tcl_Free((char *) elements);
183
Tcl_Free((char *) subListStrings);
186
tmp.vl_entry[i].weight = strtoul(elements[1],NULL,0);
188
printf("Wrong format for vl_arb_table sublist %d weight:%s\n",
190
Tcl_Free((char *) elements);
191
Tcl_Free((char *) subListStrings);
194
Tcl_Free((char *) elements);
196
Tcl_Free((char *) subListStrings);
201
%typemap(tcl8,out) ib_slvl_table_t* {
207
for (i = 0; i < 8; i++)
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));
216
Tcl_SetStringObj($target, "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ", -1);
220
%typemap(tcl8,in) ib_slvl_table_t* (ib_slvl_table_t tmp) {
223
int numEntries, code;
224
const char **subListStrings;
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));
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);
239
memset(&tmp, 0, sizeof(ib_slvl_table_t));
240
for (i = 0; i < numEntries; i++) {
242
value = strtoul(subListStrings[i],NULL,0);
244
printf("Wrong format for vl_arb_table sublist %d vl:%s\n",
245
i, subListStrings[i]);
246
Tcl_Free((char *) subListStrings);
250
printf("Given VL at index %d is %d > 15\n", i, value);
251
Tcl_Free((char *) subListStrings);
254
entry = tmp.raw_vl_by_sl[i/2];
256
entry = (value & 0xf) | (entry & 0xf0) ;
258
entry = ((value & 0xf) << 4) | (entry & 0xf);
260
tmp.raw_vl_by_sl[i/2] = entry;
262
Tcl_Free((char *) subListStrings);
267
%typemap(tcl8,out) ib_pkey_table_t* {
272
for (i = 0; i < 32; i++)
274
sprintf(buff, "0x%04x ", cl_ntoh16($source->pkey_entry[i]));
275
Tcl_AppendToObj($target,buff,strlen(buff));
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);
284
%typemap(tcl8,in) ib_pkey_table_t* (ib_pkey_table_t tmp) {
289
memset(&tmp, 0, sizeof(ib_pkey_table_t));
291
strncpy(buf, Tcl_GetStringFromObj($source,NULL), 255);
293
p_pkey = strtok_r(buf," ", &str_token);
294
while (p_pkey && (i < 32))
297
tmp.pkey_entry[i++] = cl_hton16(strtoul(p_pkey, NULL, 0));
299
printf("Wrong format for pkey:%s\n", p_pkey);
303
p_pkey = strtok_r(NULL," ", &str_token);
308
%typemap(tcl8,out) ib_mft_table_t* {
311
for (i = 0; i < IB_MCAST_BLOCK_SIZE; i++)
313
sprintf(buff, "0x%04x ", cl_ntoh16($source->mft_entry[i]));
314
Tcl_AppendToObj($target,buff,strlen(buff));
318
%typemap(tcl8,ignore) ib_mft_table_t *OUTPUT(ib_mft_table_t temp) {
322
%typemap(tcl8,argout) ib_mft_table_t *OUTPUT {
323
/* Argout ib_mft_table_t */
326
/* HACK if we did not have the result show an error ... */
329
/* we need to cleanup the result 0 ... */
330
Tcl_ResetResult(interp);
331
for (i = 0; i < IB_MCAST_BLOCK_SIZE; i++)
333
sprintf(buff, "0x%04x ", cl_ntoh16($source->mft_entry[i]));
334
Tcl_AppendToObj($target,buff,strlen(buff));
339
%typemap(tcl8,in) ib_mft_table_t* (ib_mft_table_t tmp) {
345
strncpy(buf, Tcl_GetStringFromObj($source,NULL), 255);
347
p_mftEntry = strtok_r(buf," ", &str_token);
348
while (p_mftEntry && (i < IB_MCAST_BLOCK_SIZE))
351
tmp.mft_entry[i++] = cl_hton16(strtoul(p_mftEntry, NULL, 0));
353
printf("Wrong format for MFT Entry:%s\n", p_mftEntry);
357
p_mftEntry = strtok_r(NULL," ", &str_token);
359
while (i < IB_MCAST_BLOCK_SIZE)
361
tmp.mft_entry[i++] = 0;
367
#define uint8_array_t uint8_t
369
%typemap(memberin) uint8_array_t[ANY] {
371
for (i=0; i <$dim0 ; i++) {
372
$target[i] = *($source+i);
377
#define uint32_array_t uint32_t
379
%typemap(memberin) uint32_array_t[ANY] {
381
for (i=0; i <$dim0 ; i++) {
382
$target[i] = *($source+i);
386
typedef struct _ib_node_info
388
uint8_t base_version;
389
uint8_t class_version;
393
ib_net64_t node_guid;
394
ib_net64_t port_guid;
395
ib_net16_t partition_cap;
396
ib_net16_t device_id;
398
ib_net32_t port_num_vendor_id;
401
typedef struct _ib_switch_info
405
ib_net16_t mcast_cap;
408
uint8_t def_mcast_pri_port;
409
uint8_t def_mcast_not_port;
411
ib_net16_t lids_per_port;
412
ib_net16_t enforce_cap;
417
typedef struct _ib_port_info
420
ib_net64_t subnet_prefix;
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
433
uint8_t link_speed; // LinkSpeedEnabled and LinkSpeedActive
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;
440
uint8_t vl_stall_life;
442
ib_net16_t m_key_violations;
443
ib_net16_t p_key_violations;
444
ib_net16_t q_key_violations;
446
uint8_t subnet_timeout;
447
uint8_t resp_time_value;
448
uint8_t error_threshold;
451
typedef struct _ib_node_desc
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];
459
typedef struct _ib_lft_record
462
ib_net16_t block_num;
464
uint8_array_t lft[64];
467
typedef struct _ib_pm_counters {
469
uint32_array_t reserved0[10];
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;
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];