Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

   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
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
/*
 * Copyright (c) 2004-2009 Voltaire, Inc. All rights reserved.
 * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
 * Copyright (c) 1996-2003 Intel Corporation. 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.
 *
 */

/*
 * Abstract:
 *    Implementation of osm_req_t.
 * This object represents the generic attribute requester.
 * This object is part of the opensm family of objects.
 *
 */

/*
  Next available error code: 0x300
*/

#if HAVE_CONFIG_H
#  include <config.h>
#endif				/* HAVE_CONFIG_H */

#ifdef OSM_VENDOR_INTF_AL

#include <stdlib.h>
#include <string.h>
#include <complib/cl_qlist.h>
#include <complib/cl_thread.h>
#include <complib/cl_math.h>
#include <complib/cl_debug.h>
#include <iba/ib_types.h>
#include <opensm/osm_madw.h>
#include <opensm/osm_log.h>
#include <opensm/osm_mad_pool.h>
#include <vendor/osm_vendor_api.h>

/****s* OpenSM: Vendor AL/osm_al_bind_info_t
 * NAME
 *   osm_al_bind_info_t
 *
 * DESCRIPTION
 *    Structure containing bind information.
 *
 * SYNOPSIS
 */
typedef struct _osm_al_bind_info {
	osm_vendor_t *p_vend;
	void *client_context;
	ib_qp_handle_t h_qp;
	ib_mad_svc_handle_t h_svc;
	uint8_t port_num;
	ib_pool_key_t pool_key;
	osm_vend_mad_recv_callback_t rcv_callback;
	osm_vend_mad_send_err_callback_t send_err_callback;
	osm_mad_pool_t *p_osm_pool;
	ib_av_handle_t h_dr_av;

} osm_al_bind_info_t;
/*
 * FIELDS
 * p_vend
 *    Pointer to the vendor object.
 *
 * client_context
 *    User's context passed during osm_bind
 *
 * h_qp
 *    Handle the QP for this bind.
 *
 * h_qp_svc
 *    Handle the QP mad service for this bind.
 *
 * port_num
 *    Port number (within the HCA) of the bound port.
 *
 * pool_key
 *    Pool key returned by all for this QP.
 *
 * h_dr_av
 *    Address vector handle used for all directed route SMPs.
 *
 * SEE ALSO
 *********/

inline static ib_api_status_t
__osm_al_convert_wcs(IN ib_wc_status_t const wc_status)
{
	switch (wc_status) {
	case IB_WCS_SUCCESS:
		return (IB_SUCCESS);

	case IB_WCS_TIMEOUT_RETRY_ERR:
		return (IB_TIMEOUT);

	default:
		return (IB_ERROR);
	}
}

static void __osm_al_ca_err_callback(IN ib_async_event_rec_t * p_async_rec)
{
	osm_vendor_t *p_vend = (osm_vendor_t *) p_async_rec->context;
	OSM_LOG_ENTER(p_vend->p_log);

	osm_log(p_vend->p_log, OSM_LOG_ERROR,
		"__osm_al_ca_err_callback: ERR 3B01: "
		"Event on channel adapter (%s).\n",
		ib_get_async_event_str(p_async_rec->code));

	OSM_LOG_EXIT(p_vend->p_log);
}

static void __osm_al_ca_destroy_callback(IN void *context)
{
	osm_al_bind_info_t *p_bind = (osm_al_bind_info_t *) context;
	osm_vendor_t *p_vend = p_bind->p_vend;
	OSM_LOG_ENTER(p_vend->p_log);

	osm_log(p_vend->p_log, OSM_LOG_INFO,
		"__osm_al_ca_destroy_callback: "
		"Closing local channel adapter.\n");

	OSM_LOG_EXIT(p_vend->p_log);
}

static void __osm_al_err_callback(IN ib_async_event_rec_t * p_async_rec)
{
	osm_al_bind_info_t *p_bind =
	    (osm_al_bind_info_t *) p_async_rec->context;
	osm_vendor_t *p_vend = p_bind->p_vend;
	OSM_LOG_ENTER(p_vend->p_log);

	osm_log(p_vend->p_log, OSM_LOG_ERROR,
		"__osm_al_err_callback: ERR 3B02: "
		"Error on QP (%s).\n",
		ib_get_async_event_str(p_async_rec->code));

	OSM_LOG_EXIT(p_vend->p_log);
}

static void
__osm_al_send_callback(IN void *mad_svc_context, IN ib_mad_element_t * p_elem)
{
	osm_al_bind_info_t *const p_bind =
	    (osm_al_bind_info_t *) mad_svc_context;
	osm_vendor_t *const p_vend = p_bind->p_vend;
	osm_madw_t *const p_madw = (osm_madw_t *) p_elem->context1;
	osm_vend_wrap_t *const p_vw = osm_madw_get_vend_ptr(p_madw);
	ib_mad_t *p_mad;

	OSM_LOG_ENTER(p_vend->p_log);

	CL_ASSERT(p_vw);
	CL_ASSERT(p_vw->h_av);

	/*
	   Destroy the address vector as necessary.
	 */
	if (p_vw->h_av != p_bind->h_dr_av) {
		if (osm_log_is_active(p_vend->p_log, OSM_LOG_DEBUG)) {
			osm_log(p_vend->p_log, OSM_LOG_DEBUG,
				"__osm_al_send_callback: "
				"Destroying av handle %p.\n", p_vw->h_av);
		}

		ib_destroy_av(p_vw->h_av);
	}

	p_mad = ib_get_mad_buf(p_elem);

	if (p_elem->resp_expected) {
		/*
		   If the send was unsuccessful, notify the user
		   for MADs that were expecting a response.
		   A NULL mad wrapper parameter is the user's clue
		   that the transaction turned sour.

		   Otherwise, do nothing for successful sends when a
		   reponse is expected.  The mad will be returned to the
		   pool later.
		 */
		p_madw->status = __osm_al_convert_wcs(p_elem->status);
		if (p_elem->status != IB_WCS_SUCCESS) {
			osm_log(p_vend->p_log, OSM_LOG_DEBUG,
				"__osm_al_send_callback: "
				"MAD completed with work queue error: %s.\n",
				ib_get_wc_status_str(p_elem->status));
			/*
			   Return any wrappers to the pool that may have been
			   pre-emptively allocated to handle a receive.
			 */
			if (p_vw->p_resp_madw) {
				osm_mad_pool_put(p_bind->p_osm_pool,
						 p_vw->p_resp_madw);
				p_vw->p_resp_madw = NULL;
			}

			p_bind->send_err_callback(p_bind->client_context,
						  p_madw);
		}
	} else {
		osm_log(p_vend->p_log, OSM_LOG_DEBUG,
			"__osm_al_send_callback: "
			"Returning MAD to pool, TID = 0x%" PRIx64 ".\n",
			cl_ntoh64(p_mad->trans_id));
		osm_mad_pool_put(p_bind->p_osm_pool, p_madw);
		goto Exit;
	}

Exit:
	OSM_LOG_EXIT(p_vend->p_log);
}

static void
__osm_al_rcv_callback(IN void *mad_svc_context, IN ib_mad_element_t * p_elem)
{
	osm_al_bind_info_t *const p_bind =
	    (osm_al_bind_info_t *) mad_svc_context;
	osm_vendor_t *const p_vend = p_bind->p_vend;
	osm_madw_t *p_old_madw;
	osm_madw_t *p_new_madw;
	osm_vend_wrap_t *p_old_vw;
	osm_vend_wrap_t *p_new_vw;
	ib_mad_t *p_new_mad;
	osm_mad_addr_t mad_addr;

	OSM_LOG_ENTER(p_vend->p_log);

	CL_ASSERT(p_elem->context1 == NULL);
	CL_ASSERT(p_elem->context2 == NULL);

	p_new_mad = ib_get_mad_buf(p_elem);

	/*
	   In preperation for initializing the new mad wrapper,
	   Initialize the mad_addr structure for the received wire MAD.
	 */
	mad_addr.dest_lid = p_elem->remote_lid;
	mad_addr.path_bits = p_elem->path_bits;

	/* TO DO - figure out which #define to use for the 2.5 Gb rate... */
	mad_addr.static_rate = 0;

	if (p_new_mad->mgmt_class == IB_MCLASS_SUBN_LID ||
	    p_new_mad->mgmt_class == IB_MCLASS_SUBN_DIR) {
		mad_addr.addr_type.smi.source_lid = p_elem->remote_lid;
	} else {
		mad_addr.addr_type.gsi.remote_qp = p_elem->remote_qp;
		mad_addr.addr_type.gsi.remote_qkey = p_elem->remote_qkey;
		mad_addr.addr_type.gsi.pkey_ix = p_elem->pkey_index;
		mad_addr.addr_type.gsi.service_level = p_elem->remote_sl;
		mad_addr.addr_type.gsi.global_route = FALSE;
	}

	/*
	   If this MAD is a response to a previous request,
	   then grab our pre-allocated MAD wrapper.
	   Otherwise, allocate a new MAD wrapper.
	 */
	if (ib_mad_is_response(p_new_mad)) {
		CL_ASSERT(p_elem->send_context1 != NULL);
		CL_ASSERT(p_elem->send_context2 == NULL);

		p_old_madw = (osm_madw_t *) p_elem->send_context1;
		p_old_vw = osm_madw_get_vend_ptr(p_old_madw);
		p_new_madw = p_old_vw->p_resp_madw;

		CL_ASSERT(p_new_madw);

		osm_madw_init(p_new_madw, p_bind, p_elem->size, &mad_addr);
		osm_madw_set_mad(p_new_madw, p_new_mad);
	} else {
		CL_ASSERT(p_elem->send_context1 == NULL);
		CL_ASSERT(p_elem->send_context2 == NULL);

		p_new_madw = osm_mad_pool_get_wrapper(p_bind->p_osm_pool,
						      p_bind, p_elem->size,
						      p_new_mad, &mad_addr);
	}

	CL_ASSERT(p_new_madw);
	p_new_vw = osm_madw_get_vend_ptr(p_new_madw);

	p_new_vw->h_bind = p_bind;
	p_new_vw->size = p_elem->size;
	p_new_vw->p_elem = p_elem;
	p_new_vw->h_av = 0;
	p_new_vw->p_resp_madw = NULL;

	osm_log(p_vend->p_log, OSM_LOG_DEBUG,
		"__osm_al_rcv_callback: "
		"Calling receive callback function %p.\n",
		p_bind->rcv_callback);

	p_bind->rcv_callback(p_new_madw, p_bind->client_context,
			     p_elem->send_context1);

	OSM_LOG_EXIT(p_vend->p_log);
}

ib_api_status_t
osm_vendor_init(IN osm_vendor_t * const p_vend,
		IN osm_log_t * const p_log, IN const uint32_t timeout)
{
	ib_api_status_t status;
	OSM_LOG_ENTER(p_log);

	p_vend->p_log = p_log;

	/*
	   Open our instance of AL.
	 */
	status = ib_open_al(&p_vend->h_al);
	if (status != IB_SUCCESS) {
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"osm_vendor_init: ERR 3B03: "
			"Error opening AL (%s).\n", ib_get_err_str(status));

		goto Exit;
	}

	p_vend->timeout = timeout;

Exit:
	OSM_LOG_EXIT(p_log);
	return (status);
}

osm_vendor_t *osm_vendor_new(IN osm_log_t * const p_log,
			     IN const uint32_t timeout)
{
	ib_api_status_t status;
	osm_vendor_t *p_vend;

	OSM_LOG_ENTER(p_log);

	p_vend = malloc(sizeof(*p_vend));
	if (p_vend == NULL) {
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"osm_vendor_new: ERR 3B04: "
			"Unable to allocate vendor object.\n");
		goto Exit;
	}

	memset(p_vend, 0, sizeof(*p_vend));

	status = osm_vendor_init(p_vend, p_log, timeout);
	if (status != IB_SUCCESS) {
		free(p_vend);
		p_vend = NULL;
	}

Exit:
	OSM_LOG_EXIT(p_log);
	return (p_vend);
}

void osm_vendor_delete(IN osm_vendor_t ** const pp_vend)
{
	/* TO DO - fill this in */
	ib_close_al((*pp_vend)->h_al);
	free(*pp_vend);
	*pp_vend = NULL;
}

static ib_api_status_t
__osm_ca_info_init(IN osm_vendor_t * const p_vend,
		   IN osm_ca_info_t * const p_ca_info,
		   IN const ib_net64_t ca_guid)
{
	ib_api_status_t status;

	OSM_LOG_ENTER(p_vend->p_log);

	p_ca_info->guid = ca_guid;

	if (osm_log_is_active(p_vend->p_log, OSM_LOG_VERBOSE)) {
		osm_log(p_vend->p_log, OSM_LOG_VERBOSE,
			"__osm_ca_info_init: "
			"Querying CA 0x%" PRIx64 ".\n", cl_ntoh64(ca_guid));
	}

	status = ib_query_ca_by_guid(p_vend->h_al, ca_guid, NULL,
				     &p_ca_info->attr_size);
	if ((status != IB_INSUFFICIENT_MEMORY) && (status != IB_SUCCESS)) {
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"__osm_ca_info_init: ERR 3B05: "
			"Unexpected status getting CA attributes (%s).\n",
			ib_get_err_str(status));
		goto Exit;
	}

	CL_ASSERT(p_ca_info->attr_size);

	p_ca_info->p_attr = malloc(p_ca_info->attr_size);
	if (p_ca_info->p_attr == NULL) {
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"__osm_ca_info_init: ERR 3B06: "
			"Unable to allocate attribute storage.\n");
		goto Exit;
	}

	status = ib_query_ca_by_guid(p_vend->h_al, ca_guid, p_ca_info->p_attr,
				     &p_ca_info->attr_size);
	if (status != IB_SUCCESS) {
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"__osm_ca_info_init: ERR 3B07: "
			"Unexpected status getting CA attributes (%s).\n",
			ib_get_err_str(status));
		goto Exit;
	}

Exit:
	OSM_LOG_EXIT(p_vend->p_log);
	return (status);
}

void
osm_ca_info_destroy(IN osm_vendor_t * const p_vend,
		    IN osm_ca_info_t * const p_ca_info)
{
	OSM_LOG_ENTER(p_vend->p_log);

	if (p_ca_info->p_attr)
		free(p_ca_info->p_attr);

	free(p_ca_info);

	OSM_LOG_EXIT(p_vend->p_log);
}

osm_ca_info_t *osm_ca_info_new(IN osm_vendor_t * const p_vend,
			       IN const ib_net64_t ca_guid)
{
	ib_api_status_t status;
	osm_ca_info_t *p_ca_info;

	OSM_LOG_ENTER(p_vend->p_log);

	CL_ASSERT(ca_guid);

	p_ca_info = malloc(sizeof(*p_ca_info));
	if (p_ca_info == NULL)
		goto Exit;

	memset(p_ca_info, 0, sizeof(*p_ca_info));

	status = __osm_ca_info_init(p_vend, p_ca_info, ca_guid);
	if (status != IB_SUCCESS) {
		osm_ca_info_destroy(p_vend, p_ca_info);
		p_ca_info = NULL;
		goto Exit;
	}

Exit:
	OSM_LOG_EXIT(p_vend->p_log);
	return (p_ca_info);
}

static ib_api_status_t
__osm_vendor_get_ca_guids(IN osm_vendor_t * const p_vend,
			  IN ib_net64_t ** const p_guids,
			  IN unsigned * const p_num_guids)
{
	ib_api_status_t status;

	OSM_LOG_ENTER(p_vend->p_log);

	CL_ASSERT(p_guids);
	CL_ASSERT(p_num_guids);

	status = ib_get_ca_guids(p_vend->h_al, NULL, p_num_guids);
	if ((status != IB_INSUFFICIENT_MEMORY) && (status != IB_SUCCESS)) {
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"__osm_vendor_get_ca_guids: ERR 3B08: "
			"Unexpected status getting CA GUID array (%s).\n",
			ib_get_err_str(status));
		goto Exit;
	}

	if (*p_num_guids == 0) {
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"__osm_vendor_get_ca_guids: ERR 3B09: "
			"No available channel adapters.\n");
		status = IB_INSUFFICIENT_RESOURCES;
		goto Exit;
	}

	*p_guids = malloc(*p_num_guids * sizeof(**p_guids));
	if (*p_guids == NULL) {
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"__osm_vendor_get_ca_guids: ERR 3B10: "
			"Unable to allocate CA GUID array.\n");
		goto Exit;
	}

	status = ib_get_ca_guids(p_vend->h_al, *p_guids, p_num_guids);
	CL_ASSERT(*p_num_guids);

	if (osm_log_is_active(p_vend->p_log, OSM_LOG_VERBOSE)) {
		osm_log(p_vend->p_log, OSM_LOG_VERBOSE,
			"__osm_vendor_get_ca_guids: "
			"Detected %u local channel adapters.\n", *p_num_guids);
	}

Exit:
	OSM_LOG_EXIT(p_vend->p_log);
	return (status);
}

/****f* OpenSM: CA Info/osm_ca_info_get_pi_ptr
 * NAME
 * osm_ca_info_get_pi_ptr
 *
 * DESCRIPTION
 * Returns a pointer to the port attribute of the specified port
 * owned by this CA.
 *
 * SYNOPSIS
 */
static ib_port_attr_t *__osm_ca_info_get_port_attr_ptr(IN const osm_ca_info_t *
						       const p_ca_info,
						       IN const uint8_t index)
{
	return (&p_ca_info->p_attr->p_port_attr[index]);
}

/*
 * PARAMETERS
 * p_ca_info
 *    [in] Pointer to a CA Info object.
 *
 * index
 *    [in] Port "index" for which to retrieve the port attribute.
 *    The index is the offset into the ca's internal array
 *    of port attributes.
 *
 * RETURN VALUE
 * Returns a pointer to the port attribute of the specified port
 * owned by this CA.
 *
 * NOTES
 *
 * SEE ALSO
 *********/

ib_api_status_t
osm_vendor_get_all_port_attr(IN osm_vendor_t * const p_vend,
			     IN ib_port_attr_t * const p_attr_array,
			     IN uint32_t * const p_num_ports)
{
	ib_api_status_t status;

	uint32_t ca;
	unsigned ca_count;
	uint32_t port_count = 0;
	uint8_t port_num;
	uint32_t total_ports = 0;
	ib_net64_t *p_ca_guid = NULL;
	osm_ca_info_t *p_ca_info;

	OSM_LOG_ENTER(p_vend->p_log);

	CL_ASSERT(p_vend);
	CL_ASSERT(p_vend->p_ca_info == NULL);

	/*
	   1) Determine the number of CA's
	   2) Allocate an array big enough to hold the ca info objects.
	   3) Call again to retrieve the guids.
	 */
	status = __osm_vendor_get_ca_guids(p_vend, &p_ca_guid, &ca_count);

	p_vend->p_ca_info = malloc(ca_count * sizeof(*p_vend->p_ca_info));
	if (p_vend->p_ca_info == NULL) {
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"osm_vendor_get_all_port_attr: ERR 3B11: "
			"Unable to allocate CA information array.\n");
		goto Exit;
	}

	memset(p_vend->p_ca_info, 0, ca_count * sizeof(*p_vend->p_ca_info));
	p_vend->ca_count = ca_count;

	/*
	   For each CA, retrieve the port info attributes
	 */
	for (ca = 0; ca < ca_count; ca++) {
		p_ca_info = &p_vend->p_ca_info[ca];

		status = __osm_ca_info_init(p_vend, p_ca_info, p_ca_guid[ca]);

		if (status != IB_SUCCESS) {
			osm_log(p_vend->p_log, OSM_LOG_ERROR,
				"osm_vendor_get_all_port_attr: ERR 3B12: "
				"Unable to initialize CA Info object (%s).\n",
				ib_get_err_str(status));
		}

		total_ports += osm_ca_info_get_num_ports(p_ca_info);
	}

	/*
	   If the user supplied enough storage, return the port guids,
	   otherwise, return the appropriate error.
	 */
	if (*p_num_ports >= total_ports) {
		for (ca = 0; ca < ca_count; ca++) {
			uint32_t num_ports;

			p_ca_info = &p_vend->p_ca_info[ca];

			num_ports = osm_ca_info_get_num_ports(p_ca_info);

			for (port_num = 0; port_num < num_ports; port_num++) {
				p_attr_array[port_count] =
				    *__osm_ca_info_get_port_attr_ptr(p_ca_info,
								     port_num);
				port_count++;
			}
		}
	} else {
		status = IB_INSUFFICIENT_MEMORY;
	}

	*p_num_ports = total_ports;

Exit:
	if (p_ca_guid)
		free(p_ca_guid);

	OSM_LOG_EXIT(p_vend->p_log);
	return (status);
}

ib_net64_t
osm_vendor_get_ca_guid(IN osm_vendor_t * const p_vend,
		       IN const ib_net64_t port_guid)
{
	uint8_t index;
	uint8_t num_ports;
	uint32_t num_guids = 0;
	osm_ca_info_t *p_ca_info;
	uint32_t ca;

	OSM_LOG_ENTER(p_vend->p_log);

	CL_ASSERT(port_guid);
	/*
	   First, locate the HCA that owns this port.
	 */
	if (p_vend->p_ca_info == NULL) {
		/*
		   Initialize the osm_ca_info_t array which allows
		   us to match port GUID to CA.
		 */
		osm_vendor_get_all_port_attr(p_vend, NULL, &num_guids);
	}

	CL_ASSERT(p_vend->p_ca_info);
	CL_ASSERT(p_vend->ca_count);

	for (ca = 0; ca < p_vend->ca_count; ca++) {
		p_ca_info = &p_vend->p_ca_info[ca];

		num_ports = osm_ca_info_get_num_ports(p_ca_info);
		CL_ASSERT(num_ports);

		for (index = 0; index < num_ports; index++) {
			if (port_guid ==
			    osm_ca_info_get_port_guid(p_ca_info, index)) {
				OSM_LOG_EXIT(p_vend->p_log);
				return (osm_ca_info_get_ca_guid(p_ca_info));
			}
		}
	}

	/*
	   No local CA owns this guid!
	 */
	osm_log(p_vend->p_log, OSM_LOG_ERROR,
		"osm_vendor_get_ca_guid: ERR 3B13: "
		"Unable to determine CA guid.\n");

	OSM_LOG_EXIT(p_vend->p_log);
	return (0);
}

uint8_t
osm_vendor_get_port_num(IN osm_vendor_t * const p_vend,
			IN const ib_net64_t port_guid)
{
	uint8_t index;
	uint8_t num_ports;
	uint32_t num_guids = 0;
	osm_ca_info_t *p_ca_info;
	uint32_t ca;

	OSM_LOG_ENTER(p_vend->p_log);

	CL_ASSERT(port_guid);
	/*
	   First, locate the HCA that owns this port.
	 */
	if (p_vend->p_ca_info == NULL) {
		/*
		   Initialize the osm_ca_info_t array which allows
		   us to match port GUID to CA.
		 */
		osm_vendor_get_all_port_attr(p_vend, NULL, &num_guids);
	}

	CL_ASSERT(p_vend->p_ca_info);
	CL_ASSERT(p_vend->ca_count);

	for (ca = 0; ca < p_vend->ca_count; ca++) {
		p_ca_info = &p_vend->p_ca_info[ca];

		num_ports = osm_ca_info_get_num_ports(p_ca_info);
		CL_ASSERT(num_ports);

		for (index = 0; index < num_ports; index++) {
			if (port_guid ==
			    osm_ca_info_get_port_guid(p_ca_info, index)) {
				OSM_LOG_EXIT(p_vend->p_log);
				return (osm_ca_info_get_port_num
					(p_ca_info, index));
			}
		}
	}

	/*
	   No local CA owns this guid!
	 */
	osm_log(p_vend->p_log, OSM_LOG_ERROR,
		"osm_vendor_get_port_num: ERR 3B30: "
		"Unable to determine CA guid.\n");

	OSM_LOG_EXIT(p_vend->p_log);
	return (0);
}

static ib_api_status_t
__osm_vendor_open_ca(IN osm_vendor_t * const p_vend,
		     IN const ib_net64_t port_guid)
{
	ib_net64_t ca_guid;
	ib_api_status_t status;

	OSM_LOG_ENTER(p_vend->p_log);

	ca_guid = osm_vendor_get_ca_guid(p_vend, port_guid);
	if (ca_guid == 0) {
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"__osm_vendor_open_ca: ERR 3B31: "
			"Bad port GUID value 0x%" PRIx64 ".\n",
			cl_ntoh64(port_guid));
		status = IB_ERROR;
		goto Exit;
	}

	osm_log(p_vend->p_log, OSM_LOG_VERBOSE,
		"__osm_vendor_open_ca: "
		"Opening HCA 0x%" PRIx64 ".\n", cl_ntoh64(ca_guid));

	status = ib_open_ca(p_vend->h_al,
			    ca_guid,
			    __osm_al_ca_err_callback, p_vend, &p_vend->h_ca);

	if (status != IB_SUCCESS) {
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"__osm_vendor_open_ca: ERR 3B15: "
			"Unable to open CA (%s).\n", ib_get_err_str(status));
		goto Exit;
	}

	CL_ASSERT(p_vend->h_ca);

	status = ib_alloc_pd(p_vend->h_ca, IB_PDT_ALIAS, p_vend, &p_vend->h_pd);

	if (status != IB_SUCCESS) {
		ib_close_ca(p_vend->h_ca, __osm_al_ca_destroy_callback);
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"__osm_vendor_open_ca: ERR 3B16: "
			"Unable to allocate protection domain (%s).\n",
			ib_get_err_str(status));
		goto Exit;
	}

	CL_ASSERT(p_vend->h_pd);

Exit:
	OSM_LOG_EXIT(p_vend->p_log);
	return (status);
}

static void
__osm_vendor_init_av(IN const osm_al_bind_info_t * p_bind,
		     IN ib_av_attr_t * p_av)
{
	memset(p_av, 0, sizeof(*p_av));
	p_av->port_num = p_bind->port_num;
	p_av->dlid = IB_LID_PERMISSIVE;
}

osm_bind_handle_t
osm_vendor_bind(IN osm_vendor_t * const p_vend,
		IN osm_bind_info_t * const p_user_bind,
		IN osm_mad_pool_t * const p_mad_pool,
		IN osm_vend_mad_recv_callback_t mad_recv_callback,
		IN osm_vend_mad_send_err_callback_t send_err_callback,
		IN void *context)
{
	ib_net64_t port_guid;
	osm_al_bind_info_t *p_bind = 0;
	ib_api_status_t status;
	ib_qp_create_t qp_create;
	ib_mad_svc_t mad_svc;
	ib_av_attr_t av;

	OSM_LOG_ENTER(p_vend->p_log);

	CL_ASSERT(p_user_bind);
	CL_ASSERT(p_mad_pool);
	CL_ASSERT(mad_recv_callback);
	CL_ASSERT(send_err_callback);

	port_guid = p_user_bind->port_guid;

	osm_log(p_vend->p_log, OSM_LOG_INFO,
		"osm_vendor_bind: "
		"Binding to port 0x%" PRIx64 ".\n", cl_ntoh64(port_guid));

	if (p_vend->h_ca == 0) {
		osm_log(p_vend->p_log, OSM_LOG_DEBUG,
			"osm_vendor_bind: "
			"Opening CA that owns port 0x%" PRIx64 ".\n",
			port_guid);

		status = __osm_vendor_open_ca(p_vend, port_guid);
		if (status != IB_SUCCESS) {
			osm_log(p_vend->p_log, OSM_LOG_ERROR,
				"osm_vendor_bind: ERR 3B17: "
				"Unable to Open CA (%s).\n",
				ib_get_err_str(status));
			goto Exit;
		}
	}

	p_bind = malloc(sizeof(*p_bind));
	if (p_bind == NULL) {
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"osm_vendor_bind: ERR 3B18: "
			"Unable to allocate internal bind object.\n");
		goto Exit;
	}

	memset(p_bind, 0, sizeof(*p_bind));
	p_bind->p_vend = p_vend;
	p_bind->client_context = context;
	p_bind->port_num = osm_vendor_get_port_num(p_vend, port_guid);
	p_bind->rcv_callback = mad_recv_callback;
	p_bind->send_err_callback = send_err_callback;
	p_bind->p_osm_pool = p_mad_pool;

	CL_ASSERT(p_bind->port_num);

	/*
	   Get the proper QP.
	 */
	memset(&qp_create, 0, sizeof(qp_create));

	switch (p_user_bind->mad_class) {
	case IB_MCLASS_SUBN_LID:
	case IB_MCLASS_SUBN_DIR:
		qp_create.qp_type = IB_QPT_QP0_ALIAS;
		break;

	case IB_MCLASS_SUBN_ADM:
	default:
		qp_create.qp_type = IB_QPT_QP1_ALIAS;
		break;
	}

	qp_create.sq_depth = p_user_bind->send_q_size;
	qp_create.rq_depth = p_user_bind->recv_q_size;
	qp_create.sq_sge = OSM_AL_SQ_SGE;
	qp_create.rq_sge = OSM_AL_RQ_SGE;

	status = ib_get_spl_qp(p_vend->h_pd,
			       port_guid,
			       &qp_create,
			       p_bind,
			       __osm_al_err_callback,
			       &p_bind->pool_key, &p_bind->h_qp);

	if (status != IB_SUCCESS) {
		free(p_bind);
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"osm_vendor_bind: ERR 3B19: "
			"Unable to get QP handle (%s).\n",
			ib_get_err_str(status));
		goto Exit;
	}

	CL_ASSERT(p_bind->h_qp);
	CL_ASSERT(p_bind->pool_key);

	memset(&mad_svc, 0, sizeof(mad_svc));

	mad_svc.mad_svc_context = p_bind;
	mad_svc.pfn_mad_send_cb = __osm_al_send_callback;
	mad_svc.pfn_mad_recv_cb = __osm_al_rcv_callback;
	mad_svc.mgmt_class = p_user_bind->mad_class;
	mad_svc.mgmt_version = p_user_bind->class_version;
	mad_svc.support_unsol = p_user_bind->is_responder;
	mad_svc.method_array[IB_MAD_METHOD_GET] = TRUE;
	mad_svc.method_array[IB_MAD_METHOD_SET] = TRUE;
	mad_svc.method_array[IB_MAD_METHOD_DELETE] = TRUE;
	mad_svc.method_array[IB_MAD_METHOD_TRAP] = TRUE;
	mad_svc.method_array[IB_MAD_METHOD_GETTABLE] = TRUE;

	status = ib_reg_mad_svc(p_bind->h_qp, &mad_svc, &p_bind->h_svc);

	if (status != IB_SUCCESS) {
		free(p_bind);
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"osm_vendor_bind: ERR 3B21: "
			"Unable to register QP0 MAD service (%s).\n",
			ib_get_err_str(status));
		goto Exit;
	}

	__osm_vendor_init_av(p_bind, &av);

	status = ib_create_av(p_vend->h_pd, &av, &p_bind->h_dr_av);
	if (status != IB_SUCCESS) {
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"osm_vendor_bind: ERR 3B22: "
			"Unable to create address vector (%s).\n",
			ib_get_err_str(status));

		goto Exit;
	}

	if (osm_log_is_active(p_vend->p_log, OSM_LOG_DEBUG)) {
		osm_log(p_vend->p_log, OSM_LOG_DEBUG,
			"osm_vendor_bind: "
			"Allocating av handle %p.\n", p_bind->h_dr_av);
	}

Exit:
	OSM_LOG_EXIT(p_vend->p_log);
	return ((osm_bind_handle_t) p_bind);
}

ib_mad_t *osm_vendor_get(IN osm_bind_handle_t h_bind,
			 IN const uint32_t mad_size,
			 IN osm_vend_wrap_t * const p_vw)
{
	ib_mad_t *p_mad;
	osm_al_bind_info_t *p_bind = (osm_al_bind_info_t *) h_bind;
	osm_vendor_t *p_vend = p_bind->p_vend;
	ib_api_status_t status;

	OSM_LOG_ENTER(p_vend->p_log);

	CL_ASSERT(p_vw);

	p_vw->size = mad_size;
	p_vw->h_bind = h_bind;

	/*
	   Retrieve a MAD element from the pool and give the user direct
	   access to its buffer.
	 */
	status = ib_get_mad(p_bind->pool_key, mad_size, &p_vw->p_elem);
	if (status != IB_SUCCESS) {
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"osm_vendor_get: ERR 3B25: "
			"Unable to acquire MAD (%s).\n",
			ib_get_err_str(status));

		p_mad = NULL;
		goto Exit;
	}

	CL_ASSERT(p_vw->p_elem);
	p_mad = ib_get_mad_buf(p_vw->p_elem);

	if (osm_log_get_level(p_vend->p_log) >= OSM_LOG_DEBUG) {
		osm_log(p_vend->p_log, OSM_LOG_DEBUG,
			"osm_vendor_get: "
			"Acquired MAD %p, size = %u.\n", p_mad, mad_size);
	}

Exit:
	OSM_LOG_EXIT(p_vend->p_log);
	return (p_mad);
}

void
osm_vendor_put(IN osm_bind_handle_t h_bind, IN osm_vend_wrap_t * const p_vw)
{
	osm_al_bind_info_t *p_bind = (osm_al_bind_info_t *) h_bind;
	osm_vendor_t *p_vend = p_bind->p_vend;
	ib_api_status_t status;

	OSM_LOG_ENTER(p_vend->p_log);

	CL_ASSERT(p_vw);
	CL_ASSERT(p_vw->p_elem);
	CL_ASSERT(p_vw->h_bind == h_bind);

	if (osm_log_get_level(p_vend->p_log) >= OSM_LOG_DEBUG) {
		osm_log(p_vend->p_log, OSM_LOG_DEBUG,
			"osm_vendor_put: "
			"Retiring MAD %p.\n", ib_get_mad_buf(p_vw->p_elem));
	}

	status = ib_put_mad(p_vw->p_elem);
	if (status != IB_SUCCESS) {
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"osm_vendor_put: ERR 3B26: "
			"Unable to retire MAD (%s).\n", ib_get_err_str(status));
	}

	OSM_LOG_EXIT(p_vend->p_log);
}

ib_api_status_t
osm_vendor_send(IN osm_bind_handle_t h_bind,
		IN osm_madw_t * const p_madw, IN boolean_t const resp_expected)
{
	osm_al_bind_info_t *const p_bind = h_bind;
	osm_vendor_t *const p_vend = p_bind->p_vend;
	osm_vend_wrap_t *const p_vw = osm_madw_get_vend_ptr(p_madw);
	osm_mad_addr_t *const p_mad_addr = osm_madw_get_mad_addr_ptr(p_madw);
	ib_mad_t *const p_mad = osm_madw_get_mad_ptr(p_madw);
	ib_api_status_t status;
	ib_mad_element_t *p_elem;
	ib_av_attr_t av;

	OSM_LOG_ENTER(p_vend->p_log);

	CL_ASSERT(p_vw->h_bind == h_bind);
	CL_ASSERT(p_vw->p_elem);

	p_elem = p_vw->p_elem;

	/*
	   If a response is expected to this MAD, then preallocate
	   a mad wrapper to contain the wire MAD received in the
	   response.  Allocating a wrapper here allows for easier
	   failure paths than after we already received the wire mad.
	 */
	if (resp_expected) {
		p_vw->p_resp_madw =
		    osm_mad_pool_get_wrapper_raw(p_bind->p_osm_pool);
		if (p_vw->p_resp_madw == NULL) {
			osm_log(p_vend->p_log, OSM_LOG_ERROR,
				"osm_vendor_send: ERR 3B27: "
				"Unable to allocate MAD wrapper.\n");
			status = IB_INSUFFICIENT_RESOURCES;
			goto Exit;
		}
	} else
		p_vw->p_resp_madw = NULL;

	/*
	   For all sends other than directed route SM MADs,
	   acquire an address vector for the destination.
	 */
	if (p_mad->mgmt_class != IB_MCLASS_SUBN_DIR) {
		memset(&av, 0, sizeof(av));
		av.port_num = p_bind->port_num;
		av.dlid = p_mad_addr->dest_lid;
		av.static_rate = p_mad_addr->static_rate;
		av.path_bits = p_mad_addr->path_bits;

		if ((p_mad->mgmt_class != IB_MCLASS_SUBN_LID) &&
		    (p_mad->mgmt_class != IB_MCLASS_SUBN_DIR)) {
			av.sl = p_mad_addr->addr_type.gsi.service_level;

			if (p_mad_addr->addr_type.gsi.global_route) {
				av.grh_valid = TRUE;
				/* ANIL */
				/* av.grh = p_mad_addr->addr_type.gsi.grh_info; */
			}
		}

		if (osm_log_is_active(p_vend->p_log, OSM_LOG_DEBUG)) {
			osm_log(p_vend->p_log, OSM_LOG_DEBUG,
				"osm_vendor_send: "
				"av.port_num 0x%X, "
				"av.dlid 0x%X, "
				"av.static_rate   %d, "
				"av.path_bits %d.\n",
				av.port_num, cl_ntoh16(av.dlid),
				av.static_rate, av.path_bits);
		}

		status = ib_create_av(p_vend->h_pd, &av, &p_vw->h_av);
		if (status != IB_SUCCESS) {
			osm_log(p_vend->p_log, OSM_LOG_ERROR,
				"osm_vendor_send: ERR 3B28: "
				"Unable to create address vector (%s).\n",
				ib_get_err_str(status));

			if (p_vw->p_resp_madw)
				osm_mad_pool_put(p_bind->p_osm_pool,
						 p_vw->p_resp_madw);
			goto Exit;
		}

		if (osm_log_is_active(p_vend->p_log, OSM_LOG_DEBUG)) {
			osm_log(p_vend->p_log, OSM_LOG_DEBUG,
				"osm_vendor_send: "
				"Allocating av handle %p.\n", p_vw->h_av);
		}
	} else {
		p_vw->h_av = p_bind->h_dr_av;
	}

	p_elem->h_av = p_vw->h_av;

	p_elem->context1 = p_madw;
	p_elem->context2 = NULL;

	p_elem->immediate_data = 0;
	p_elem->p_grh = NULL;
	p_elem->resp_expected = resp_expected;
	p_elem->retry_cnt = OSM_DEFAULT_RETRY_COUNT;

	p_elem->send_opt = IB_SEND_OPT_SIGNALED;
	p_elem->timeout_ms = p_vend->timeout;

	/* Completion information. */
	p_elem->status = 0;	/* Not trusting AL */

	if ((p_mad->mgmt_class == IB_MCLASS_SUBN_LID) ||
	    (p_mad->mgmt_class == IB_MCLASS_SUBN_DIR)) {
		p_elem->remote_qp = 0;
		p_elem->remote_qkey = 0;
	} else {
		p_elem->remote_qp = p_mad_addr->addr_type.gsi.remote_qp;
		p_elem->remote_qkey = p_mad_addr->addr_type.gsi.remote_qkey;
		osm_log(p_vend->p_log, OSM_LOG_DEBUG,
			"osm_vendor_send: "
			"remote qp = 0x%X, remote qkey = 0x%X.\n",
			cl_ntoh32(p_elem->remote_qp),
			cl_ntoh32(p_elem->remote_qkey));
	}

	status = ib_send_mad(p_bind->h_svc, p_elem, NULL);
	if (status != IB_SUCCESS) {
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"osm_vendor_send: ERR 3B29: "
			"Send failed (%s).\n", ib_get_err_str(status));
		if (p_vw->p_resp_madw)
			osm_mad_pool_put(p_bind->p_osm_pool, p_vw->p_resp_madw);
		goto Exit;
	}

Exit:
	OSM_LOG_EXIT(p_vend->p_log);
	return (status);
}

ib_api_status_t osm_vendor_local_lid_change(IN osm_bind_handle_t h_bind)
{
	osm_al_bind_info_t *p_bind = (osm_al_bind_info_t *) h_bind;
	osm_vendor_t *p_vend = p_bind->p_vend;
	ib_av_attr_t av;
	ib_api_status_t status;

	OSM_LOG_ENTER(p_vend->p_log);

	/*
	   The only thing we need to do is refresh the directed
	   route address vector.
	 */
	__osm_vendor_init_av(p_bind, &av);

	status = ib_destroy_av(p_bind->h_dr_av);
	if (status != IB_SUCCESS) {
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"osm_vendor_local_lid_change: ERR 3B32: "
			"Unable to destroy address vector (%s).\n",
			ib_get_err_str(status));

		goto Exit;
	}

	status = ib_create_av(p_vend->h_pd, &av, &p_bind->h_dr_av);
	if (status != IB_SUCCESS) {
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"osm_vendor_local_lid_change: ERR 3B33: "
			"Unable to create address vector (%s).\n",
			ib_get_err_str(status));

		goto Exit;
	}

Exit:
	OSM_LOG_EXIT(p_vend->p_log);
	return (status);
}

void osm_vendor_set_sm(IN osm_bind_handle_t h_bind, IN boolean_t is_sm_val)
{
	osm_al_bind_info_t *p_bind = (osm_al_bind_info_t *) h_bind;
	osm_vendor_t *p_vend = p_bind->p_vend;
	ib_api_status_t status;
	ib_port_attr_mod_t attr_mod;

	OSM_LOG_ENTER(p_vend->p_log);

	memset(&attr_mod, 0, sizeof(attr_mod));

	attr_mod.cap.sm = is_sm_val;

	status = ib_modify_ca(p_vend->h_ca, p_bind->port_num,
			      IB_CA_MOD_IS_SM, &attr_mod);

	if (status != IB_SUCCESS) {
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"osm_vendor_set_sm: ERR 3B34: "
			"Unable set 'IS_SM' bit to:%u in port attributes (%s).\n",
			is_sm_val, ib_get_err_str(status));
	}

	OSM_LOG_EXIT(p_vend->p_log);
}

void osm_vendor_set_debug(IN osm_vendor_t * const p_vend, IN int32_t level)
{

}

#endif				/* OSM_VENDOR_INTF_AL */